class RuboCop::Cop::Lint::ConstantResolution
Login
# good
::User::Login
# good
User
# bad
# Restrict this cop not being concerned about certain constants
@example Ignore: [‘Login’]
User::Login
# good
::Login
# good
Login
# bad
# Restrict this cop to only being concerned about certain constants
@example Only: [‘Login’]
::User::Login
# good
::User
# good
User::Login
# bad
User
# bad
# By default checks every constant
@example
this cop which is disabled by default.
conflicting rules. Because it respects user configurations that want to enable
NOTE: ‘Style/RedundantConstantBase` cop is disabled if this cop is enabled to prevent
offenses, Enable this cop with `Only: [The, Constant, Names, Causing, Issues]`
using the same name a namespace and a class. To avoid too many unnecessary
are problematic because of a conflict with a library or just internally
Large projects will over time end up with one or two constant names that
the code that uses the gem. Enable this cop without using `Only`/`Ignore`
Generally, gems should fully qualify all constants to avoid conflicts with
unnecessarily.
This is not enabled by default because it would mark a lot of offenses
Check that certain constants are fully qualified.
def allowed_names
def allowed_names cop_config['Only'] end
def const_name?(name)
def const_name?(name) name = name.to_s (allowed_names.empty? || allowed_names.include?(name)) && !ignored_names.include?(name) end
def ignored_names
def ignored_names cop_config['Ignore'] end
def on_const(node)
def on_const(node) return if !unqualified_const?(node) || node.parent&.defined_module || node.loc.nil? add_offense(node) end