Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gem "activesupport", require: false
gem "mry", require: false
gem "parser"
gem "pry", require: false
gem "rubocop", "1.32.0", require: false
gem "rubocop", "1.33.0", require: false
gem "rubocop-i18n", require: false
gem "rubocop-graphql", require: false
gem "rubocop-minitest", require: false
Expand Down
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.32.0)
rubocop (1.33.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.0.0)
Expand All @@ -51,13 +51,13 @@ GEM
rubocop-ast (>= 1.19.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.19.1)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-graphql (0.14.4)
rubocop-graphql (0.14.5)
rubocop (>= 0.87, < 2)
rubocop-i18n (3.0.0)
rubocop (~> 1.0)
rubocop-minitest (0.20.1)
rubocop-minitest (0.21.0)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.14.3)
rubocop (>= 1.7.0, < 2.0)
Expand All @@ -72,8 +72,8 @@ GEM
rubocop (~> 1.31)
rubocop-sequel (0.3.4)
rubocop (~> 1.0)
rubocop-shopify (2.8.0)
rubocop (~> 1.31)
rubocop-shopify (2.9.0)
rubocop (~> 1.33)
rubocop-sorbet (0.6.11)
rubocop (>= 0.90.0)
rubocop-thread_safety (0.4.4)
Expand All @@ -94,7 +94,7 @@ DEPENDENCIES
pry
rake
rspec
rubocop (= 1.32.0)
rubocop (= 1.33.0)
rubocop-graphql
rubocop-i18n
rubocop-minitest
Expand Down
19 changes: 15 additions & 4 deletions config/contents/lint/ambiguous_block_association.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Checks for ambiguous block association with method
when param passed without parentheses.

This cop can customize ignored methods with `IgnoredMethods`.
By default, there are no methods to ignored.
This cop can customize allowed methods with `AllowedMethods`.
By default, there are no methods to allowed.

### Example:

Expand All @@ -25,12 +25,23 @@ By default, there are no methods to ignored.
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }

### Example: IgnoredMethods: [] (default)
### Example: AllowedMethods: [] (default)

# bad
expect { do_something }.to change { object.attribute }

### Example: IgnoredMethods: [change]
### Example: AllowedMethods: [change]

# good
expect { do_something }.to change { object.attribute }

### Example: AllowedPatterns: [] (default)

# bad
expect { do_something }.to change { object.attribute }

### Example: AllowedPatterns: [/change/]

# good
expect { do_something }.to change { object.attribute }
expect { do_something }.to not_change { object.attribute }
11 changes: 10 additions & 1 deletion config/contents/lint/debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ Specific default groups can be disabled if necessary:

```yaml
Lint/Debugger:
WebConsole: ~
DebuggerMethods:
WebConsole: ~
```

You can also add your own methods by adding a new category:

```yaml
Lint/Debugger:
DebuggerMethods:
MyDebugger:
MyDebugger.debug_this
```

### Example:

Expand Down
3 changes: 3 additions & 0 deletions config/contents/lint/empty_conditional_body.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Checks for the presence of `if`, `elsif` and `unless` branches without a body.

NOTE: empty `else` branches are handled by `Style/EmptyElse`.

### Example:
# bad
if condition
Expand Down
18 changes: 14 additions & 4 deletions config/contents/lint/number_conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ always correct to raise if a value is not numeric.
NOTE: Some values cannot be converted properly using one of the `Kernel`
method (for instance, `Time` and `DateTime` values are allowed by this
cop by default). Similarly, Rails' duration methods do not work well
with `Integer()` and can be ignored with `IgnoredMethods`. By default,
there are no methods to ignored.
with `Integer()` and can be allowed with `AllowedMethods`. By default,
there are no methods to allowed.

### Safety:

Expand Down Expand Up @@ -42,12 +42,22 @@ input if it is not a standard class.
foo.try { |i| Float(i) }
bar.send { |i| Complex(i) }

### Example: IgnoredMethods: [] (default)
### Example: AllowedMethods: [] (default)

