From df53f9a4cd8ba6379b776fccfdc9a77eb0eafe9c Mon Sep 17 00:00:00 2001 From: Scott Matthewman Date: Mon, 28 Oct 2019 15:33:09 +0000 Subject: [PATCH] Rename Naming/UncommunicativeBlockParamName -> Naming/BlockParameterName --- config/default.yml | 28 ++--- lib/rubocop.rb | 2 +- lib/rubocop/config_obsoletion.rb | 1 + ..._param_name.rb => block_parameter_name.rb} | 2 +- manual/cops.md | 2 +- manual/cops_naming.md | 102 +++++++++--------- spec/rubocop/config_obsoletion_spec.rb | 3 + ...e_spec.rb => block_parameter_name_spec.rb} | 2 +- 8 files changed, 73 insertions(+), 69 deletions(-) rename lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb => block_parameter_name.rb} (96%) rename spec/rubocop/cop/naming/{uncommunicative_block_param_name_spec.rb => block_parameter_name_spec.rb} (97%) diff --git a/config/default.yml b/config/default.yml index 83488fc5532..7e96d6c8148 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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' @@ -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, diff --git a/lib/rubocop.rb b/lib/rubocop.rb index 9c2a1dbdb3c..ac8337faa1a 100644 --- a/lib/rubocop.rb +++ b/lib/rubocop.rb @@ -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' @@ -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' diff --git a/lib/rubocop/config_obsoletion.rb b/lib/rubocop/config_obsoletion.rb index 57c8daf2db4..9a7a429b5d2 100644 --- a/lib/rubocop/config_obsoletion.rb +++ b/lib/rubocop/config_obsoletion.rb @@ -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', diff --git a/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb b/lib/rubocop/cop/naming/block_parameter_name.rb similarity index 96% rename from lib/rubocop/cop/naming/uncommunicative_block_param_name.rb rename to lib/rubocop/cop/naming/block_parameter_name.rb index d99c8e05040..30fce45c4ea 100644 --- a/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb +++ b/lib/rubocop/cop/naming/block_parameter_name.rb @@ -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) diff --git a/manual/cops.md b/manual/cops.md index b1ca13ff163..0876d87c5ed 100644 --- a/manual/cops.md +++ b/manual/cops.md @@ -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) @@ -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) diff --git a/manual/cops_naming.md b/manual/cops_naming.md index a48227f844b..fd27dcea725 100644 --- a/manual/cops_naming.md +++ b/manual/cops_naming.md @@ -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 @@ -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 diff --git a/spec/rubocop/config_obsoletion_spec.rb b/spec/rubocop/config_obsoletion_spec.rb index 920aaeab5f8..7880609bacb 100644 --- a/spec/rubocop/config_obsoletion_spec.rb +++ b/spec/rubocop/config_obsoletion_spec.rb @@ -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 }, @@ -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`. diff --git a/spec/rubocop/cop/naming/uncommunicative_block_param_name_spec.rb b/spec/rubocop/cop/naming/block_parameter_name_spec.rb similarity index 97% rename from spec/rubocop/cop/naming/uncommunicative_block_param_name_spec.rb rename to spec/rubocop/cop/naming/block_parameter_name_spec.rb index a8f09dc1146..c528c4cd462 100644 --- a/spec/rubocop/cop/naming/uncommunicative_block_param_name_spec.rb +++ b/spec/rubocop/cop/naming/block_parameter_name_spec.rb @@ -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