From 1d5ed89138a448c118f78ca4ce8f9836e216e469 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Wed, 7 Apr 2021 15:25:11 +0200 Subject: [PATCH] fmt: remove trailing space in comments (#9620) --- vlib/builtin/builtin_d_gcboehm.v | 2 +- vlib/dl/dl_nix.c.v | 2 +- vlib/dl/dl_windows.c.v | 2 +- vlib/os/process_test.v | 2 +- vlib/v/fmt/comments.v | 4 ++-- vlib/v/fmt/tests/trailing_space_expected.vv | 10 ++++++++++ vlib/v/fmt/tests/trailing_space_input.vv | 10 ++++++++++ vlib/v/pref/default.v | 6 +++--- vlib/v/tests/assembly/asm_test.amd64.v | 4 ++-- vlib/v/tests/assembly/asm_test.i386.v | 2 +- .../match_expression_with_fn_names_in_branches_test.v | 2 +- vlib/v/tests/mut_receiver_returned_as_reference_test.v | 2 +- .../bin/a_program_under_bin_can_find_mod1_test.v | 2 +- .../bin/main.vsh | 6 +++--- .../mod1/submodule/m.v | 2 +- vlib/v/tests/sum_type_test.v | 2 +- 16 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 vlib/v/fmt/tests/trailing_space_expected.vv create mode 100644 vlib/v/fmt/tests/trailing_space_input.vv diff --git a/vlib/builtin/builtin_d_gcboehm.v b/vlib/builtin/builtin_d_gcboehm.v index a7362912a0..8860239ae8 100644 --- a/vlib/builtin/builtin_d_gcboehm.v +++ b/vlib/builtin/builtin_d_gcboehm.v @@ -29,7 +29,7 @@ fn C.GC_REALLOC(ptr voidptr, n size_t) voidptr fn C.GC_FREE(ptr voidptr) // explicitely perform garbage collection now! Garbage collections -// are done automatically when needed, so this function is hardly needed +// are done automatically when needed, so this function is hardly needed fn C.GC_gcollect() // functions to temporarily suspend/resume garbage collection diff --git a/vlib/dl/dl_nix.c.v b/vlib/dl/dl_nix.c.v index 059cf9dcce..2a43bffd9d 100644 --- a/vlib/dl/dl_nix.c.v +++ b/vlib/dl/dl_nix.c.v @@ -31,7 +31,7 @@ pub fn sym(handle voidptr, symbol string) voidptr { } // dlerror provides a text error diagnostic message for functions in `dl` -// it returns a human-readable string, describing the most recent error +// it returns a human-readable string, describing the most recent error // that occurred from a call to one of the `dl` functions, since the last // call to dlerror() pub fn dlerror() string { diff --git a/vlib/dl/dl_windows.c.v b/vlib/dl/dl_windows.c.v index 58d41aee4b..b6ae2fcda3 100644 --- a/vlib/dl/dl_windows.c.v +++ b/vlib/dl/dl_windows.c.v @@ -28,7 +28,7 @@ pub fn sym(handle voidptr, symbol string) voidptr { } // dlerror provides a text error diagnostic message for functions in `dl` -// it returns a human-readable string, describing the most recent error +// it returns a human-readable string, describing the most recent error // that occurred from a call to one of the `dl` functions, since the last // call to dlerror() pub fn dlerror() string { diff --git a/vlib/os/process_test.v b/vlib/os/process_test.v index 0246b72aca..bdc6a46006 100644 --- a/vlib/os/process_test.v +++ b/vlib/os/process_test.v @@ -11,7 +11,7 @@ const ( fn testsuite_begin() ? { os.rm(test_os_process) or {} if os.getenv('WINE_TEST_OS_PROCESS_EXE') != '' { - // Make it easier to run the test under wine emulation, by just + // Make it easier to run the test under wine emulation, by just // prebuilding the executable with: // v -os windows -o x.exe cmd/tools/test_os_process.v // WINE_TEST_OS_PROCESS_EXE=x.exe ./v -os windows vlib/os/process_test.v diff --git a/vlib/v/fmt/comments.v b/vlib/v/fmt/comments.v index 5100f878b1..580eccf3b4 100644 --- a/vlib/v/fmt/comments.v +++ b/vlib/v/fmt/comments.v @@ -44,7 +44,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { } } else if !node.text.contains('\n') { is_separate_line := !options.inline || node.text.starts_with('\x01') - mut s := node.text.trim_left('\x01') + mut s := node.text.trim_left('\x01').trim_right(' ') mut out_s := '//' if s != '' { if is_char_alphanumeric(s[0]) { @@ -67,7 +67,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { f.writeln('') } for line in lines { - f.writeln(line) + f.writeln(line.trim_right(' ')) f.empty_line = false } if end_break { diff --git a/vlib/v/fmt/tests/trailing_space_expected.vv b/vlib/v/fmt/tests/trailing_space_expected.vv new file mode 100644 index 0000000000..690540c5df --- /dev/null +++ b/vlib/v/fmt/tests/trailing_space_expected.vv @@ -0,0 +1,10 @@ +// NB: The input file has and *should* have trailing spaces. +// When making changes, please ensure these spaces are not removed. + +fn comments_with_trailing_space() { + // two spaces on the right + /* + spaces after here + and everywhere :) + */ +} diff --git a/vlib/v/fmt/tests/trailing_space_input.vv b/vlib/v/fmt/tests/trailing_space_input.vv new file mode 100644 index 0000000000..2b5b448fa9 --- /dev/null +++ b/vlib/v/fmt/tests/trailing_space_input.vv @@ -0,0 +1,10 @@ +// NB: The input file has and *should* have trailing spaces. +// When making changes, please ensure these spaces are not removed. + +fn comments_with_trailing_space() { + // two spaces on the right + /* + spaces after here + and everywhere :) + */ +} \ No newline at end of file diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index 17fcd1e6ea..e7d6fca9ab 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -61,15 +61,15 @@ pub fn (mut p Preferences) fill_with_defaults() { // locate resources relative to it. That enables running examples like // this: // `./v run examples/flappylearning/` - // instead of: + // instead of: // `./v -o examples/flappylearning/flappylearning run examples/flappylearning/` // This topic comes up periodically from time to time on Discord, and // many CI breakages already happened, when someone decides to make V // behave in this aspect similarly to the dumb behaviour of other // compilers. // - // If you do decide to break it, please *at the very least*, test it - // extensively, and make a PR about it, instead of commiting directly + // If you do decide to break it, please *at the very least*, test it + // extensively, and make a PR about it, instead of commiting directly // and breaking the CI, VC, and users doing `v up`. if rpath == '$p.vroot/cmd/v' && os.is_dir('vlib/compiler') { // Building V? Use v2, since we can't overwrite a running diff --git a/vlib/v/tests/assembly/asm_test.amd64.v b/vlib/v/tests/assembly/asm_test.amd64.v index 06ad1fd2b1..84c415587f 100644 --- a/vlib/v/tests/assembly/asm_test.amd64.v +++ b/vlib/v/tests/assembly/asm_test.amd64.v @@ -24,7 +24,7 @@ fn test_inline_asm() { mov f, d add f, e add f, 5 - ; +r (f) // output + ; +r (f) // output ; r (d) r (e) // input } @@ -45,7 +45,7 @@ fn test_inline_asm() { mut j := 0 // do 5*3 - // adding three, five times + // adding three, five times asm amd64 { mov rcx, 5 // loop 5 times loop_start: diff --git a/vlib/v/tests/assembly/asm_test.i386.v b/vlib/v/tests/assembly/asm_test.i386.v index aa1ec91110..e1b780102e 100644 --- a/vlib/v/tests/assembly/asm_test.i386.v +++ b/vlib/v/tests/assembly/asm_test.i386.v @@ -25,7 +25,7 @@ fn test_inline_asm() { mov f, d add f, e add f, 5 - ; +r (f) // output + ; +r (f) // output ; r (d) r (e) // input } diff --git a/vlib/v/tests/match_expression_with_fn_names_in_branches_test.v b/vlib/v/tests/match_expression_with_fn_names_in_branches_test.v index 8994995a4c..665f7bc69f 100644 --- a/vlib/v/tests/match_expression_with_fn_names_in_branches_test.v +++ b/vlib/v/tests/match_expression_with_fn_names_in_branches_test.v @@ -32,7 +32,7 @@ fn sine(note &Note, time f32, amp f32) f32 { pub fn new_context(cfg Config) fn (&Note, f32, f32) f32 { // Note, that here `sine` and `sawtooth`, // are different functions, but they do have - // a compatible signature, so `next_fn` can + // a compatible signature, so `next_fn` can // become either one of them: next_fn := match cfg.wave_kind { .sine { sine } diff --git a/vlib/v/tests/mut_receiver_returned_as_reference_test.v b/vlib/v/tests/mut_receiver_returned_as_reference_test.v index ea1a681542..fcf4fba9b0 100644 --- a/vlib/v/tests/mut_receiver_returned_as_reference_test.v +++ b/vlib/v/tests/mut_receiver_returned_as_reference_test.v @@ -10,7 +10,7 @@ fn (mut p Player) set_name(name string) &Player { return p // because of automatic (de)reference of return values } -// NB: `p` is declared as a `mut` parameter, +// NB: `p` is declared as a `mut` parameter, // which now only affects its mutability. fn (mut p Player) set_position(x int, y int) &Player { p.x = x diff --git a/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v b/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v index cbc3fa04f1..e2045a652d 100644 --- a/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v +++ b/vlib/v/tests/project_with_modules_having_submodules/bin/a_program_under_bin_can_find_mod1_test.v @@ -6,7 +6,7 @@ fn test_mod1_can_still_be_found_through_parent_project_vmod() { /* NB: this main program is under bin/ , but it still -can find mod1, because the parent project has v.mod, +can find mod1, because the parent project has v.mod, so v module lookup for this program will find mod1 through relation to the parent v.mod file */ diff --git a/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh b/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh index ef643ce804..abd256f35e 100644 --- a/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh +++ b/vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh @@ -7,8 +7,8 @@ println('This script is located inside: ' + resource_abs_path('')) println('The result of calling m.f is: ' + m.f().str()) /* -NB: this main program v script is under bin/ , -but it *still* can find mod1, because the parent project has v.mod, -so v module lookup for this bin/main.vsh file will find mod1 through +NB: this main program v script is under bin/ , +but it *still* can find mod1, because the parent project has v.mod, +so v module lookup for this bin/main.vsh file will find mod1 through relation to the parent ../v.mod file */ diff --git a/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v b/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v index e1bfe37da4..e241849fb7 100644 --- a/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v +++ b/vlib/v/tests/project_with_modules_having_submodules/mod1/submodule/m.v @@ -2,7 +2,7 @@ module submodule /* This submodule just imports its sibling submodules. -Note that they are NOT under 'submodule' itself, +Note that they are NOT under 'submodule' itself, but are in its parent mod1 , and mod1 has a 'v.mod' file. */ import v.tests.project_with_modules_having_submodules.mod1.mod11 diff --git a/vlib/v/tests/sum_type_test.v b/vlib/v/tests/sum_type_test.v index 0f0084984e..c1c262eb76 100644 --- a/vlib/v/tests/sum_type_test.v +++ b/vlib/v/tests/sum_type_test.v @@ -572,7 +572,7 @@ fn handle(e Expr) string { // Binary Search Tree test by @SleepyRoy // TODO: make Node.value generic once it's robust enough -// TODO: `return match` instead of returns everywhere inside match +// TODO: `return match` instead of returns everywhere inside match struct Empty {}