From f2a54954c313757ded31ce9848611998b6c4b11c Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Fri, 10 Sep 2021 09:56:23 -0400 Subject: [PATCH] Update `Naming/InclusiveLanguage` to be disabled by default. --- ...ge_update_naminginclusivelanguage_to_be.md | 1 + config/default.yml | 3 +- lib/rubocop/cop/naming/inclusive_language.rb | 18 +++--- .../cop/naming/inclusive_language_spec.rb | 63 +++++++++---------- 4 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 changelog/change_update_naminginclusivelanguage_to_be.md diff --git a/changelog/change_update_naminginclusivelanguage_to_be.md b/changelog/change_update_naminginclusivelanguage_to_be.md new file mode 100644 index 00000000000..51100ff2b8a --- /dev/null +++ b/changelog/change_update_naminginclusivelanguage_to_be.md @@ -0,0 +1 @@ +* [#10074](https://github.com/rubocop/rubocop/pull/10074): Update `Naming/InclusiveLanguage` to be disabled by default. ([@dvandersluis][]) diff --git a/config/default.yml b/config/default.yml index 633034c71da..6631235c2be 100644 --- a/config/default.yml +++ b/config/default.yml @@ -2569,8 +2569,9 @@ Naming/HeredocDelimiterNaming: Naming/InclusiveLanguage: Description: 'Recommend the use of inclusive language instead of problematic terms.' - Enabled: pending + Enabled: false VersionAdded: '1.18' + VersionChanged: '<>' CheckIdentifiers: true CheckConstants: true CheckVariables: true diff --git a/lib/rubocop/cop/naming/inclusive_language.rb b/lib/rubocop/cop/naming/inclusive_language.rb index 0b5a546c763..75f16ce1e2a 100644 --- a/lib/rubocop/cop/naming/inclusive_language.rb +++ b/lib/rubocop/cop/naming/inclusive_language.rb @@ -70,6 +70,8 @@ class InclusiveLanguage < Base include RangeHelp EMPTY_ARRAY = [].freeze + MSG = "Consider replacing '%s'%s." + MSG_FOR_FILE_PATH = "Consider replacing '%s' in file path%s." WordLocation = Struct.new(:word, :position) @@ -197,12 +199,11 @@ def investigate_filepath end def create_single_word_message_for_file(word) - create_message(word).sub(/\.$/, ' in file path.') + create_message(word, MSG_FOR_FILE_PATH) end def create_multiple_word_message_for_file(words) - quoted_words = words.map { |word| "'#{word}'" } - "Consider replacing problematic terms #{quoted_words.join(', ')} in file path." + format(MSG_FOR_FILE_PATH, term: words.join("', '"), suffix: ' with other terms') end def scan_for_words(input) @@ -223,9 +224,12 @@ def mask_input(str) safe_str.gsub(@allowed_regex) { |match| '*' * match.size } end - def create_message(word) + def create_message(word, message = MSG) flagged_term = find_flagged_term(word) - "Consider replacing problematic term '#{word}'#{flagged_term['SuggestionString']}." + suggestions = flagged_term['SuggestionString'] + suggestions = ' with another term' if suggestions.blank? + + format(message, term: word, suffix: suggestions) end def find_flagged_term(word) @@ -235,10 +239,6 @@ def find_flagged_term(word) flagged_term end - def create_message_for_file(word) - create_message(word).sub(/\.$/, ' in file path.') - end - def preprocess_suggestions(suggestions) return '' if suggestions.nil? || (suggestions.is_a?(String) && suggestions.strip.empty?) || suggestions.empty? diff --git a/spec/rubocop/cop/naming/inclusive_language_spec.rb b/spec/rubocop/cop/naming/inclusive_language_spec.rb index d811fe1c629..e150c4e9656 100644 --- a/spec/rubocop/cop/naming/inclusive_language_spec.rb +++ b/spec/rubocop/cop/naming/inclusive_language_spec.rb @@ -9,14 +9,14 @@ it 'registers an offense when using a flagged term' do expect_offense(<<~RUBY) whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist'. + ^^^^^^^^^ Consider replacing 'whitelist' with another term. RUBY end it 'registers an offense when using a flagged term with mixed case' do expect_offense(<<~RUBY) class WhiteList - ^^^^^^^^^ Consider replacing problematic term 'WhiteList'. + ^^^^^^^^^ Consider replacing 'WhiteList' with another term. end RUBY end @@ -24,7 +24,7 @@ class WhiteList it 'registers an offense for a partial word match' do expect_offense(<<~RUBY) class Nodewhitelist - ^^^^^^^^^ Consider replacing problematic term 'whitelist'. + ^^^^^^^^^ Consider replacing 'whitelist' with another term. end RUBY end @@ -37,7 +37,7 @@ class Nodewhitelist it 'ignores flagged terms that are set to nil' do expect_offense(<<~RUBY) # working on replacing whitelist and blacklist - ^^^^^^^^^ Consider replacing problematic term 'blacklist'. + ^^^^^^^^^ Consider replacing 'blacklist' with another term. RUBY end end @@ -53,8 +53,8 @@ class Nodewhitelist it 'registers an offense for each word' do expect_offense(<<~RUBY) master, slave = nodes - ^^^^^ Consider replacing problematic term 'slave' with 'replica', 'secondary', or 'follower'. - ^^^^^^ Consider replacing problematic term 'master' with 'main', 'primary', or 'leader'. + ^^^^^ Consider replacing 'slave' with 'replica', 'secondary', or 'follower'. + ^^^^^^ Consider replacing 'master' with 'main', 'primary', or 'leader'. RUBY end end @@ -67,7 +67,7 @@ class Nodewhitelist it 'registers an offense for a flagged term matched with a regexp' do expect_offense(<<~RUBY) # white-list of IPs - ^^^^^^^^^^ Consider replacing problematic term 'white-list'. + ^^^^^^^^^^ Consider replacing 'white-list' with another term. RUBY end end @@ -92,11 +92,11 @@ class Nodewhitelist # not allowed Slave - ^^^^^ Consider replacing problematic term 'Slave'. + ^^^^^ Consider replacing 'Slave' with another term. :database_slave - ^^^^^ Consider replacing problematic term 'slave'. + ^^^^^ Consider replacing 'slave' with another term. 'database@slave' - ^^^^^ Consider replacing problematic term 'slave'. + ^^^^^ Consider replacing 'slave' with another term. RUBY end end @@ -126,7 +126,7 @@ class Nodewhitelist it 'registers an offense at the correct location' do expect_offense(<<~RUBY) barx, foo = method_call - ^^^ Consider replacing problematic term 'foo'. + ^^^ Consider replacing 'foo' with another term. RUBY end end @@ -143,7 +143,7 @@ class Nodewhitelist it 'includes the suggestion in the offense message' do expect_offense(<<~RUBY) whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist' with 'allowlist'. + ^^^^^^^^^ Consider replacing 'whitelist' with 'allowlist'. RUBY end end @@ -158,7 +158,7 @@ class Nodewhitelist it 'includes both suggestions in the offense message' do expect_offense(<<~RUBY) whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist' with 'allowlist' or 'permit'. + ^^^^^^^^^ Consider replacing 'whitelist' with 'allowlist' or 'permit'. RUBY end end @@ -176,7 +176,7 @@ class Nodewhitelist it 'includes all suggestions in the message' do expect_offense(<<~RUBY) default_branch = 'master' - ^^^^^^ Consider replacing problematic term 'master' with 'main', 'primary', or 'leader'. + ^^^^^^ Consider replacing 'master' with 'main', 'primary', or 'leader'. RUBY end end @@ -193,7 +193,7 @@ class Nodewhitelist it 'registers an offense' do expect_offense(<<~RUBY) whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist'. + ^^^^^^^^^ Consider replacing 'whitelist' with another term. RUBY end end @@ -220,21 +220,21 @@ class Nodewhitelist it 'registers offenses for instance variables' do expect_offense(<<~RUBY) @whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist'. + ^^^^^^^^^ Consider replacing 'whitelist' with another term. RUBY end it 'registers offenses for class variables' do expect_offense(<<~RUBY) @@whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist'. + ^^^^^^^^^ Consider replacing 'whitelist' with another term. RUBY end it 'registers offenses for global variables' do expect_offense(<<~RUBY) $whitelist = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'whitelist'. + ^^^^^^^^^ Consider replacing 'whitelist' with another term. RUBY end end @@ -261,7 +261,7 @@ class Nodewhitelist it 'registers offenses for constants' do expect_offense(<<~RUBY) WHITELIST = %w(user1 user2) - ^^^^^^^^^ Consider replacing problematic term 'WHITELIST'. + ^^^^^^^^^ Consider replacing 'WHITELIST' with another term. RUBY end end @@ -286,7 +286,7 @@ class Nodewhitelist it 'registers an offense for an interpolated string' do expect_offense(<<~RUBY) puts "master node \#{node}" - ^^^^^^ Consider replacing problematic term 'master'. + ^^^^^^ Consider replacing 'master' with another term. RUBY end @@ -294,9 +294,9 @@ class Nodewhitelist it 'registers an offense for a multiline string' do expect_offense(<<~RUBY) node_types = "master - ^^^^^^ Consider replacing problematic term 'master'. + ^^^^^^ Consider replacing 'master' with another term. slave - ^^^^^ Consider replacing problematic term 'slave'. + ^^^^^ Consider replacing 'slave' with another term. primary secondary" RUBY @@ -306,10 +306,10 @@ class Nodewhitelist expect_offense(<<~RUBY) node_text = <<~TEXT master - ^^^^^^ Consider replacing problematic term 'master'. + ^^^^^^ Consider replacing 'master' with another term. primary slave - ^^^^^ Consider replacing problematic term 'slave'. + ^^^^^ Consider replacing 'slave' with another term. secondary TEXT RUBY @@ -337,7 +337,7 @@ class Nodewhitelist it 'registers an offense' do expect_offense(<<~RUBY) config[:master] = {} - ^^^^^^ Consider replacing problematic term 'master'. + ^^^^^^ Consider replacing 'master' with another term. RUBY end end @@ -362,9 +362,9 @@ class Nodewhitelist it 'registers an offense in a single line comment' do expect_offense(<<~RUBY) # is it a foo? - ^^^ Consider replacing problematic term 'foo'. + ^^^ Consider replacing 'foo' with another term. bar = baz # it's a foo! - ^^^ Consider replacing problematic term 'foo'. + ^^^ Consider replacing 'foo' with another term. RUBY end @@ -372,7 +372,7 @@ class Nodewhitelist expect_offense(<<~RUBY) =begin foo - ^^^ Consider replacing problematic term 'foo'. + ^^^ Consider replacing 'foo' with another term. bar =end RUBY @@ -405,8 +405,7 @@ class Nodewhitelist it 'registers an offense' do expect(offenses.size).to eq(1) - expect(messages) - .to eq(["Consider replacing problematic term 'master' with 'main' in file path."]) + expect(messages).to eq(["Consider replacing 'master' in file path with 'main'."]) end end @@ -419,7 +418,7 @@ class Nodewhitelist it 'registers an offense with all problematic words' do expect(offenses.size).to eq(1) expect(messages) - .to eq(["Consider replacing problematic terms 'master', 'slave' in file path."]) + .to eq(["Consider replacing 'master', 'slave' in file path with other terms."]) end end @@ -431,7 +430,7 @@ class Nodewhitelist it 'registers an offense for a director' do expect(offenses.size).to eq(1) - expect(messages).to eq(["Consider replacing problematic term 'master' in file path."]) + expect(messages).to eq(["Consider replacing 'master' in file path with another term."]) end end