Class: RuboCop::Cop::Lint::NoENV

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/lint/no_env.rb

Overview

Examples:

# bad
ENV[]

# bad
ENV.fetch(..)

# good
GetEnv[]

# good
GetEnv.fetch(...)

Constant Summary collapse

MSG =
'Use `GetEnv` instead of `ENV`.'

Instance Method Summary collapse

Instance Method Details

#on_const(node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/cop/lint/no_env.rb', line 26

def on_const(node)
  parent = node.parent
  return unless is_ENV_index?(parent) || is_ENV_fetch?(parent)

  add_offense(node) do |corrector|
    if Gem::Version.new(RuboCop::Version.version) >= Gem::Version.new('0.82.0')
      corrector.replace(node, 'GetEnv')
    else
      corrector.replace(node.loc.expression, 'GetEnv')
    end
  end
end