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

Change terminology to Allowlist and Denylist #7469

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Changes

* [#7077](https://github.com/rubocop-hq/rubocop/issues/7077): **(Breaking)** Further standardisation of cop names. ([@scottmatthewman][])
* [#7469](https://github.com/rubocop-hq/rubocop/pull/7469): Change a terminology from `Whitelist` and `Blacklist` to `Allowlist` and `Denylist`. ([@koic][])

## 0.76.0 (2019-10-28)

Expand Down
46 changes: 24 additions & 22 deletions config/default.yml
Expand Up @@ -141,11 +141,12 @@ Bundler/GemComment:
Description: 'Add a comment describing each gem.'
Enabled: false
VersionAdded: '0.59'
VersionChanged: '0.77'
Include:
- '**/*.gemfile'
- '**/Gemfile'
- '**/gems.rb'
Whitelist: []
IgnoredGems: []

Bundler/InsecureProtocolSource:
Description: >-
Expand Down Expand Up @@ -1590,8 +1591,8 @@ Lint/SafeNavigationChain:
Description: 'Do not chain ordinary method call after safe navigation operator.'
Enabled: true
VersionAdded: '0.47'
VersionChanged: '0.56'
Whitelist:
VersionChanged: '0.77'
AllowedMethods:
- present?
- blank?
- presence
Expand All @@ -1605,14 +1606,14 @@ Lint/SafeNavigationConsistency:
for all method calls on that same object.
Enabled: true
VersionAdded: '0.55'
Whitelist:
VersionChanged: '0.77'
AllowedMethods:
- present?
- blank?
- presence
- try
- try!


Lint/SafeNavigationWithEmpty:
Description: 'Avoid `foo&.empty?` in conditionals.'
Enabled: true
Expand Down Expand Up @@ -1902,9 +1903,9 @@ Naming/BlockParameterName:
# Parameter names may be equal to or greater than this value
MinNameLength: 1
AllowNamesEndingInNumbers: true
# Whitelisted names that will not register an offense
# Allowed names that will not register an offense
AllowedNames: []
# Blacklisted names that will register an offense
# Forbidden names that will register an offense
ForbiddenNames: []

Naming/ClassAndModuleCamelCase:
Expand Down Expand Up @@ -1998,7 +1999,7 @@ Naming/HeredocDelimiterNaming:
StyleGuide: '#heredoc-delimiters'
Enabled: true
VersionAdded: '0.50'
Blacklist:
ForbiddenDelimiters:
- !ruby/regexp '/(^|\s)(EO[A-Z]{1}|END)(\s|$)/'

Naming/MemoizedInstanceVariableName:
Expand Down Expand Up @@ -2040,7 +2041,7 @@ Naming/MethodParameterName:
# Parameter names may be equal to or greater than this value
MinNameLength: 3
AllowNamesEndingInNumbers: true
# Whitelisted names that will not register an offense
# Allowed names that will not register an offense
AllowedNames:
- io
- id
Expand All @@ -2052,28 +2053,28 @@ Naming/MethodParameterName:
- ip
- db
- os
# Blacklisted names that will register an offense
# Fobidden names that will register an offense
ForbiddenNames: []

Naming/PredicateName:
Description: 'Check the names of predicate methods.'
StyleGuide: '#bool-methods-qmark'
Enabled: true
VersionAdded: '0.50'
VersionChanged: '0.51'
VersionChanged: '0.77'
# Predicate name prefixes.
NamePrefix:
- is_
- has_
- have_
# Predicate name prefixes that should be removed.
NamePrefixBlacklist:
ForbiddenPrefixes:
- is_
- has_
- have_
# Predicate names which, despite having a blacklisted prefix, or no `?`,
# Predicate names which, despite having a forbidden prefix, or no `?`,
# should still be accepted
NameWhitelist:
AllowedMethods:
- is_a?
# Method definition macros for dynamically generated methods.
MethodDefinitionMacros:
Expand Down Expand Up @@ -2885,8 +2886,9 @@ Style/IpAddresses:
Description: "Don't include literal IP addresses in code."
Enabled: false
VersionAdded: '0.58'
# Allow strings to be whitelisted
Whitelist:
VersionChanged: '0.77'
# Allow addresses to be permitted
AllowedAddresses:
- "::"
# :: is a valid IPv6 address, but could potentially be legitimately in code

Expand Down Expand Up @@ -3159,8 +3161,8 @@ Style/NestedParenthesizedCalls:
argument list of another parenthesized method call.
Enabled: true
VersionAdded: '0.36'
VersionChanged: '0.50'
Whitelist:
VersionChanged: '0.77'
AllowedMethods:
- be
- be_a
- be_an
Expand Down Expand Up @@ -3537,11 +3539,11 @@ Style/SafeNavigation:
safe navigation (`&.`).
Enabled: true
VersionAdded: '0.43'
VersionChanged: '0.56'
VersionChanged: '0.77'
# Safe navigation may cause a statement to start returning `nil` in addition
# to whatever it used to return.
ConvertCodeThatCanStartToReturnNil: false
Whitelist:
AllowedMethods:
- present?
- blank?
- presence
Expand Down Expand Up @@ -3819,7 +3821,7 @@ Style/TrivialAccessors:
StyleGuide: '#attr_family'
Enabled: true
VersionAdded: '0.9'
VersionChanged: '0.38'
VersionChanged: '0.77'
# When set to `false` the cop will suggest the use of accessor methods
# in situations like:
#
Expand All @@ -3840,7 +3842,7 @@ Style/TrivialAccessors:
# Commonly used in DSLs
AllowDSLWriters: false
IgnoreClassMethods: false
Whitelist:
AllowedMethod:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that this is missing the trailing s.
Should be AllowedMethods.

PR incoming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: #7530
PR: #7529

- to_ary
- to_a
- to_c
Expand Down
36 changes: 36 additions & 0 deletions lib/rubocop/config_obsoletion.rb
Expand Up @@ -158,6 +158,42 @@ class ConfigObsoletion
parameters: 'SafeMode',
alternative: '`SafeMode` has been removed. ' \
'Use `SafeAutoCorrect` instead.'
},
{
cops: 'Bundler/GemComment',
parameters: 'Whitelist',
alternative: '`Whitelist` has been renamed to `IgnoredGems`.'
},
{
cops: %w[
Lint/SafeNavigationChain Lint/SafeNavigationConsistency
Style/NestedParenthesizedCalls Style/SafeNavigation
Style/TrivialAccessors
],
parameters: 'Whitelist',
alternative: '`Whitelist` has been renamed to `AllowedMethods`.'
},
{
cops: 'Style/IpAddresses',
parameters: 'Whitelist',
alternative: '`Whitelist` has been renamed to `AllowedAddresses`.'
},
{
cops: 'Naming/HeredocDelimiterNaming',
parameters: 'Blacklist',
alternative: '`Blacklist` has been renamed to `ForbiddenDelimiters`.'
},
{
cops: 'Naming/PredicateName',
parameters: 'NamePrefixBlacklist',
alternative: '`NamePrefixBlacklist` has been renamed to ' \
'`ForbiddenPrefixes`.'
},
{
cops: 'Naming/PredicateName',
parameters: 'NameWhitelist',
alternative: '`NameWhitelist` has been renamed to ' \
'`AllowedMethods`.'
}
].freeze

Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/bundler/gem_comment.rb
Expand Up @@ -24,7 +24,7 @@ class GemComment < Cop

