Class: RuboCop::Cop::Rails::UnknownEnv

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rails/unknown_env.rb

Overview

Checks that environments called with ‘Rails.env` predicates exist. By default the cop allows three environments which Rails ships with: `development`, `test`, and `production`. More can be added to the `Environments` config parameter.

Examples:

# bad
Rails.env.proudction?
Rails.env == 'proudction'

# good
Rails.env.production?
Rails.env == 'production'

Constant Summary collapse

MSG =
'Unknown environment `%<name>s`.'
MSG_SIMILAR =
'Unknown environment `%<name>s`. Did you mean `%<similar>s`?'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/rubocop/cop/rails/unknown_env.rb', line 41

def on_send(node)
  unknown_environment_predicate?(node) do |name|
    add_offense(node.loc.selector, message: message(name))
  end

  unknown_environment_equal?(node) do |str_node|
    name = str_node.value
    add_offense(str_node, message: message(name))
  end
end