Class: RuboCop::Cop::Ezcater::DirectEnvCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/ezcater/direct_env_check.rb

Overview

Use the ‘Rails.configuration.x` namespace for configuration backed by environment variables, rather than inspecting `ENV` directly.

Restricting environment variables references to be within application configuration makes it more obvious which env vars an application relies upon. See ezcater.atlassian.net/wiki/x/ZIChNg.

Examples:


# good
enforce_foo! if Rails.configuration.x.foo_enforced

# bad
enforce_foo! if ENV["FOO_ENFORCED"] == "true"

Constant Summary collapse

MSG =
"Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `ENV`. Restricting\nenvironment variables references to be within application configuration makes it more obvious which env vars\nan application relies upon. https://ezcater.atlassian.net/wiki/x/ZIChNg\n".split("\n").join(" ")

Instance Method Summary collapse

Instance Method Details

#on_const(node) ⇒ Object



32
33
34
35
36
# File 'lib/rubocop/cop/ezcater/direct_env_check.rb', line 32

def on_const(node)
  env_ref(node) do
    add_offense(node.loc.expression, message: MSG)
  end
end