# bad
10.minutes.to_i

### Example: IgnoredMethods: [minutes]
### Example: AllowedMethods: [minutes]

# good
10.minutes.to_i

### Example: AllowedPatterns: [] (default)

# bad
10.minutes.to_i

### Example: AllowedPatterns: [/min*/]

# good
10.minutes.to_i
Expand Down
3 changes: 2 additions & 1 deletion config/contents/metrics/abc_size.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ is meant to distinguish actual `attr_reader` from other methods.
render 'pages/search/page'
end

This cop also takes into account `IgnoredMethods` (defaults to `[]`)
This cop also takes into account `AllowedMethods` (defaults to `[]`)
And `AllowedPatterns` (defaults to `[]`)
4 changes: 2 additions & 2 deletions config/contents/metrics/block_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ will be counted as one line regardless of its actual size.


NOTE: The `ExcludedMethods` configuration is deprecated and only kept
for backwards compatibility. Please use `IgnoredMethods` instead.
By default, there are no methods to ignored.
for backwards compatibility. Please use `AllowedMethods` and `AllowedPatterns`
instead. By default, there are no methods to allowed.

### Example: CountAsOne: ['array', 'heredoc']

Expand Down
9 changes: 5 additions & 4 deletions config/contents/metrics/method_length.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Checks if the length of a method exceeds some maximum value.
Comment lines can optionally be ignored.
Comment lines can optionally be allowed.
The maximum allowed length is configurable.

You can set literals you want to fold with `CountAsOne`.
Available are: 'array', 'hash', and 'heredoc'. Each literal
will be counted as one line regardless of its actual size.

NOTE: The `ExcludedMethods` configuration is deprecated and only kept
for backwards compatibility. Please use `IgnoredMethods` instead.
By default, there are no methods to ignored.
NOTE: The `ExcludedMethods` and `IgnoredMethods` configuration is
deprecated and only kept for backwards compatibility.
Please use `AllowedMethods` and `AllowedPatterns` instead.
By default, there are no methods to allowed.

### Example: CountAsOne: ['array', 'heredoc']

Expand Down
27 changes: 24 additions & 3 deletions config/contents/naming/predicate_name.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
Makes sure that predicates are named properly.
`is_a?` method is allowed by default.
These are customizable with `AllowedMethods` option.
Checks that predicate methods names end with a question mark and
do not start with a forbidden prefix.

A method is determined to be a predicate method if its name starts
with one of the prefixes defined in the `NamePrefix` configuration.
You can change what prefixes are considered by changing this option.
Any method name that starts with one of these prefixes is required by
the cop to end with a `?`. Other methods can be allowed by adding to
the `AllowedMethods` configuration.

NOTE: The `is_a?` method is allowed by default.

If `ForbiddenPrefixes` is set, methods that start with the configured
prefixes will not be allowed and will be removed by autocorrection.

In other words, if `ForbiddenPrefixes` is empty, a method named `is_foo`
will register an offense only due to the lack of question mark (and will be
autocorrected to `is_foo?`). If `ForbiddenPrefixes` contains `is_`,
`is_foo` will register an offense both because the ? is missing and because of
the `is_` prefix, and will be corrected to `foo?`.

NOTE: `ForbiddenPrefixes` is only applied to prefixes in `NamePrefix`;
a prefix in the former but not the latter will not be considered by
this cop.

### Example:
# bad
Expand Down
24 changes: 20 additions & 4 deletions config/contents/style/block_delimiters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ multi-line blocks.
Methods that can be either procedural or functional and cannot be
categorised from their usage alone is ignored.
`lambda`, `proc`, and `it` are their defaults.
Additional methods can be added to the `IgnoredMethods`.
Additional methods can be added to the `AllowedMethods`.

### Example: EnforcedStyle: line_count_based (default)
# bad - single line block
Expand Down Expand Up @@ -60,7 +60,7 @@ Additional methods can be added to the `IgnoredMethods`.
x
}.inspect

