Project

General

Profile

Actions

Bug #14674

closed

New mismatched indentations warnings?

Added by marcandre (Marc-Andre Lafortune) over 6 years ago. Updated over 6 years ago.

Status:
Closed
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.

Updated by shevegen (Robert A. Heiler) over 6 years 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) over 6 years ago

It was intentional, but mismatched with your style?

Updated by marcandre (Marc-Andre Lafortune) over 6 years 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) over 6 years ago

I agree with @marcandre (Marc-Andre Lafortune). 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.

Actions #5

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63141.


parse.y: when indent

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0