Sorbet enums look like constants in a block:
class TestEnum < T::Enum
enums do
Foo = new("foo")
Bar = new("bar")
end
end
# => Lint/ConstantDefinitionInBlock raised
Rubocop could permit this declaration.
Or... depending on how Rubocop works, then the rubocop-sorbet gem could be changed to "help ignore it" (internally modify the rule)?
I don't think there are other alternatives, other than marking all instances to ignore that rule. I could have a go at a PR if you decide it is within Rubocop's remit to "know about" T::Enum.
I think this cop can have allowed list of method name for block. So, I've opened a PR #9027 that adds user-configurable option.
@hlascelles RuboCop 1.3.0 has been released. The following configuration can solve this issue:
Lint/ConstantDefinitionInBlock:
AllowedMethods:
- enums
That's nice. @koic should we not have that in our default? I mean, what are the odds that someone writes enums { Foo = ... } and is not using sorbet?
Excellent, thank you!
@marcandre Cool! I was worried about false negatives for users who have defined constants in user custom enums method's block. But it would be worthwhile to be able to resolve this realistic issue for Sorbet by default rather than not knowing if it would happen or not. And there is not much imagination that the false negatives will occur. So I've opened a PR #9036.