# The AllowBracesOnProceduralOneLiners option is ignored unless the
# The AllowBracesOnProceduralOneLiners option is allowed unless the
# EnforcedStyle is set to `semantic`. If so:

# If the AllowBracesOnProceduralOneLiners option is unspecified, or
Expand Down Expand Up @@ -110,7 +110,7 @@ Additional methods can be added to the `IgnoredMethods`.

# Methods listed in the BracesRequiredMethods list, such as 'sig'
# in this example, will require `{...}` braces. This option takes
# precedence over all other configurations except IgnoredMethods.
# precedence over all other configurations except AllowedMethods.

# bad
sig do
Expand All @@ -132,7 +132,7 @@ Additional methods can be added to the `IgnoredMethods`.
puts foo
end

### Example: IgnoredMethods: ['lambda', 'proc', 'it' ] (default)
### Example: AllowedMethods: ['lambda', 'proc', 'it' ] (default)

# good
foo = lambda do |x|
Expand All @@ -142,3 +142,19 @@ Additional methods can be added to the `IgnoredMethods`.
foo = lambda do |x|
x * 100
end

### Example: AllowedPatterns: [] (default)

# bad
things.map { |thing|
something = thing.some_method
process(something)
}

### Example: AllowedPatterns: [/map/]

# good
things.map { |thing|
something = thing.some_method
process(something)
}
28 changes: 24 additions & 4 deletions config/contents/style/class_equality_comparison.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Enforces the use of `Object#instance_of?` instead of class comparison
for equality.
`==`, `equal?`, and `eql?` methods are ignored by default.
These are customizable with `IgnoredMethods` option.
`==`, `equal?`, and `eql?` methods are allowed by default.
These are customizable with `AllowedMethods` option.

### Example:
# bad
Expand All @@ -13,7 +13,7 @@ These are customizable with `IgnoredMethods` option.
# good
var.instance_of?(Date)

### Example: IgnoreMethods: [] (default)
### Example: AllowedMethods: [] (default)
# good
var.instance_of?(Date)

Expand All @@ -23,7 +23,7 @@ These are customizable with `IgnoredMethods` option.
var.class.eql?(Date)
var.class.name == 'Date'

### Example: IgnoreMethods: [`==`]
### Example: AllowedMethods: [`==`]
# good
var.instance_of?(Date)
var.class == Date
Expand All @@ -32,3 +32,23 @@ These are customizable with `IgnoredMethods` option.
# bad
var.class.equal?(Date)
var.class.eql?(Date)

### Example: AllowedPatterns: [] (default)
# good
var.instance_of?(Date)

# bad
var.class == Date
var.class.equal?(Date)
var.class.eql?(Date)
var.class.name == 'Date'

### Example: AllowedPatterns: [`/eq/`]
# good
var.instance_of?(Date)
var.class.equal?(Date)
var.class.eql?(Date)

# bad
var.class == Date
var.class.name == 'Date'
18 changes: 14 additions & 4 deletions config/contents/style/format_string_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ which are passed as arguments to those methods:
The reason is that _unannotated_ format is very similar
to encoded URLs or Date/Time formatting strings.

This cop can be customized ignored methods with `IgnoredMethods`.
By default, there are no methods to ignored.
This cop can be customized allowed methods with `AllowedMethods`.
By default, there are no methods to allowed.

### Example: EnforcedStyle: annotated (default)

Expand Down Expand Up @@ -57,12 +57,22 @@ if the number of them is less than or equals to
# good
format('%06d', 10)

### Example: IgnoredMethods: [] (default)
### Example: AllowedMethods: [] (default)

# bad
redirect('foo/%{bar_id}')

### Example: IgnoredMethods: [redirect]
### Example: AllowedMethods: [redirect]

# good
redirect('foo/%{bar_id}')

### Example: AllowedPatterns: [] (default)

# bad
redirect('foo/%{bar_id}')

### Example: AllowedPatterns: [/redirect/]

# good
redirect('foo/%{bar_id}')
Loading