Skip to content

Commit

Permalink
Use offense instead of offence
Browse files Browse the repository at this point in the history
Follow up to c7ecb857.
  • Loading branch information
koic committed Jul 16, 2021
1 parent 82d7122 commit f2c5f0e
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -99,6 +99,10 @@ Metrics/ModuleLength:
- 'spec/**/*.rb'

Naming/InclusiveLanguage:
FlaggedTerms:
offence:
Suggestions:
- offense
Exclude:
- lib/rubocop/cop/naming/inclusive_language.rb

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/cops_style.adoc
Expand Up @@ -3330,7 +3330,7 @@ will not attempt to automatically add a binding, or add filename and
line values.

This cop works only when a string literal is given as a code string.
No offence is reported if a string variable is given as below:
No offense is reported if a string variable is given as below:

=== Examples

Expand Down
30 changes: 15 additions & 15 deletions lib/rubocop/cop/layout/hash_alignment.rb
Expand Up @@ -213,7 +213,7 @@ def on_hash(node)
check_pairs(node)
end

attr_accessor :offences_by, :column_deltas
attr_accessor :offenses_by, :column_deltas

private

Expand All @@ -224,7 +224,7 @@ def autocorrect_incompatible_with_other_cops?(node)
end

def reset!
self.offences_by = {}
self.offenses_by = {}
self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
end

Expand All @@ -248,33 +248,33 @@ def check_pairs(node)
end
end

add_offences
add_offenses
end

def add_offences
kwsplat_offences = offences_by.delete(KeywordSplatAlignment)
register_offences_with_format(kwsplat_offences, KeywordSplatAlignment)
def add_offenses
kwsplat_offenses = offenses_by.delete(KeywordSplatAlignment)
register_offenses_with_format(kwsplat_offenses, KeywordSplatAlignment)

format, offences = offences_by.min_by { |_, v| v.length }
register_offences_with_format(offences, format)
format, offenses = offenses_by.min_by { |_, v| v.length }
register_offenses_with_format(offenses, format)
end

def register_offences_with_format(offences, format)
(offences || []).each do |offence|
add_offense(offence, message: MESSAGES[format]) do |corrector|
delta = column_deltas[alignment_for(offence).first.class][offence]
def register_offenses_with_format(offenses, format)
(offenses || []).each do |offense|
add_offense(offense, message: MESSAGES[format]) do |corrector|
delta = column_deltas[alignment_for(offense).first.class][offense]

correct_node(corrector, offence, delta) unless delta.nil?
correct_node(corrector, offense, delta) unless delta.nil?
end
end
end

def check_delta(delta, node:, alignment:)
offences_by[alignment.class] ||= []
offenses_by[alignment.class] ||= []
return if good_alignment? delta

column_deltas[alignment.class][node] = delta
offences_by[alignment.class].push(node)
offenses_by[alignment.class].push(node)
end

def ignore_hash_argument?(node)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/layout/indentation_style.rb
Expand Up @@ -43,7 +43,7 @@ def on_new_investigation
str_ranges = string_literal_ranges(processed_source.ast)

processed_source.lines.each.with_index(1) do |line, lineno|
next unless (range = find_offence(line, lineno))
next unless (range = find_offense(line, lineno))
next if in_string_literal?(str_ranges, range)

add_offense(range) { |corrector| autocorrect(corrector, range) }
Expand All @@ -60,7 +60,7 @@ def autocorrect(corrector, range)
end
end

def find_offence(line, lineno)
def find_offense(line, lineno)
match = if style == :spaces
line.match(/\A\s*\t+/)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/eval_with_location.rb
Expand Up @@ -43,7 +43,7 @@ module Style
# RUBY
#
# This cop works only when a string literal is given as a code string.
# No offence is reported if a string variable is given as below:
# No offense is reported if a string variable is given as below:
#
# @example
# # not checked
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cli/options_spec.rb
Expand Up @@ -1806,7 +1806,7 @@ def f
$stdin = STDIN
end

it 'prints offence reports to stderr and corrected code to stdout if --auto-correct-all and --stderr are used' do
it 'prints offense reports to stderr and corrected code to stdout if --auto-correct-all and --stderr are used' do
$stdin = StringIO.new('p $/')
argv = ['--auto-correct-all',
'--only=Style/SpecialGlobalVars',
Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/cop/lint/mixed_regexp_capture_types_spec.rb
Expand Up @@ -37,38 +37,38 @@
# For example, `/(?<foo>#{var}*)` is interpreted as `/(?<foo>*)`.
# So it does not offense when variables are used in regexp literals.
context 'when containing a non-regexp literal' do
it 'does not register an offence when containing a lvar' do
it 'does not register an offense when containing a lvar' do
expect_no_offenses(<<~'RUBY')
var = '(\d+)'
/(?<foo>#{var}*)/
RUBY
end

it 'does not register an offence when containing a ivar' do
it 'does not register an offense when containing a ivar' do
expect_no_offenses(<<~'RUBY')
/(?<foo>#{@var}*)/
RUBY
end

it 'does not register an offence when containing a cvar' do
it 'does not register an offense when containing a cvar' do
expect_no_offenses(<<~'RUBY')
/(?<foo>#{@@var}*)/
RUBY
end

it 'does not register an offence when containing a gvar' do
it 'does not register an offense when containing a gvar' do
expect_no_offenses(<<~'RUBY')
/(?<foo>#{$var}*)/
RUBY
end

it 'does not register an offence when containing a method' do
it 'does not register an offense when containing a method' do
expect_no_offenses(<<~'RUBY')
/(?<foo>#{do_something}*)/
RUBY
end

it 'does not register an offence when containing a constant' do
it 'does not register an offense when containing a constant' do
expect_no_offenses(<<~'RUBY')
/(?<foo>#{CONST}*)/
RUBY
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/lint/out_of_range_regexp_ref_spec.rb
Expand Up @@ -66,7 +66,7 @@
# RuboCop does not know a value of variables that it will contain in the regexp literal.
# For example, `/(?<foo>#{var}*)` is interpreted as `/(?<foo>*)`.
# So it does not offense when variables are used in regexp literals.
it 'does not register an offence regexp containing non literal' do
it 'does not register an offense regexp containing non literal' do
expect_no_offenses(<<~'RUBY')
var = '(\d+)'
/(?<foo>#{var}*)/ =~ "12"
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/style/block_delimiters_spec.rb
Expand Up @@ -633,7 +633,7 @@
expect_no_offenses('each { |x| }')
end

it 'registers an offence for a multi-line block with do-end' do
it 'registers an offense for a multi-line block with do-end' do
expect_offense(<<~RUBY)
each do |x|
^^ Prefer `{...}` over `do...end` for blocks.
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/style/format_string_token_spec.rb
Expand Up @@ -21,7 +21,7 @@
expect_no_offenses("format('%#{token}', foo)")
end

it 'registers offence for dual unannotated' do
it 'registers offense for dual unannotated' do
expect_offense(<<~RUBY)
format('%#{token} %s', foo, bar)
^^ Prefer [...]
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/result_cache_spec.rb
Expand Up @@ -53,7 +53,7 @@ def abs(path)

# Fixes https://github.com/rubocop/rubocop/issues/6274
context 'when offenses are saved' do
context 'an offence with status corrected' do
context 'an offense with status corrected' do
let(:offense) do
RuboCop::Cop::Offense.new(
:warning, location, 'unused var', 'Lint/UselessAssignment', :corrected
Expand All @@ -66,7 +66,7 @@ def abs(path)
end
end

context 'an offence with status corrected_with_todo' do
context 'an offense with status corrected_with_todo' do
let(:offense) do
RuboCop::Cop::Offense.new(
:warning, location, 'unused var', 'Lint/UselessAssignment', :corrected_with_todo
Expand All @@ -79,7 +79,7 @@ def abs(path)
end
end

context 'an offence with status uncorrected' do
context 'an offense with status uncorrected' do
let(:offense) do
RuboCop::Cop::Offense.new(
:warning, location, 'unused var', 'Lint/UselessAssignment', :uncorrected
Expand All @@ -92,7 +92,7 @@ def abs(path)
end
end

context 'an offence with status unsupported' do
context 'an offense with status unsupported' do
let(:offense) do
RuboCop::Cop::Offense.new(
:warning, location, 'unused var', 'Lint/UselessAssignment', :unsupported
Expand All @@ -105,7 +105,7 @@ def abs(path)
end
end

context 'an offence with status new_status' do
context 'an offense with status new_status' do
let(:offense) do
RuboCop::Cop::Offense.new(
:warning, location, 'unused var', 'Lint/UselessAssignment', :new_status
Expand Down

0 comments on commit f2c5f0e

Please sign in to comment.