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_arg(node)
Alias for: on_lvasgn
on_blockarg(node)
Alias for: on_lvasgn
on_cvasgn(node)
Alias for: on_lvasgn
on_ivasgn(node)
Alias for: on_lvasgn
on_kwarg(node)
Alias for: on_lvasgn
on_kwoptarg(node)
Alias for: on_lvasgn
on_kwrestarg(node)
Alias for: on_lvasgn
on_lvar(node)
Alias for: on_lvasgn
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
on_optarg(node)
Alias for: on_lvasgn
on_restarg(node)
Alias for: on_lvasgn

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