diff --git a/Gemfile b/Gemfile index 12416a91..5080b5af 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ source 'https://rubygems.org' gem "activesupport", require: false gem "parser" gem "pry", require: false -gem "rubocop", "1.35.0", require: false +gem "rubocop", "1.36.0", require: false gem "rubocop-i18n", require: false gem "rubocop-graphql", require: false gem "rubocop-minitest", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 6784b43d..b716397b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (7.0.3.1) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -21,7 +21,7 @@ GEM pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) - rack (2.2.4) + rack (3.0.0) rainbow (3.1.1) rake (13.0.6) regexp_parser (2.5.0) @@ -32,14 +32,14 @@ GEM rspec-mocks (~> 3.11.0) rspec-core (3.11.0) rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) + rspec-expectations (3.11.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.0) - rubocop (1.35.0) + rubocop (1.36.0) json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.2.1) @@ -51,23 +51,23 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.21.0) parser (>= 3.1.1.0) - rubocop-graphql (0.14.5) + rubocop-graphql (0.14.6) rubocop (>= 0.87, < 2) rubocop-i18n (3.0.0) rubocop (~> 1.0) - rubocop-minitest (0.21.0) + rubocop-minitest (0.22.0) rubocop (>= 0.90, < 2.0) - rubocop-performance (1.14.3) + rubocop-performance (1.15.0) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.15.2) + rubocop-rails (2.16.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.7.0, < 2.0) + rubocop (>= 1.33.0, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.12.1) - rubocop (~> 1.31) + rubocop-rspec (2.13.0) + rubocop (~> 1.33) rubocop-sequel (0.3.4) rubocop (~> 1.0) rubocop-shopify (2.9.0) @@ -91,7 +91,7 @@ DEPENDENCIES pry rake rspec - rubocop (= 1.35.0) + rubocop (= 1.36.0) rubocop-graphql rubocop-i18n rubocop-minitest diff --git a/config/contents/layout/block_alignment.md b/config/contents/layout/block_alignment.md index 4f3fdb57..bc7e04f8 100644 --- a/config/contents/layout/block_alignment.md +++ b/config/contents/layout/block_alignment.md @@ -17,23 +17,24 @@ location. The autofixer will default to `start_of_line`. # bad foo.bar - .each do - baz - end + .each do + baz + end # good - variable = lambda do |i| - i + foo.bar + .each do + baz end ### Example: EnforcedStyleAlignWith: start_of_block # bad foo.bar - .each do - baz - end + .each do + baz + end # good @@ -46,13 +47,13 @@ location. The autofixer will default to `start_of_line`. # bad foo.bar - .each do - baz - end + .each do + baz + end # good foo.bar .each do - baz - end \ No newline at end of file + baz + end diff --git a/config/contents/layout/end_of_line.md b/config/contents/layout/end_of_line.md index 6099fb74..8a6f4070 100644 --- a/config/contents/layout/end_of_line.md +++ b/config/contents/layout/end_of_line.md @@ -17,17 +17,17 @@ Checks for Windows-style line endings in the source code. # all platforms. # bad - puts 'Hello' # Return character is CR+LF on all platfoms. + puts 'Hello' # Return character is CR+LF on all platforms. # good - puts 'Hello' # Return character is LF on all platfoms. + puts 'Hello' # Return character is LF on all platforms. ### Example: EnforcedStyle: crlf # The `crlf` style means that CR+LF (Carriage Return + Line Feed) is # enforced on all platforms. # bad - puts 'Hello' # Return character is LF on all platfoms. + puts 'Hello' # Return character is LF on all platforms. # good - puts 'Hello' # Return character is CR+LF on all platfoms. + puts 'Hello' # Return character is CR+LF on all platforms. diff --git a/config/contents/lint/duplicate_require.md b/config/contents/lint/duplicate_require.md index 9aa92ebf..d02e1f40 100644 --- a/config/contents/lint/duplicate_require.md +++ b/config/contents/lint/duplicate_require.md @@ -1,4 +1,4 @@ -Checks for duplicate `require`s and `require_relative`s. +Checks for duplicate ``require``s and ``require_relative``s. ### Safety: diff --git a/config/contents/lint/redundant_safe_navigation.md b/config/contents/lint/redundant_safe_navigation.md index 7660d154..8e050009 100644 --- a/config/contents/lint/redundant_safe_navigation.md +++ b/config/contents/lint/redundant_safe_navigation.md @@ -2,6 +2,11 @@ Checks for redundant safe navigation calls. `instance_of?`, `kind_of?`, `is_a?`, `eql?`, `respond_to?`, and `equal?` methods are checked by default. These are customizable with `AllowedMethods` option. +The `AllowedMethods` option specifies nil-safe methods, +in other words, it is a method that is allowed to skip safe navigation. +Note that the `AllowedMethod` option is not an option that specifies methods +for which to suppress (allow) this cop's check. + In the example below, the safe navigation operator (`&.`) is unnecessary because `NilClass` has methods like `respond_to?` and `is_a?`. @@ -31,9 +36,10 @@ will be autocorrected to never return `nil`. # good - without `&.` this will always return `true` foo&.respond_to?(:to_a) -### Example: AllowedMethods: [foo?] +### Example: AllowedMethods: [nil_safe_method] # bad - do_something if attrs&.foo?(:[]) + do_something if attrs&.nil_safe_method(:[]) # good - do_something if attrs&.bar?(:[]) + do_something if attrs.nil_safe_method(:[]) + do_something if attrs&.not_nil_safe_method(:[]) diff --git a/config/contents/lint/shadowed_exception.md b/config/contents/lint/shadowed_exception.md index 40c50434..f2bae093 100644 --- a/config/contents/lint/shadowed_exception.md +++ b/config/contents/lint/shadowed_exception.md @@ -7,7 +7,7 @@ ancestor is, or if it and its ancestor are both rescued in the same `rescue` statement. In both cases, the more specific rescue is unnecessary because it is covered by rescuing the less specific exception. (ie. `rescue Exception, StandardError` has the same behavior -whether `StandardError` is included or not, because all `StandardError`s +whether `StandardError` is included or not, because all ``StandardError``s are rescued by `rescue Exception`). ### Example: diff --git a/config/contents/lint/unreachable_loop.md b/config/contents/lint/unreachable_loop.md index 29476e36..961c9ea9 100644 --- a/config/contents/lint/unreachable_loop.md +++ b/config/contents/lint/unreachable_loop.md @@ -4,7 +4,7 @@ A loop that can never reach the second iteration is a possible error in the code In rare cases where only one iteration (or at most one iteration) is intended behavior, the code should be refactored to use `if` conditionals. -NOTE: Block methods that are used with `Enumerable`s are considered to be loops. +NOTE: Block methods that are used with ``Enumerable``s are considered to be loops. `AllowedPatterns` can be used to match against the block receiver in order to allow code that would otherwise be registered as an offense (eg. `times` used not in an diff --git a/config/contents/lint/useless_access_modifier.md b/config/contents/lint/useless_access_modifier.md index 64060ded..8d99d94e 100644 --- a/config/contents/lint/useless_access_modifier.md +++ b/config/contents/lint/useless_access_modifier.md @@ -26,8 +26,8 @@ create other methods in the module's current access context. # bad class Foo # The following is redundant (methods defined on the class' - # singleton class are not affected by the public modifier) - public + # singleton class are not affected by the private modifier) + private def self.method3 end diff --git a/config/contents/lint/useless_ruby2_keywords.md b/config/contents/lint/useless_ruby2_keywords.md index 8f8dac61..2da4e42a 100644 --- a/config/contents/lint/useless_ruby2_keywords.md +++ b/config/contents/lint/useless_ruby2_keywords.md @@ -1,7 +1,7 @@ Looks for `ruby2_keywords` calls for methods that do not need it. `ruby2_keywords` should only be called on methods that accept an argument splat -(`*args`) but do not explicit keyword arguments (`k:` or `k: true`) or +(`\*args`) but do not explicit keyword arguments (`k:` or `k: true`) or a keyword splat (`**kwargs`). ### Example: diff --git a/config/contents/style/access_modifier_declarations.md b/config/contents/style/access_modifier_declarations.md index 1ceb727c..27751c18 100644 --- a/config/contents/style/access_modifier_declarations.md +++ b/config/contents/style/access_modifier_declarations.md @@ -4,6 +4,12 @@ EnforcedStyle config covers only method definitions. Applications of visibility methods to symbols can be controlled using AllowModifiersOnSymbols config. +### Safety: + +Autocorrection is not safe, because the visibility of dynamically +defined methods can vary depending on the state determined by +the group access modifier. + ### Example: EnforcedStyle: group (default) # bad class Foo diff --git a/config/contents/style/case_equality.md b/config/contents/style/case_equality.md index 9eeda270..3b10436d 100644 --- a/config/contents/style/case_equality.md +++ b/config/contents/style/case_equality.md @@ -2,6 +2,8 @@ Checks for uses of the case equality operator(===). If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of the case equality operator is a constant. +If `AllowOnSelfClass` option is enabled, the cop will ignore violations when the receiver of +the case equality operator is `self.class`. Note intermediate variables are not accepted. ### Example: # bad @@ -20,3 +22,11 @@ the case equality operator is a constant. ### Example: AllowOnConstant: true # good Array === something + +### Example: AllowOnSelfClass: false (default) + # bad + self.class === something + +### Example: AllowOnSelfClass: true + # good + self.class === something diff --git a/config/contents/style/guard_clause.md b/config/contents/style/guard_clause.md index 2b7e2fc9..c0b38d60 100644 --- a/config/contents/style/guard_clause.md +++ b/config/contents/style/guard_clause.md @@ -1,6 +1,10 @@ Use a guard clause instead of wrapping the code inside a conditional expression +A condition with an `elsif` or `else` branch is allowed unless +one of `return`, `break`, `next`, `raise`, or `fail` is used +in the body of the conditional expression. + ### Example: # bad def test @@ -45,31 +49,37 @@ expression ### Example: AllowConsecutiveConditionals: false (default) # bad - if foo? - work - end + def test + if foo? + work + end - if bar? # <- reports an offense - work + if bar? # <- reports an offense + work + end end ### Example: AllowConsecutiveConditionals: true # good - if foo? - work - end + def test + if foo? + work + end - if bar? - work + if bar? + work + end end # bad - if foo? - work - end + def test + if foo? + work + end - do_something + do_something - if bar? # <- reports an offense - work - end \ No newline at end of file + if bar? # <- reports an offense + work + end + end diff --git a/config/contents/style/symbol_proc.md b/config/contents/style/symbol_proc.md index d13b64b2..1317e26b 100644 --- a/config/contents/style/symbol_proc.md +++ b/config/contents/style/symbol_proc.md @@ -7,10 +7,11 @@ These are customizable with `AllowedMethods` option. ### Safety: -This cop is unsafe because `proc`s and blocks work differently -when additional arguments are passed in. A block will silently -allow additional arguments, but a `proc` will raise -an `ArgumentError`. +This cop is unsafe because there is a difference that a `Proc` +generated from `Symbol#to_proc` behaves as a lambda, while +a `Proc` generated from a block does not. +For example, a lambda will raise an `ArgumentError` if the +number of arguments is wrong, but a non-lambda `Proc` will not. For example: