Skip to content

Commit

Permalink
Rename Naming/UncommunicativeBlockParamName -> Naming/BlockParameterName
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmatthewman authored and bbatsov committed Nov 2, 2019
1 parent cd8c339 commit df53f9a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 69 deletions.
28 changes: 14 additions & 14 deletions config/default.yml
Expand Up @@ -1881,6 +1881,20 @@ Naming/BinaryOperatorParameterName:
Enabled: true
VersionAdded: '0.50'

Naming/BlockParameterName:
Description: >-
Checks for block parameter names that contain capital letters,
end in numbers, or do not meet a minimal length.
Enabled: true
VersionAdded: '0.53'
# Parameter names may be equal to or greater than this value
MinNameLength: 1
AllowNamesEndingInNumbers: true
# Whitelisted names that will not register an offense
AllowedNames: []
# Blacklisted names that will register an offense
ForbiddenNames: []

Naming/ClassAndModuleCamelCase:
Description: 'Use CamelCase for classes and modules.'
StyleGuide: '#camelcase-classes'
Expand Down Expand Up @@ -2040,20 +2054,6 @@ Naming/RescuedExceptionsVariableName:
VersionChanged: '0.68'
PreferredName: e

Naming/UncommunicativeBlockParamName:
Description: >-
Checks for block parameter names that contain capital letters,
end in numbers, or do not meet a minimal length.
Enabled: true
VersionAdded: '0.53'
# Parameter names may be equal to or greater than this value
MinNameLength: 1
AllowNamesEndingInNumbers: true
# Whitelisted names that will not register an offense
AllowedNames: []
# Blacklisted names that will register an offense
ForbiddenNames: []

Naming/UncommunicativeMethodParamName:
Description: >-
Checks for method parameter names that contain capital letters,
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop.rb
Expand Up @@ -373,6 +373,7 @@

require_relative 'rubocop/cop/naming/accessor_method_name'
require_relative 'rubocop/cop/naming/ascii_identifiers'
require_relative 'rubocop/cop/naming/block_parameter_name'
require_relative 'rubocop/cop/naming/class_and_module_camel_case'
require_relative 'rubocop/cop/naming/constant_name'
require_relative 'rubocop/cop/naming/file_name'
Expand All @@ -383,7 +384,6 @@
require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
require_relative 'rubocop/cop/naming/predicate_name'
require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
require_relative 'rubocop/cop/naming/uncommunicative_block_param_name'
require_relative 'rubocop/cop/naming/uncommunicative_method_param_name'
require_relative 'rubocop/cop/naming/variable_name'
require_relative 'rubocop/cop/naming/variable_number'
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/config_obsoletion.rb
Expand Up @@ -27,6 +27,7 @@ class ConfigObsoletion
'Lint/UnneededCopEnableDirective' => 'Lint/RedundantCopEnableDirective',
'Lint/UnneededRequireStatement' => 'Lint/RedundantRequireStatement',
'Lint/UnneededSplatExpansion' => 'Lint/RedundantSplatExpansion',
'Naming/UncommunicativeBlockParamName' => 'Naming/BlockParameterName',
'Style/DeprecatedHashMethods' => 'Style/PreferredHashMethods',
'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
'Style/OpMethod' => 'Naming/BinaryOperatorParameterName',
Expand Down
Expand Up @@ -35,7 +35,7 @@ module Naming
# foo { |speed, distance| speed * distance }
#
# baz { |age, height, gender| do_stuff(age, height, gender) }
class UncommunicativeBlockParamName < Cop
class BlockParameterName < Cop
include UncommunicativeName

