constant-definition-in-block
What it does
Section titled “What it does”Reports a constant, class or module defined directly in a block. enums blocks (Sorbet) are not reported.
Why it matters
Section titled “Why it matters”A constant in a block belongs to the scope that encloses the block, not to the block, so the definition is global to the file or class, and runs again each time the block does, with a warning about a constant that is already defined.
To fix, define the constant outside the block, or use a variable or let.
Example
Section titled “Example”... endend[1].each { X = 1 }Configuration
Section titled “Configuration”ruby: lint: rules: constant-definition-in-block: warn # off (default), warn, errorEnabled by the presets: ruby/rubocop.
Suppress one line with sudsy-disable-next-line constant-definition-in-block in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| rubocop | Lint/ConstantDefinitionInBlock |
full |