You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new cop, `Rake/ConstantDefinitionInTask`, that registers an offense
for a constant assignment inside a task or namespace.
```ruby
task :foo do
CONST = 1
end
namespace :foo do
CONST = 1
end
CONST = 1
task :foo do
end
```
A constant assigned inside a `task` or `namespace` block is defined to the
top level, not scoped to the block. That is the same surprise the existing
cops already cover for methods and classes:
* `Rake/MethodDefinitionInTask` for methods
* `Rake/ClassDefinitionInTask` for classes and modules
* `Rake/ConstantDefinitionInTask` (new) for plain constant assignments
Rake files are also sometimes loaded rather than required, so a constant
that leaks to the top level can produce "already initialized constant"
warnings on reload.
The cop reuses `Helper::TaskDefinition`, and like `Rake/ClassDefinitionInTask`
it skips nodes inside a `class`, `module`, or `Class.new` body via
`Helper::ClassDefinition.in_class_definition?`, because those constants are
not defined to the top level.
Adds the cop and its spec, a `config/default.yml` entry (`Enabled: pending`,
`VersionAdded: '<<next>>'`), a `register_cop` directive in
`lib/rubocop/cop/rake.rb` so the cop is registered for lazy loading, the
cop count in `spec/lazy_loading_spec.rb`, and a CHANGELOG entry.
`bundle exec rake` is green.
*[#66](https://github.com/rubocop/rubocop-rake/pull/66): Speed up loading rubocop-rake by lazily loading only the cops needed for a run. This requires RuboCop 1.89.0+. ([@koic][])
0 commit comments