Skip to content

Commit

Permalink
[rubocop#1220] Create namespace Metrics and move some cops there
Browse files Browse the repository at this point in the history
Move the Style cops BlockNesting, ClassLength,
CyclomaticComplexity, MetricsLineLength, MethodLength,
and ParameterLists to the new namespace.
  • Loading branch information
jonas054 committed Jul 29, 2014
1 parent e193b9c commit e2153e8
Show file tree
Hide file tree
Showing 33 changed files with 170 additions and 161 deletions.
14 changes: 7 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-05-17 17:36:04 +0200 using RuboCop version 0.21.0.
# on 2014-07-24 21:49:40 +0200 using RuboCop version 0.24.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 7
# Offense count: 8
# Configuration parameters: CountComments.
Style/ClassLength:
Metrics/ClassLength:
Max: 129

# Offense count: 24
Style/CyclomaticComplexity:
# Offense count: 30
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 115
# Offense count: 124
# Configuration parameters: CountComments.
Style/MethodLength:
Metrics/MethodLength:
Max: 21
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* [#1079](https://github.com/bbatsov/rubocop/pull/1079): New cop `MultilineBlockLayout` checks if a multiline block has an extpression on the same line as the start of the block. ([@barunio][])
* [#1217](https://github.com/bbatsov/rubocop/pull/1217): `Style::EmptyLinesAroundAccessModifier` cop does auto-correction. ([@tamird][])

### Changes

* [#1220](https://github.com/bbatsov/rubocop/issues/1220): New namespace `Metrics` created and some `Style` cops moved there. ([@jonas054][])

### Bugs fixed

* [#1197](https://github.com/bbatsov/rubocop/issues/1197): Fix false positive for new lambda syntax in `SpaceInsideBlockBraces`. ([@jonas054][])
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ inherit_from: ../.rubocop.yml
Style/Encoding:
Enabled: false

Style/LineLength:
Metrics/LineLength:
Max: 99
```
Expand Down Expand Up @@ -318,15 +318,15 @@ Rails/DefaultScope:
Specific cops can be disabled by setting `Enabled` to `false` for that specific cop.

```yaml
Style/LineLength:
Metrics/LineLength:
Enabled: false
```

Cops can customize their severity level. All cops support the `Severity` param.
Allowed params are `refactor`, `convention`, `warning`, `error` and `fatal`.

```yaml
Style/CyclomaticComplexity:
Metrics/CyclomaticComplexity:
Severity: warning
```

Expand All @@ -346,9 +346,9 @@ One or more individual cops can be disabled locally in a section of a
file by adding a comment such as

```ruby
# rubocop:disable Style/LineLength, Style/StringLiterals
# rubocop:disable Metrics/LineLength, Style/StringLiterals
[...]
# rubocop:enable Style/LineLength, Style/StringLiterals
# rubocop:enable Metrics/LineLength, Style/StringLiterals
```

You can also disable *all* cops with
Expand Down
48 changes: 25 additions & 23 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ Style/BarePercentLiterals:
- percent_q
- bare_percent

Style/BlockNesting:
Max: 3

Style/BracesAroundHashParameters:
EnforcedStyle: no_braces
SupportedStyles:
Expand Down Expand Up @@ -159,10 +156,6 @@ Style/ClassCheck:
- is_a?
- kind_of?

Style/ClassLength:
CountComments: false # count full line comments?
Max: 100

# Align with the style guide.
Style/CollectionMethods:
# Mapping from undesired method to desired_method
Expand All @@ -187,10 +180,6 @@ Style/CommentAnnotation:
- HACK
- REVIEW

# Avoid complex methods.
Style/CyclomaticComplexity:
Max: 6

# Multi-line method chaining should be done with leading dots.
Style/DotPosition:
EnforcedStyle: leading
Expand Down Expand Up @@ -271,10 +260,6 @@ Style/LambdaCall:
- call
- braces

Style/LineLength:
Max: 80
AllowURI: true

Style/Next:
# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like this one
Expand All @@ -299,10 +284,6 @@ Style/MethodDefParentheses:
- require_parentheses
- require_no_parentheses

Style/MethodLength:
CountComments: false # count full line comments?
Max: 10

Style/MethodName:
EnforcedStyle: snake_case
SupportedStyles:
Expand All @@ -312,10 +293,6 @@ Style/MethodName:
Style/NumericLiterals:
MinDigits: 5

Style/ParameterLists:
Max: 5
CountKeywordArgs: true

# Allow safe assignment in conditions.
Style/ParenthesesAroundCondition:
AllowSafeAssignment: true
Expand Down Expand Up @@ -476,6 +453,31 @@ Style/WhileUntilModifier:
Style/WordArray:
MinSize: 0

##################### Metrics ##################################

Metrics/BlockNesting:
Max: 3

Metrics/ClassLength:
CountComments: false # count full line comments?
Max: 100

# Avoid complex methods.
Metrics/CyclomaticComplexity:
Max: 6

Metrics/LineLength:
Max: 80
AllowURI: true

Metrics/MethodLength:
CountComments: false # count full line comments?
Max: 10

Metrics/ParameterLists:
Max: 5
CountKeywordArgs: true

##################### Lint ##################################

# Allow safe assignment in conditions.
Expand Down
50 changes: 26 additions & 24 deletions config/enabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ Style/BlockComments:
Description: 'Do not use block comments.'
Enabled: true

Style/BlockNesting:
Description: 'Avoid excessive block nesting'
Enabled: true

Style/Blocks:
Description: >-
Avoid using {...} for multi-line blocks (multiline chaining is
Expand Down Expand Up @@ -101,10 +97,6 @@ Style/ClassCheck:
Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.'
Enabled: true

Style/ClassLength:
Description: 'Avoid classes longer than 100 lines of code.'
Enabled: true

Style/ClassMethods:
Description: 'Use self when defining module/class methods.'
Enabled: true
Expand Down Expand Up @@ -135,10 +127,6 @@ Style/ConstantName:
Description: 'Constants should use SCREAMING_SNAKE_CASE.'
Enabled: true

Style/CyclomaticComplexity:
Description: 'Avoid complex methods.'
Enabled: true

Style/DefWithParentheses:
Description: 'Use def with parentheses when there are arguments.'
Enabled: true
Expand Down Expand Up @@ -275,10 +263,6 @@ Style/LineEndConcatenation:
line end.
Enabled: true

Style/LineLength:
Description: 'Limit lines to 80 characters.'
Enabled: true

Style/MethodCallParentheses:
Description: 'Do not use parentheses for method calls with no arguments.'
Enabled: true
Expand All @@ -289,10 +273,6 @@ Style/MethodDefParentheses:
parentheses.
Enabled: true

Style/MethodLength:
Description: 'Avoid methods longer than 10 lines of code.'
Enabled: true

Style/MethodName:
Description: 'Use the configured style when naming methods.'
Enabled: true
Expand Down Expand Up @@ -365,10 +345,6 @@ Style/OpMethod:
Description: 'When defining binary operators, name the argument other.'
Enabled: true

Style/ParameterLists:
Description: 'Avoid parameter lists longer than three or four parameters.'
Enabled: true

Style/ParenthesesAroundCondition:
Description: >-
Don't use parentheses around the condition of an
Expand Down Expand Up @@ -609,6 +585,32 @@ Style/WordArray:
Description: 'Use %w or %W for arrays of words.'
Enabled: true

#################### Metrics ################################

Metrics/BlockNesting:
Description: 'Avoid excessive block nesting'
Enabled: true

Metrics/ClassLength:
Description: 'Avoid classes longer than 100 lines of code.'
Enabled: true

Metrics/CyclomaticComplexity:
Description: 'Avoid complex methods.'
Enabled: true

Metrics/LineLength:
Description: 'Limit lines to 80 characters.'
Enabled: true

Metrics/MethodLength:
Description: 'Avoid methods longer than 10 lines of code.'
Enabled: true

Metrics/ParameterLists:
Description: 'Avoid parameter lists longer than three or four parameters.'
Enabled: true

#################### Lint ################################
### Warnings

Expand Down
13 changes: 7 additions & 6 deletions lib/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@
require 'rubocop/cop/lint/useless_setter_call'
require 'rubocop/cop/lint/void'

require 'rubocop/cop/metrics/block_nesting'
require 'rubocop/cop/metrics/class_length'
require 'rubocop/cop/metrics/cyclomatic_complexity'
require 'rubocop/cop/metrics/line_length'
require 'rubocop/cop/metrics/method_length'
require 'rubocop/cop/metrics/parameter_lists'

require 'rubocop/cop/style/access_modifier_indentation'
require 'rubocop/cop/style/accessor_method_name'
require 'rubocop/cop/style/alias'
Expand All @@ -113,7 +120,6 @@
require 'rubocop/cop/style/bare_percent_literals'
require 'rubocop/cop/style/begin_block'
require 'rubocop/cop/style/block_comments'
require 'rubocop/cop/style/block_nesting'
require 'rubocop/cop/style/blocks'
require 'rubocop/cop/style/braces_around_hash_parameters'
require 'rubocop/cop/style/case_equality'
Expand All @@ -122,15 +128,13 @@
require 'rubocop/cop/style/class_and_module_camel_case'
require 'rubocop/cop/style/class_and_module_children'
require 'rubocop/cop/style/class_check'
require 'rubocop/cop/style/class_length'
require 'rubocop/cop/style/class_methods'
require 'rubocop/cop/style/class_vars'
require 'rubocop/cop/style/collection_methods'
require 'rubocop/cop/style/colon_method_call'
require 'rubocop/cop/style/comment_annotation'
require 'rubocop/cop/style/comment_indentation'
require 'rubocop/cop/style/constant_name'
require 'rubocop/cop/style/cyclomatic_complexity'
require 'rubocop/cop/style/def_with_parentheses'
require 'rubocop/cop/style/deprecated_hash_methods'
require 'rubocop/cop/style/documentation'
Expand Down Expand Up @@ -164,11 +168,9 @@
require 'rubocop/cop/style/lambda_call'
require 'rubocop/cop/style/leading_comment_space'
require 'rubocop/cop/style/line_end_concatenation'
require 'rubocop/cop/style/line_length'
require 'rubocop/cop/style/method_call_parentheses'
require 'rubocop/cop/style/method_called_on_do_end_block'
require 'rubocop/cop/style/method_def_parentheses'
require 'rubocop/cop/style/method_length'
require 'rubocop/cop/style/method_name'
require 'rubocop/cop/style/module_function'
require 'rubocop/cop/style/multiline_block_chain'
Expand All @@ -185,7 +187,6 @@
require 'rubocop/cop/style/numeric_literals'
require 'rubocop/cop/style/one_line_conditional'
require 'rubocop/cop/style/op_method'
require 'rubocop/cop/style/parameter_lists'
require 'rubocop/cop/style/parentheses_around_condition'
require 'rubocop/cop/style/percent_literal_delimiters'
require 'rubocop/cop/style/percent_q_literals'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RuboCop
module Cop
module Style
module Metrics
# This cop checks for excessive nesting of conditional and looping
# constructs. Despite the cop's name, blocks are not considered as an
# extra level of nesting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RuboCop
module Cop
module Style
module Metrics
# This cop checks if the length a class exceeds some maximum value.
# Comment lines can optionally be ignored.
# The maximum allowed length is configurable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RuboCop
module Cop
module Style
module Metrics
# This cop checks that the cyclomatic complexity of methods is not higher
# than the configured maximum. The cyclomatic complexity is the number of
# linearly independent paths through a method. The algorithm counts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RuboCop
module Cop
module Style
module Metrics
# This cop checks the length of lines in the source code.
# The maximum length is configurable.
class LineLength < Cop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RuboCop
module Cop
module Style
module Metrics
# This cop checks if the length a method exceeds some maximum value.
# Comment lines can optionally be ignored.
# The maximum allowed length is configurable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RuboCop
module Cop
module Style
module Metrics
# This cop checks for methods with too many parameters.
# The maximum number of parameters in configurable.
# On Ruby 2.0+ keyword arguments can optionally
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/statement_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def fit_within_line_as_modifier_form?(node)

def max_line_length
cop_config && cop_config['MaxLineLength'] ||
config.for_cop('Style/LineLength')['Max']
config.for_cop('Metrics/LineLength')['Max']
end

def length(node)
Expand Down
Loading

0 comments on commit e2153e8

Please sign in to comment.