class RuboCop::Cop::Rails::EnvironmentVariableAccess

ENV = “bar”
# good
@example AllowWrites: true<br><br>ENV = “bar”
# bad
@example AllowWrites: false (default)

ENV.fetch(“FOO”)
ENV[“FOO”]
# good
@example AllowReads: true

ENV.fetch(“FOO”)
ENV[“FOO”]
# bad
@example AllowReads: false (default)
Rails.application.config.foo = “bar”
Rails.application.secrets.foo
Rails.application.config.x.foo.bar
Rails.application.config.foo
# good
@example
be configured to allow either reads or writes if required.
and copied into the application’s configuration or secrets. The cop can
time if the environment variables were loaded as part of initialization
errors due to misconfiguration that could have been discovered at boot
`ENV` variable within the application code. This can lead to runtime
Looks for direct access to environment variables through the

def allow_reads?

def allow_reads?
  cop_config['AllowReads'] == true
end

def allow_writes?

def allow_writes?
  cop_config['AllowWrites'] == true
end

def on_const(node)

def on_const(node)
  add_offense(node, message: READ_MSG) if env_read?(node) && !allow_reads?
  add_offense(node, message: WRITE_MSG) if env_write?(node) && !allow_writes?
end