exercism / snippet-extractor

GNU Affero General Public License v3.0
1 stars 25 forks source link

How to test for trailing whitespace? #65

Open loziniak opened 1 year ago

loziniak commented 1 year ago

In #62 I encountered a problem. I have a whitespace before comments (line comment 1, 2 and 3), but cannot write tests, because Rubocop complains during CI. Is this possible to:

or

loziniak commented 1 year ago

This is a sample code for snippet-extractor test:

          x: 1 ; line comment 1
          y: 11
          x: 2   ;-- line comment 2
          x: 3      ;@@ line comment 3

Rubocop complains for the expected part:

          x: 1 
          y: 11
          x: 2   
          x: 3      
joshiraez commented 1 year ago

Mmm this is awry. The snippet extractor will always trim any whitespace from the lines (I have to double check but I'm quite sure the only thing it preserves are tabs/spaces at the start).

It rather seems a problem with Rubocop failing linting checks. Could you paste your error please? (Try first to check your other issue and limit your test to 10 lines to see if it keeps complaining and we can go from there)

loziniak commented 1 year ago

log from Rubocop check:

warning: parser/current is loading parser/ruby26, which recognizes2.6.10-compliant syntax, but you are running 2.6.6.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Inspecting 39 files
.................................C.....

Offenses:

test/languages/red_test.rb:33:15: C: [Correctable] Layout/TrailingWhitespace: Trailing whitespace detected.
          x: 1 
              ^
test/languages/red_test.rb:35:15: C: [Correctable] Layout/TrailingWhitespace: Trailing whitespace detected.
          x: 2   
              ^^^
test/languages/red_test.rb:36:15: C: [Correctable] Layout/TrailingWhitespace: Trailing whitespace detected.
          x: 3      
              ^^

39 files inspected, 3 offenses detected, 3 offenses auto-correctable
loziniak commented 1 year ago

66 is fixed now, but here nothing changed.

loziniak commented 1 year ago

In 0c374d9 I tried to get into account the fact, that Extractor will clear whitespace, but id didn't.

joshiraez commented 1 year ago

I'm quite sure this is a rubocop issue, but I think the extractor will remove any trailing whitespace at the right anyway, so you should be safe to remove those from the expected,

joshiraez commented 1 year ago

Oh wait, I just saw your commit. Let me take a look at this then

loziniak commented 11 months ago

Hello, any news here?