def on_block(node)
Expand Down
2 changes: 1 addition & 1 deletion manual/cops.md
Expand Up @@ -279,6 +279,7 @@ In the following section you find all available cops:
* [Naming/AccessorMethodName](cops_naming.md#namingaccessormethodname)
* [Naming/AsciiIdentifiers](cops_naming.md#namingasciiidentifiers)
* [Naming/BinaryOperatorParameterName](cops_naming.md#namingbinaryoperatorparametername)
* [Naming/BlockParameterName](cops_naming.md#namingblockparametername)
* [Naming/ClassAndModuleCamelCase](cops_naming.md#namingclassandmodulecamelcase)
* [Naming/ConstantName](cops_naming.md#namingconstantname)
* [Naming/FileName](cops_naming.md#namingfilename)
Expand All @@ -288,7 +289,6 @@ In the following section you find all available cops:
* [Naming/MethodName](cops_naming.md#namingmethodname)
* [Naming/PredicateName](cops_naming.md#namingpredicatename)
* [Naming/RescuedExceptionsVariableName](cops_naming.md#namingrescuedexceptionsvariablename)
* [Naming/UncommunicativeBlockParamName](cops_naming.md#naminguncommunicativeblockparamname)
* [Naming/UncommunicativeMethodParamName](cops_naming.md#naminguncommunicativemethodparamname)
* [Naming/VariableName](cops_naming.md#namingvariablename)
* [Naming/VariableNumber](cops_naming.md#namingvariablenumber)
Expand Down
102 changes: 51 additions & 51 deletions manual/cops_naming.md
Expand Up @@ -99,6 +99,57 @@ def +(other); end
* [https://rubystyle.guide#other-arg](https://rubystyle.guide#other-arg)
## Naming/BlockParameterName
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | No | 0.53 | -
This cop checks block parameter names for how descriptive they
are. It is highly configurable.
The `MinNameLength` config option takes an integer. It represents
the minimum amount of characters the name must be. Its default is 1.
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
offense. The `ForbiddenNames` config option takes an array of
blacklisted names that will always register an offense.
### Examples
```ruby
# bad
bar do |varOne, varTwo|
varOne + varTwo
end

# With `AllowNamesEndingInNumbers` set to false
foo { |num1, num2| num1 * num2 }

# With `MinParamNameLength` set to number greater than 1
baz { |a, b, c| do_stuff(a, b, c) }

# good
bar do |thud, fred|
thud + fred
end

foo { |speed, distance| speed * distance }

baz { |age, height, gender| do_stuff(age, height, gender) }
```
### Configurable attributes
Name | Default value | Configurable values
--- | --- | ---
MinNameLength | `1` | Integer
AllowNamesEndingInNumbers | `true` | Boolean
AllowedNames | `[]` | Array
ForbiddenNames | `[]` | Array
## Naming/ClassAndModuleCamelCase
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
Expand Down Expand Up @@ -556,57 +607,6 @@ Name | Default value | Configurable values
--- | --- | ---
PreferredName | `e` | String
## Naming/UncommunicativeBlockParamName
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | No | 0.53 | -
This cop checks block parameter names for how descriptive they
are. It is highly configurable.
The `MinNameLength` config option takes an integer. It represents
the minimum amount of characters the name must be. Its default is 1.
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
offense. The `ForbiddenNames` config option takes an array of
blacklisted names that will always register an offense.
### Examples
```ruby
# bad
bar do |varOne, varTwo|
varOne + varTwo
end

# With `AllowNamesEndingInNumbers` set to false
foo { |num1, num2| num1 * num2 }

# With `MinParamNameLength` set to number greater than 1
baz { |a, b, c| do_stuff(a, b, c) }

# good
bar do |thud, fred|
thud + fred
end

foo { |speed, distance| speed * distance }

baz { |age, height, gender| do_stuff(age, height, gender) }
```
### Configurable attributes
Name | Default value | Configurable values
--- | --- | ---
MinNameLength | `1` | Integer
AllowNamesEndingInNumbers | `true` | Boolean
AllowedNames | `[]` | Array
ForbiddenNames | `[]` | Array
## Naming/UncommunicativeMethodParamName
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
Expand Down
3 changes: 3 additions & 0 deletions spec/rubocop/config_obsoletion_spec.rb
Expand Up @@ -38,6 +38,7 @@
'Lint/UnneededCopEnableDirective' => { 'Enabled': true },
'Lint/UnneededRequireStatement' => { 'Enabled': true },
'Lint/UnneededSplatExpansion' => { 'Enabled': true },
'Naming/UncommunicativeBlockParamName' => { 'Enabled': true },
'Style/DeprecatedHashMethods' => { 'Enabled': true },
'Style/MethodCallParentheses' => { 'Enabled': true },
'Style/OpMethod' => { 'Enabled': true },
Expand Down Expand Up @@ -126,6 +127,8 @@
(obsolete configuration found in example/.rubocop.yml, please update it)
The `Lint/UnneededSplatExpansion` cop has been renamed to `Lint/RedundantSplatExpansion`.
(obsolete configuration found in example/.rubocop.yml, please update it)
The `Naming/UncommunicativeBlockParamName` cop has been renamed to `Naming/BlockParameterName`.
(obsolete configuration found in example/.rubocop.yml, please update it)
The `Style/DeprecatedHashMethods` cop has been renamed to `Style/PreferredHashMethods`.
(obsolete configuration found in example/.rubocop.yml, please update it)
The `Style/MethodCallParentheses` cop has been renamed to `Style/MethodCallWithoutArgsParentheses`.
Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Naming::UncommunicativeBlockParamName, :config do
RSpec.describe RuboCop::Cop::Naming::BlockParameterName, :config do
subject(:cop) { described_class.new(config) }

let(:cop_config) do
Expand Down

0 comments on commit df53f9a

Please sign in to comment.