forked from rubocop/rubocop-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix rubocop#51] Add ability to whitelist receiver class names
In `Rails/DynamicFindBy`. Also use `AllowedReceivers` & `AllowedMethods` instead of `Whitelist` which will be deprecated soon. Fixes rubocop#51.
- Loading branch information
1 parent
2c860fc
commit 18a458e
Showing
7 changed files
with
91 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
# Common functionality for checking whitelisted methods & class names. | ||
module Allowed | ||
def allowed?(node) | ||
allowed_method?(node) || allowed_receiver?(node) || | ||
whitelisted?(node) | ||
end | ||
|
||
private | ||
|
||
def allowed_method?(node) | ||
return unless cop_config['AllowedMethods'] | ||
|
||
cop_config['AllowedMethods'].include?(node.method_name.to_s) | ||
end | ||
|
||
def allowed_receiver?(node) | ||
return unless cop_config['AllowedReceivers'] && node.receiver | ||
|
||
cop_config['AllowedReceivers'].include?(node.receiver.source.to_s) | ||
end | ||
|
||
# config option `WhiteList` will be deprecated soon | ||
def whitelisted?(node) | ||
whitelist_config = cop_config['Whitelist'] | ||
return unless whitelist_config | ||
|
||
whitelist_config.include?(node.method_name.to_s) || | ||
node.receiver && whitelist_config.include?(node.receiver.source.to_s) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters