Skip to content

Commit b74740a

Browse files
committed
Make Style/InverseMethods aware of some Active Support methods
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
1 parent 1358bb0 commit b74740a

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

.rubocop.yml

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ Style/FormatStringToken:
6666
Exclude:
6767
- spec/**/*
6868

69+
Style/InverseMethods:
70+
# This rubocop-rails repository doesn't use Active Support, so it can't replace `include?` with `exclude?`.
71+
InverseMethods:
72+
:include?: ~
73+
6974
Layout/HashAlignment:
7075
EnforcedHashRocketStyle:
7176
- key
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

config/default.yml

+8
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,14 @@ Style/FormatStringToken:
11441144
AllowedMethods:
11451145
- redirect
11461146

1147+
Style/InverseMethods:
1148+
# `InverseMethods` are methods that can be inverted by a not (`not` or `!`)
1149+
# The relationship of inverse methods only needs to be defined in one direction.
1150+
# Keys and values both need to be defined as symbols.
1151+
InverseMethods:
1152+
:present?: :blank?
1153+
:include?: :exclude?
1154+
11471155
Style/SymbolProc:
11481156
AllowedMethods:
11491157
- define_method

lib/rubocop/rails.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module RuboCop
55
module Rails
66
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
77
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
8-
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
8+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read, permitted_classes: [Regexp, Symbol]).freeze
99

1010
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
1111

0 commit comments

Comments
 (0)