Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2018

Conversation

yahonda
Copy link
Contributor

@yahonda yahonda commented Apr 8, 2018

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.

  • Create .rubocop_todo.yml file
$ rubocop --auto-gen-config
  • Edit .rubocop_todo.yml generated and modify as follows.
 41 Layout/CaseIndentation:
 42   Exclude:
 43     - 'lib/crass/parser.rb'
 44     - 'lib/crass/tokenizer.rb'
 45     - 'test/support/common.rb'
  • Replace Exclude with Include under Layout/CaseIndentication:
    and remove test/support/common.rb' since only lib/crass/parser.rb and lib/crass/tokenizer.rb files are reported by rake.
 41 Layout/CaseIndentation:
 42   Include:
 43     - 'lib/crass/parser.rb'
 44     - 'lib/crass/tokenizer.rb'
 45
  • Execute rubocop -a (--auto-correct) option
$ rubocop -a
  • Remove .rubocop.yml and .rubocop_todo.yml
$ rm .rubocop.yml .rubocop_todo.yml

and `warning: mismatched indentations at 'else' with 'case'`
@rgrove rgrove merged commit 4edf427 into rgrove:master Apr 8, 2018
@rgrove
Copy link
Owner

rgrove commented Apr 8, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants