Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Style/InverseMethods aware of some Active Support methods #935

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
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