Project

General

Profile

Bug #14674

New mismatched indentations warnings?

Added by marcandre (Marc-Andre Lafortune) 10 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 2.6.0dev (2018-04-11 trunk 63132) [x86_64-darwin15]
[ruby-core:86492]

Description

I recently got a failure in my test suite because ruby head warns of indentation it considers mismatched:

$ ruby -w -e "
case
   when :foo
end
"
-e:3: warning: mismatched indentations at 'when' with 'case' at 2

I hope this is not intentional and will be fixed.

Associated revisions

Revision a3a5f38d
Added by nobu (Nobuyoshi Nakada) 10 months ago

parse.y: when indent

  • parse.y (k_when): warn less-indented when than case. [ruby-core:86492] [Bug #14674]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 63141
Added by nobu (Nobuyoshi Nakada) 10 months ago

parse.y: when indent

  • parse.y (k_when): warn less-indented when than case. [ruby-core:86492] [Bug #14674]

Revision 63141
Added by nobu (Nobuyoshi Nakada) 10 months ago

parse.y: when indent

  • parse.y (k_when): warn less-indented when than case. [ruby-core:86492] [Bug #14674]

Revision 3b93a8bc
Added by nobu (Nobuyoshi Nakada) 10 months ago

parse.y: else indent

  • parse.y (keyword_else): warn less-indented else than case. [ruby-core:86492] [Bug #14674]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 63165
Added by nobu (Nobuyoshi Nakada) 10 months ago

parse.y: else indent

  • parse.y (keyword_else): warn less-indented else than case. [ruby-core:86492] [Bug #14674]

Revision 63165
Added by nobu (Nobuyoshi Nakada) 10 months ago

parse.y: else indent

  • parse.y (keyword_else): warn less-indented else than case. [ruby-core:86492] [Bug #14674]

History

Updated by shevegen (Robert A. Heiler) 10 months ago

I think in the long run it would be nice if ruby hackers have more
control over non-error messages (e. g. warnings).

Some may prefer ruby providing cues for a more consistent code
layout but others may not necessarily care that much. In both
situations it would be nice to be able to decide on the verbosity
level of warnings.

Updated by nobu (Nobuyoshi Nakada) 10 months ago

It was intentional, but mismatched with your style?

Updated by marcandre (Marc-Andre Lafortune) 10 months ago

I strongly believe that it is not Ruby's parser job to warn us about styling, especially if there's no strong reason to suspect that it's a programmer error.

I realize rubocop is not official or part of MRI, but it has the required qualities to do this:
1) requires opt-in (i.e. users wanting to enforce a particular style can use rubocop; others don't need to)
2) configurable (i.e. rules can be turned off or tweaked)
3) exception can be dealt with with comments in the code (e.g. # rubocop:disable Some/Rule)
4) warning/errors are generated when desired, not all the time (e.g. during tests/manually, but not when actually running the code)

rubocop can even autocorrect according to these desired specs. Ruby MRI has none of these features!

Note that rubocop already supports Layout/CaseIndentation, can issue warning, error, or ignore it. It supports two different alignment styles, and supports any desired indent.

In short: warnings should be kept to a strict minimum in MRI, and enforcing a style for case/when is a terrible use of a warning.

Would you consider reverting this, or asking Matz?

Updated by zverok (Victor Shepelev) 10 months ago

I agree with @marcandre. I used to prefer "indented when" style once, and still think it is pretty acceptable.

When Ruby has introduced interpreter warnings about mismatched indentation, I thought it is a good thing, allowing to catch obvious typos like this:

def foo
  bar.each do 
end # forgot to close do/end of "each", hard to spot after a large methods

#...

# Without that warning, the interpreter error about missing "end" at the very end of the file,
# far from the actual point of error

But for being useful this way, the interpreter should report only absolutely obvious and unambiguous typos, not "non-preferred style". Ruby is too mature to introduce hardcoded style preferences, I believe.

#5

Updated by nobu (Nobuyoshi Nakada) 10 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63141.


parse.y: when indent

  • parse.y (k_when): warn less-indented when than case. [ruby-core:86492] [Bug #14674]

Also available in: Atom PDF