def on_send(node)
return unless gem_declaration?(node)
return if whitelisted_gem?(node)
return if ignored_gem?(node)
return if commented?(node)

add_offense(node)
Expand Down Expand Up @@ -54,9 +54,9 @@ def preceding_comment?(node1, node2)
comment_line?(node2.loc.expression.source)
end

def whitelisted_gem?(node)
whitelist = Array(cop_config['Whitelist'])
whitelist.include?(node.first_argument.value)
def ignored_gem?(node)
ignored_gems = Array(cop_config['IgnoredGems'])
ignored_gems.include?(node.first_argument.value)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/mixin/nil_methods.rb
Expand Up @@ -5,20 +5,20 @@ module Cop
# This module provides a list of methods that are:
# 1. In the NilClass by default
# 2. Added to NilClass by explicitly requiring any standard libraries
# 3. Cop's configuration parameter Whitelist.
# 3. Cop's configuration parameter AllowedMethods.
module NilMethods
private

def nil_methods
nil.methods + other_stdlib_methods + whitelist
nil.methods + other_stdlib_methods + allowed_methods
end

def other_stdlib_methods
[:to_d]
end

def whitelist
cop_config['Whitelist'].map(&:to_sym)
def allowed_methods
cop_config['AllowedMethods'].map(&:to_sym)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/naming/block_parameter_name.rb
Expand Up @@ -11,9 +11,9 @@ module Naming
# The `AllowNamesEndingInNumbers` config option takes a boolean. When
# set to false, this cop will register offenses for names ending with
# numbers. Its default is false. The `AllowedNames` config option
# takes an array of whitelisted names that will never register an
# takes an array of permitted names that will never register an
# offense. The `ForbiddenNames` config option takes an array of
# blacklisted names that will always register an offense.
# restricted names that will always register an offense.
#
# @example
# # bad
Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
Expand Up @@ -5,7 +5,7 @@ module Cop
module Naming
# This cop checks that your heredocs are using meaningful delimiters.
# By default it disallows `END` and `EO*`, and can be configured through
# blacklisting additional delimiters.
# forbidden listing additional delimiters.
#
# @example
#
Expand Down Expand Up @@ -41,13 +41,13 @@ def meaningful_delimiters?(node)

