Class: RuboCop::Cop::Naming::InclusiveLanguage
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/naming/inclusive_language.rb
Overview
This cops recommends the use of inclusive language instead of problematic terms. The cop can check the following locations for offenses:
-
identifiers
-
constants
-
variables
-
strings
-
symbols
-
comments
-
file paths
Each of these locations can be individually enabled/disabled via configuration, for example CheckIdentifiers = true/false.
Flagged terms are configurable for the cop. For each flagged term an optional Regex can be specified to identify offenses. Suggestions for replacing a flagged term can be configured and will be displayed as part of the offense message. An AllowedRegex can be specified for a flagged term to exempt allowed uses of the term. ‘WholeWord: true` can be set on a flagged term to indicate the cop should only match when a term matches the whole word (partial matches will not be offenses).
Defined Under Namespace
Classes: WordLocation
Constant Summary collapse
- EMPTY_ARRAY =
[].freeze
- MSG =
"Consider replacing '%<term>s'%<suffix>s."
- MSG_FOR_FILE_PATH =
"Consider replacing '%<term>s' in file path%<suffix>s."
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(config = nil, options = nil) ⇒ InclusiveLanguage
constructor
A new instance of InclusiveLanguage.
- #on_new_investigation ⇒ Object
Methods inherited from Base
#add_global_offense, #add_offense, autocorrect_incompatible_with, badge, callbacks_needed, #callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #cop_config, #cop_name, cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_other_file, #parse, #ready, #relevant_file?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
#initialize(config = nil, options = nil) ⇒ InclusiveLanguage
Returns a new instance of InclusiveLanguage.
78 79 80 81 82 83 84 85 |
# File 'lib/rubocop/cop/naming/inclusive_language.rb', line 78 def initialize(config = nil, = nil) super @flagged_term_hash = {} @flagged_terms_regex = nil @allowed_regex = nil @check_token = preprocess_check_config preprocess_flagged_terms end |
Instance Method Details
#on_new_investigation ⇒ Object
87 88 89 90 |
# File 'lib/rubocop/cop/naming/inclusive_language.rb', line 87 def on_new_investigation investigate_filepath if cop_config['CheckFilepaths'] investigate_tokens end |