-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate
ConfigurableMax
in favour of ExcludeLimit
which allows …
…multiple configuration options to be added to the exclude limit for `--auto-gen-config`.
- Loading branch information
1 parent
851741b
commit 61627d6
Showing
11 changed files
with
48 additions
and
15 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
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
# Allows specified configuration options to have an exclude limit | ||
# ie. a maximum value tracked that it can be used by `--auto-gen-config`. | ||
module ExcludeLimit | ||
# Sets up a configuration option to have an exclude limit tracked. | ||
# The parameter name given is transformed into a method name (eg. `Max` | ||
# becomes `self.max=` and `MinDigits` becomes `self.min_digits=`). | ||
def exclude_limit(parameter_name, method_name: transform(parameter_name)) | ||
define_method("#{method_name}=") do |value| | ||
cfg = config_to_allow_offenses | ||
cfg[:exclude_limit] ||= {} | ||
current_max = cfg[:exclude_limit][parameter_name] | ||
value = [current_max, value].max if current_max | ||
cfg[:exclude_limit][parameter_name] = value | ||
end | ||
end | ||
|
||
private | ||
|
||
def transform(parameter_name) | ||
parameter_name.gsub(/(?<!\A)(?=[A-Z])/, '_').downcase | ||
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
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