class RuboCop::Cop::Inclusivity::Race
Detects potentially insensitive langugae used in variable names and suggests alternatives that promote inclusivity.
The `Offenses` config parameter can be used to configure the cop with your list of insensitive words.
@example Using insensitive language
# bad blacklist = 1 # good banlist = 1
Constants
- MSG
Public Instance Methods
on_lvasgn(node)
click to toggle source
# File lib/rubocop/cop/inclusivity/race.rb, line 22 def on_lvasgn(node) name, = *node return unless name check_name(node, name, node.loc.name) end
Also aliased as: on_ivasgn, on_cvasgn, on_arg, on_optarg, on_restarg, on_kwoptarg, on_kwarg, on_kwrestarg, on_blockarg, on_lvar
Private Instance Methods
check_name(node, name, name_range)
click to toggle source
# File lib/rubocop/cop/inclusivity/race.rb, line 41 def check_name(node, name, name_range) if (alternatives = preferred_language(name)) msg = message(name, alternatives) add_offense(node, location: name_range, message: msg) end end
message(insensitive, alternatives)
click to toggle source
# File lib/rubocop/cop/inclusivity/race.rb, line 52 def message(insensitive, alternatives) format(MSG, insensitive, alternatives.join(", ")) end
preferred_language(word)
click to toggle source
# File lib/rubocop/cop/inclusivity/race.rb, line 48 def preferred_language(word) cop_config["Offenses"][word.to_s.downcase] end