Class: RuboCop::Cop::Naming::InclusiveLanguage
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/naming/inclusive_language.rb
Overview
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).
The cop supports autocorrection when there is only one suggestion. When there are multiple suggestions, the best suggestion cannot be identified and will not be autocorrected.
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 included from RangeHelp
RangeHelp::BYTE_ORDER_MARK, RangeHelp::NOT_GIVEN
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 included from AutoCorrector
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, #always_autocorrect?, autocorrect_incompatible_with, badge, #begin_investigation, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #contextual_autocorrect?, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_other_file, #parse, #parser_engine, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_gem_version, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
permalink #initialize(config = nil, options = nil) ⇒ InclusiveLanguage
Returns a new instance of InclusiveLanguage.
84 85 86 87 88 89 90 91 |
# File 'lib/rubocop/cop/naming/inclusive_language.rb', line 84 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
permalink #on_new_investigation ⇒ Object
[View source]
93 94 95 96 |
# File 'lib/rubocop/cop/naming/inclusive_language.rb', line 93 def on_new_investigation investigate_filepath if cop_config['CheckFilepaths'] investigate_tokens end |