Skip to content

Commit

Permalink
Make Style/InverseMethods aware of some Active Support methods
Browse files Browse the repository at this point in the history
This PR makes `Style/InverseMethods` aware of Active Support's
`present?`, `blank?`, `include?`, and `exclude?` methods.

These methods are based on the following setting:
https://github.com/rubocop/rubocop/blob/v1.45.0/config/default.yml#L4030-L4033
  • Loading branch information
koic committed Feb 19, 2023
1 parent 1358bb0 commit b74740a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Style/FormatStringToken:
Exclude:
- spec/**/*

Style/InverseMethods:
# This rubocop-rails repository doesn't use Active Support, so it can't replace `include?` with `exclude?`.
InverseMethods:
:include?: ~

Layout/HashAlignment:
EnforcedHashRocketStyle:
- key
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#935](https://github.com/rubocop/rubocop-rails/pull/935): Make `Style/InverseMethods` aware of Active Support's `present?`, `blank?`, `include?`, and `exclude?` methods. ([@koic][])
8 changes: 8 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,14 @@ Style/FormatStringToken:
AllowedMethods:
- redirect

Style/InverseMethods:
# `InverseMethods` are methods that can be inverted by a not (`not` or `!`)
# The relationship of inverse methods only needs to be defined in one direction.
# Keys and values both need to be defined as symbols.
InverseMethods:
:present?: :blank?
:include?: :exclude?

Style/SymbolProc:
AllowedMethods:
- define_method
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RuboCop
module Rails
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read, permitted_classes: [Regexp, Symbol]).freeze

private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)

Expand Down

0 comments on commit b74740a

Please sign in to comment.