rgrove / crass

A Ruby CSS parser that's fully compliant with the CSS Syntax Level 3 specification.
MIT License
138 stars 14 forks source link

Address `warning: mismatched indentations at 'when' with 'case'` #7

Closed yahonda closed 6 years ago

yahonda commented 6 years ago

Address warning: mismatched indentations at 'when' with 'case' and warning: mismatched indentations at 'else' with 'case'

Recently Rails railties CI with ruby-head, which is now ruby2.6.0.dev has been failing due to this error.

The log length has exceeded the limit of 4 MB (this usually means that the test suite is raising the same exception over and over).

Here are the number of warnings of crass-1.0.3.

$ grep warning log.txt  | sort | uniq -c | sort -n |grep crass
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/parser.rb:405: warning: mismatched indentations at 'when' with 'case' at 402
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/parser.rb:408: warning: mismatched indentations at 'when' with 'case' at 402
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/parser.rb:415: warning: mismatched indentations at 'when' with 'case' at 402
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/parser.rb:420: warning: mismatched indentations at 'else' with 'case' at 402
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/tokenizer.rb:540: warning: mismatched indentations at 'when' with 'case' at 539
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/tokenizer.rb:543: warning: mismatched indentations at 'when' with 'case' at 539
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/tokenizer.rb:553: warning: mismatched indentations at 'when' with 'case' at 539
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/tokenizer.rb:559: warning: mismatched indentations at 'when' with 'case' at 539
  68 /home/travis/.rvm/gems/ruby-head/gems/crass-1.0.3/lib/crass/tokenizer.rb:570: warning: mismatched indentations at 'else' with 'case' at 539
$

These warnings can be reproduced by running rake command.

$ rake
NOTE: Testing support for frozen string literals
/home/yahonda/git/crass/lib/crass/parser.rb:405: warning: mismatched indentations at 'when' with 'case' at 402
/home/yahonda/git/crass/lib/crass/parser.rb:408: warning: mismatched indentations at 'when' with 'case' at 402
/home/yahonda/git/crass/lib/crass/parser.rb:415: warning: mismatched indentations at 'when' with 'case' at 402
/home/yahonda/git/crass/lib/crass/parser.rb:420: warning: mismatched indentations at 'else' with 'case' at 402
/home/yahonda/git/crass/lib/crass/tokenizer.rb:540: warning: mismatched indentations at 'when' with 'case' at 539
/home/yahonda/git/crass/lib/crass/tokenizer.rb:543: warning: mismatched indentations at 'when' with 'case' at 539
/home/yahonda/git/crass/lib/crass/tokenizer.rb:553: warning: mismatched indentations at 'when' with 'case' at 539
/home/yahonda/git/crass/lib/crass/tokenizer.rb:559: warning: mismatched indentations at 'when' with 'case' at 539
/home/yahonda/git/crass/lib/crass/tokenizer.rb:570: warning: mismatched indentations at 'else' with 'case' at 539
Run options: --seed 1077

... snip ...
$

How to address these warnings

These warnings can be addressed by using RuboCop. I do not request to install RuboCop permanently in this repository then just created it temporary and remove them.

 41 Layout/CaseIndentation:
 42   Include:
 43     - 'lib/crass/parser.rb'
 44     - 'lib/crass/tokenizer.rb'
 45
rgrove commented 6 years ago

Thanks!