Class: RuboCop::Cop::Gusto::RakeConstants
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Gusto::RakeConstants
- Defined in:
- lib/rubocop/cop/gusto/rake_constants.rb
Overview
Detects constants in a rake file because they are defined at the top level. It is confusing because the scope looks like it would be in the task or namespace, but actually it is defined at the top level.
Constant Summary collapse
- MSG =
"Do not define a constant in rake file, because they are sometimes `load`ed, instead of `require`d which can lead to warnings about redefining constants"
Instance Method Summary collapse
- #on_casgn(node) ⇒ Object
- #on_class(node) ⇒ Object
- #on_module(node) ⇒ Object
- #task_or_namespace?(node) ⇒ Object
Instance Method Details
#on_casgn(node) ⇒ Object
42 43 44 45 46 |
# File 'lib/rubocop/cop/gusto/rake_constants.rb', line 42 def on_casgn(node) return unless in_task_or_namespace?(node) add_offense(node) end |
#on_class(node) ⇒ Object
48 49 50 51 52 |
# File 'lib/rubocop/cop/gusto/rake_constants.rb', line 48 def on_class(node) return unless in_task_or_namespace?(node) add_offense(node) end |
#on_module(node) ⇒ Object
54 55 56 57 58 |
# File 'lib/rubocop/cop/gusto/rake_constants.rb', line 54 def on_module(node) return unless in_task_or_namespace?(node) add_offense(node) end |
#task_or_namespace?(node) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rubocop/cop/gusto/rake_constants.rb', line 34 def_node_matcher :task_or_namespace?, <<-PATTERN (block (send _ {:task :namespace} ...) args _ ) PATTERN |