From 971e08dbe2105fcaa68fcdcf18d8c1d75a6d6af2 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 19 Jul 2021 11:17:39 +0900 Subject: [PATCH] Use `offense` instead of `offence` Follow up to https://github.com/rubocop/rubocop/commit/f2c5f0ea. --- .rubocop.yml | 15 +++----- lib/rubocop/cop/rails/link_to_blank.rb | 4 +-- spec/rubocop/cop/rails/content_tag_spec.rb | 36 ++++++++++---------- spec/rubocop/cop/rails/find_by_spec.rb | 4 +-- spec/rubocop/cop/rails/link_to_blank_spec.rb | 26 +++++++------- 5 files changed, 39 insertions(+), 46 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 93016e74b8..66fa55b8c9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,23 +20,16 @@ InternalAffairs/NodeMatcherDirective: Enabled: false Naming/InclusiveLanguage: + FlaggedTerms: + offence: + Suggestions: + - offense # These are excluded for compatible API names. RuboCop Rails 3.0 will fix it. Exclude: - lib/rubocop/cop/rails/dynamic_find_by.rb - lib/rubocop/cop/rails/skips_model_validations.rb - spec/rubocop/cop/rails/dynamic_find_by_spec.rb - spec/rubocop/cop/rails/skips_model_validations_spec.rb - FlaggedTerms: - whitelist: - Suggestions: - - allowlist - blacklist: - Suggestions: - - denylist - master: - AllowedRegex: - - 'blob/master/' - - 'master \(unreleased\)' Naming/PredicateName: # Method define macros for dynamically generated method. diff --git a/lib/rubocop/cop/rails/link_to_blank.rb b/lib/rubocop/cop/rails/link_to_blank.rb index 558532681c..2938f619ce 100644 --- a/lib/rubocop/cop/rails/link_to_blank.rb +++ b/lib/rubocop/cop/rails/link_to_blank.rb @@ -75,8 +75,8 @@ def append_to_rel(rel_node, corrector) corrector.replace(str_range, "#{existing_rel} noopener") end - def add_rel(send_node, offence_node, corrector) - opening_quote = offence_node.children.last.source[0] + def add_rel(send_node, offense_node, corrector) + opening_quote = offense_node.children.last.source[0] closing_quote = opening_quote == ':' ? '' : opening_quote new_rel_exp = ", rel: #{opening_quote}noopener#{closing_quote}" range = if (last_argument = send_node.last_argument).hash_type? diff --git a/spec/rubocop/cop/rails/content_tag_spec.rb b/spec/rubocop/cop/rails/content_tag_spec.rb index f2b80945fd..3890b566b5 100644 --- a/spec/rubocop/cop/rails/content_tag_spec.rb +++ b/spec/rubocop/cop/rails/content_tag_spec.rb @@ -30,7 +30,7 @@ end context 'Rails 5.1', :rails51 do - it 'corrects an offence' do + it 'corrects an offense' do expect_offense(<<~RUBY) content_tag(:p, 'Hello world!') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -41,7 +41,7 @@ RUBY end - it 'corrects an offence with empty tag' do + it 'corrects an offense with empty tag' do expect_offense(<<~RUBY) content_tag(:br) ^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -52,7 +52,7 @@ RUBY end - it 'corrects an offence with array of classnames' do + it 'corrects an offense with array of classnames' do expect_offense(<<~RUBY) content_tag(:div, "Hello world!", class: ["strong", "highlight"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -63,7 +63,7 @@ RUBY end - it 'corrects an offence with nested content_tag' do + it 'corrects an offense with nested content_tag' do expect_offense(<<~RUBY) content_tag(:div, content_tag(:span, 'foo')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -74,7 +74,7 @@ RUBY end - it 'corrects an offence with nested content_tag with block' do + it 'corrects an offense with nested content_tag with block' do expect_offense(<<~RUBY) content_tag(:div) { content_tag(:strong, 'Hi') } ^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -86,7 +86,7 @@ RUBY end - it 'corrects an offence when first argument is hash' do + it 'corrects an offense when first argument is hash' do expect_offense(<<~RUBY) content_tag({foo: 1}) ^^^^^^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -97,7 +97,7 @@ RUBY end - it 'corrects an offence when first argument is non-identifier string' do + it 'corrects an offense when first argument is non-identifier string' do expect_offense(<<~RUBY) content_tag('foo-bar', 'baz', class: 'strong') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag` instead of `content_tag`. @@ -123,25 +123,25 @@ RUBY end - it 'does not register an offence when `tag` is used with an argument' do + it 'does not register an offense when `tag` is used with an argument' do expect_no_offenses(<<~RUBY) tag.p('Hello world!') RUBY end - it 'does not register an offence when `tag` is used without arguments' do + it 'does not register an offense when `tag` is used without arguments' do expect_no_offenses(<<~RUBY) tag.br RUBY end - it 'does not register an offence when `tag` is used with arguments' do + it 'does not register an offense when `tag` is used with arguments' do expect_no_offenses(<<~RUBY) tag.div("Hello world!", class: ["strong", "highlight"]) RUBY end - it 'does not register an offence when `tag` is nested' do + it 'does not register an offense when `tag` is nested' do expect_no_offenses(<<~RUBY) tag.div() { tag.strong('Hi') } RUBY @@ -154,32 +154,32 @@ end context 'when the first argument is a variable' do - it 'does not register an offence when the first argument is a lvar' do + it 'does not register an offense when the first argument is a lvar' do expect_no_offenses(<<~RUBY) name = do_something content_tag(name, "Hello world!", class: ["strong", "highlight"]) RUBY end - it 'does not register an offence when the first argument is an ivar' do + it 'does not register an offense when the first argument is an ivar' do expect_no_offenses(<<~RUBY) content_tag(@name, "Hello world!", class: ["strong", "highlight"]) RUBY end - it 'does not register an offence when the first argument is a cvar' do + it 'does not register an offense when the first argument is a cvar' do expect_no_offenses(<<~RUBY) content_tag(@@name, "Hello world!", class: ["strong", "highlight"]) RUBY end - it 'does not register an offence when the first argument is a gvar' do + it 'does not register an offense when the first argument is a gvar' do expect_no_offenses(<<~RUBY) content_tag($name, "Hello world!", class: ["strong", "highlight"]) RUBY end - it 'does not register an offence when the first argument is a splat argument' do + it 'does not register an offense when the first argument is a splat argument' do expect_no_offenses(<<~RUBY) content_tag(*args, &block) RUBY @@ -187,7 +187,7 @@ end context 'when the first argument is a method' do - it 'does not register an offence' do + it 'does not register an offense' do expect_no_offenses(<<~RUBY) content_tag(name, "Hello world!", class: ["strong", "highlight"]) RUBY @@ -195,7 +195,7 @@ end context 'when the first argument is a constant' do - it 'does not register an offence' do + it 'does not register an offense' do expect_no_offenses(<<~RUBY) content_tag(CONST, "Hello world!", class: ["strong", "highlight"]) RUBY diff --git a/spec/rubocop/cop/rails/find_by_spec.rb b/spec/rubocop/cop/rails/find_by_spec.rb index 3b8b337d9a..7a142dc771 100644 --- a/spec/rubocop/cop/rails/find_by_spec.rb +++ b/spec/rubocop/cop/rails/find_by_spec.rb @@ -88,7 +88,7 @@ context 'when receiver is not an Active Record' do context 'when method is Array#take' do - it 'does not register an offence' do + it 'does not register an offense' do expect_no_offenses(<<~RUBY) array = Array.new(1) { rand } array.compact.take @@ -97,7 +97,7 @@ end context 'when method is Array#first' do - it 'does not register an offence' do + it 'does not register an offense' do expect_no_offenses(<<~RUBY) array = Array.new(1) { rand } array.compact.first diff --git a/spec/rubocop/cop/rails/link_to_blank_spec.rb b/spec/rubocop/cop/rails/link_to_blank_spec.rb index 6d839fa2f6..656b26ae9b 100644 --- a/spec/rubocop/cop/rails/link_to_blank_spec.rb +++ b/spec/rubocop/cop/rails/link_to_blank_spec.rb @@ -2,19 +2,19 @@ RSpec.describe RuboCop::Cop::Rails::LinkToBlank, :config do context 'when not using target _blank' do - it 'does not register an offence' do + it 'does not register an offense' do expect_no_offenses(<<~RUBY) link_to 'Click here', 'https://www.example.com' RUBY end - it 'does not register an offence when passing options' do + it 'does not register an offense when passing options' do expect_no_offenses(<<~RUBY) link_to 'Click here', 'https://www.example.com', class: 'big' RUBY end - it 'does not register an offence when using the block syntax' do + it 'does not register an offense when using the block syntax' do expect_no_offenses(<<~RUBY) link_to 'https://www.example.com', class: 'big' do "Click Here" @@ -25,7 +25,7 @@ context 'when using target_blank' do context 'when using no rel' do - it 'registers and corrects an offence' do + it 'registers and corrects an offense' do expect_offense(<<~RUBY) link_to 'Click here', 'https://www.example.com', target: '_blank' ^^^^^^^^^^^^^^^^ Specify a `:rel` option containing noopener. @@ -36,21 +36,21 @@ RUBY end - it 'registers an offence when using a string for the target key' do + it 'registers an offense when using a string for the target key' do expect_offense(<<~RUBY) link_to 'Click here', 'https://www.example.com', "target" => '_blank' ^^^^^^^^^^^^^^^^^^^^ Specify a `:rel` option containing noopener. RUBY end - it 'registers an offence when using a symbol for the target value' do + it 'registers an offense when using a symbol for the target value' do expect_offense(<<~RUBY) link_to 'Click here', 'https://www.example.com', target: :_blank ^^^^^^^^^^^^^^^ Specify a `:rel` option containing noopener. RUBY end - it 'registers an offence and auto-corrects when using the block syntax' do + it 'registers an offense and auto-corrects when using the block syntax' do expect_offense(<<~RUBY) link_to 'https://www.example.com', target: '_blank' do ^^^^^^^^^^^^^^^^ Specify a `:rel` option containing noopener. @@ -90,7 +90,7 @@ RUBY end - it 'registers and corrects an offence when using hash brackets for the option' do + it 'registers and corrects an offense when using hash brackets for the option' do expect_offense(<<~RUBY) link_to 'Click here', 'https://www.example.com', { target: :_blank } ^^^^^^^^^^^^^^^ Specify a `:rel` option containing noopener. @@ -104,7 +104,7 @@ context 'when using rel' do context 'when the rel does not contain noopener' do - it 'registers an offence and corrects' do + it 'registers an offense and corrects' do expect_offense(<<~RUBY) link_to 'Click here', 'https://www.example.com', "target" => '_blank', rel: 'unrelated' ^^^^^^^^^^^^^^^^^^^^ Specify a `:rel` option containing noopener. @@ -117,7 +117,7 @@ end context 'when the rel contains noopener' do - it 'register no offence' do + it 'register no offense' do expect_no_offenses(<<~RUBY) link_to 'Click here', 'https://www.example.com', target: '_blank', rel: 'noopener unrelated' RUBY @@ -125,7 +125,7 @@ end context 'when the rel contains noreferrer' do - it 'register no offence' do + it 'register no offense' do expect_no_offenses(<<~RUBY) link_to 'Click here', 'https://www.example.com', target: '_blank', rel: 'unrelated noreferrer' RUBY @@ -133,7 +133,7 @@ end context 'when the rel contains noopener and noreferrer' do - it 'register no offence' do + it 'register no offense' do expect_no_offenses(<<~RUBY) link_to 'Click here', 'https://www.example.com', target: '_blank', rel: 'noopener noreferrer' RUBY @@ -141,7 +141,7 @@ end context 'when the rel is symbol noopener' do - it 'register no offence' do + it 'register no offense' do expect_no_offenses(<<~RUBY) link_to 'Click here', 'https://www.example.com', target: :_blank, rel: :noopener RUBY