E229: Indentation Does Not Reflect Nesting
This warning occurs when indentation does not reflect syntactic nesting, which may confuse readers or reflect a misunderstanding on the code writer's part.
This can happen when a line intended to declare a new scope does not actually do so, for instance because a colon becomes part of a name.
Example
class SomeClass // no colon, so this is an empty class declaration
def y = 1 // this is a standalone, top-level definition!
Error
-- [E229] Syntax Warning: example.scala:2:2 ------------------------------------
2 | def y = 1 // this is a standalone, top-level definition!
| ^
| Line is indented too far to the right, or a '{' or ':' is missing
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Indentation that does not reflect syntactic nesting may be due to a typo such as missing punctuation.
-----------------------------------------------------------------------------
Solution
class SomeClass
// If the declaration is intentionally at the top level, indent it as such
def y = 1
In this article