Class: RuboCop::Cop::Restrictenv::NoEnvAccess

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/restrictenv/no_env_access.rb

Overview

This cop prevents accessing ENV. Use it in conjunction with an exception in .rubocop.yml to enforce where environment variables can be read

Use this cop to enforce interacting with the environment only in initializers and in config/ files, for example.

Examples:

EnforcedStyle: forbid (default)

# Description of the `forbid` style.

# bad
ENV.fetch('SOMETHING')

# bad
ENV.fetch('SOMETHING', 'default_value')

# bad
ENV['SOMETHING']

Constant Summary collapse

MSG =
'Do not access ENV directly in application code.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



31
32
33
34
35
# File 'lib/rubocop/cop/restrictenv/no_env_access.rb', line 31

def on_send(node)
  return unless env_used?(node)

  add_offense(node)
end