Skip to content

Commit

Permalink
Use offense instead of offence
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Jul 19, 2021
1 parent a073d9a commit 971e08d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 46 deletions.
15 changes: 4 additions & 11 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rails/link_to_blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
36 changes: 18 additions & 18 deletions spec/rubocop/cop/rails/content_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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
Expand All @@ -154,48 +154,48 @@
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
end
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
end
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
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rails/find_by_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions spec/rubocop/cop/rails/link_to_blank_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -117,31 +117,31 @@
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
end
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
end
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
end
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
Expand Down

0 comments on commit 971e08d

Please sign in to comment.