return false unless delimiters =~ /\w/

blacklisted_delimiters.none? do |blacklisted_delimiter|
delimiters =~ Regexp.new(blacklisted_delimiter)
forbidden_delimiters.none? do |forbidden_delimiter|
delimiters =~ Regexp.new(forbidden_delimiter)
end
end

def blacklisted_delimiters
cop_config['Blacklist'] || []
def forbidden_delimiters
cop_config['ForbiddenDelimiters'] || []
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/naming/method_parameter_name.rb
Expand Up @@ -11,9 +11,9 @@ module Naming
# The `AllowNamesEndingInNumbers` config option takes a boolean. When
# set to false, this cop will register offenses for names ending with
# numbers. Its default is false. The `AllowedNames` config option
# takes an array of whitelisted names that will never register an
# takes an array of permitted names that will never register an
# offense. The `ForbiddenNames` config option takes an array of
# blacklisted names that will always register an offense.
# restricted names that will always register an offense.
#
# @example
# # bad
Expand Down
12 changes: 6 additions & 6 deletions lib/rubocop/cop/naming/predicate_name.rb
Expand Up @@ -70,11 +70,11 @@ def allowed_method_name?(method_name, prefix)
!method_name.match(/^#{prefix}[^0-9]/) ||
method_name == expected_name(method_name, prefix) ||
method_name.end_with?('=') ||
predicate_whitelist.include?(method_name)
allowed_methods.include?(method_name)
end

def expected_name(method_name, prefix)
new_name = if prefix_blacklist.include?(prefix)
new_name = if forbidden_prefixes.include?(prefix)
method_name.sub(prefix, '')
else
method_name.dup
Expand All @@ -87,16 +87,16 @@ def message(method_name, new_name)
"Rename `#{method_name}` to `#{new_name}`."
end

def prefix_blacklist
cop_config['NamePrefixBlacklist']
def forbidden_prefixes
cop_config['ForbiddenPrefixes']
end

def predicate_prefixes
cop_config['NamePrefix']
end

def predicate_whitelist
cop_config['NameWhitelist']
def allowed_methods
cop_config['AllowedMethods']
end

def method_definition_macros(macro_name)
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/style/ip_addresses.rb
Expand Up @@ -28,7 +28,7 @@ def offense?(node)
contents = node.source[1...-1]
return false if contents.empty?

return false if whitelist.include?(contents.downcase)
return false if allowed_addresses.include?(contents.downcase)

# To try to avoid doing two regex checks on every string,
# shortcut out if the string does not look like an IP address
Expand All @@ -47,9 +47,9 @@ def correct_style_detected; end

private

def whitelist
whitelist = cop_config['Whitelist']
Array(whitelist).map(&:downcase)
def allowed_addresses
allowed_addresses = cop_config['AllowedAddresses']
Array(allowed_addresses).map(&:downcase)
end

def could_be_ip?(str)
Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/style/nested_parenthesized_calls.rb
Expand Up @@ -49,17 +49,17 @@ def autocorrect(nested)
def allowed_omission?(send_node)
!send_node.arguments? || send_node.parenthesized? ||
send_node.setter_method? || send_node.operator_method? ||
whitelisted?(send_node)
allowed?(send_node)
end

def whitelisted?(send_node)
def allowed?(send_node)
send_node.parent.arguments.one? &&
whitelisted_methods.include?(send_node.method_name.to_s) &&
allowed_methods.include?(send_node.method_name.to_s) &&
send_node.arguments.one?
end

def whitelisted_methods
cop_config['Whitelist'] || []
def allowed_methods
cop_config['AllowedMethods'] || []
end
end
end
Expand Down