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

--auto-gen-config produces Metrics/LineLength twice if Metrics/LineLength is configured in .rubocop.yml #5228

Closed
aried3r opened this issue Dec 12, 2017 · 4 comments

Comments

@aried3r
Copy link

aried3r commented Dec 12, 2017

Expected behavior

Metrics/LineLength should only be reported once in .rubocop_todo.yml.

Actual behavior

Metrics/LineLength is reported twice. My guess is that this is because of the two-phase run in the newer rubocop version? It also only happens when .rubocop.yml contains a configuration rule for Metrics/LineLength.

Steps to reproduce the problem

# .rubocop.yml

Metrics/LineLength:
  Max: 100
# example.rb
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

Run rubocop --auto-gen-config

rubocop --auto-gen-config
Phase 1 of 2: run Metrics/LineLength cop
Inspecting 1 file
C

Offenses:

example.rb:1:101: C: Metrics/LineLength: Line is too long. [103/100]
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
                                                                                                    ^^^

1 file inspected, 1 offense detected
Created .rubocop_todo.yml.
Phase 2 of 2: run all cops
Inspecting 1 file
C

Offenses:

example.rb:1:101: C: Metrics/LineLength: Line is too long. [103/100]
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
                                                                                                    ^^^

1 file inspected, 1 offense detected
Created .rubocop_todo.yml.
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-12-12 18:25:59 +0100 using RuboCop version 0.52.0.
# 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: 1
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
  Max: 103

# Offense count: 1
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
  Max: 103

RuboCop version

$ rubocop -V
0.52.0 (using Parser 2.4.0.2, running on ruby 2.4.2 x86_64-darwin16)
@jonas054
Copy link
Collaborator

I'll take a look.

@PetrKaleta
Copy link

This is still happening in 1.26.1 Exactly the same problem.

Here is my .rubocop.yml

require:
  - rubocop-performance
  - rubocop-minitest
  - rubocop-rake

inherit_from: .rubocop_todo.yml

AllCops:
  EnabledByDefault: true

Style/FrozenStringLiteralComment:
  EnforcedStyle: always_true
  SafeAutoCorrect: true

Style/AsciiComments:
  Enabled: false

Style/MethodCallWithArgsParentheses:
  Enabled: false

Style/StringHashKeys:
  Enabled: false

Style/Copyright:
  Enabled: false

Style/MissingElse:
  Enabled: false

Style/InlineComment:
  Enabled: false

Style/ImplicitRuntimeError:
  Enabled: false

Style/ConstantVisibility:
  Enabled: false

Style/ClassMethodsDefinitions:
  Enabled: false

Lint/NumberConversion:
  Enabled: false

Lint/ConstantResolution:
  Enabled: false

Lint/ReturnInVoidContext:
  Enabled: false

Layout/LineLength:
  Max: 120
  IgnoredPatterns:
    - "^#.*$"

Layout/SingleLineBlockChain:
  Enabled: false

Layout/MultilineAssignmentLayout:
  Enabled: false

Layout/EmptyLineAfterMultilineCondition:
  Enabled: false

Layout/RedundantLineBreak:
  Enabled: false

Metrics/MethodLength:
  Enabled: false

Metrics/BlockLength:
  Enabled: false

Metrics/CyclomaticComplexity:
  Enabled: false

Metrics/PerceivedComplexity:
  Enabled: false

Metrics/AbcSize:
  Enabled: false

Metrics/ParameterLists:
  Max: 10

Naming/VariableNumber:
  Enabled: false

@jonas054
Copy link
Collaborator

I can reproduce the problem, but it only happens when the user configuration for Layout/LineLength:Max is 120, i.e. same as the default value.

@PetrKaleta
Copy link

I can reproduce the problem, but it only happens when the user configuration for Layout/LineLength:Max is 120, i.e. same as the default value.

I can confirm, if Layout/LineLength:Max is set to a default value 120 then problems with duplicity occurs. Tested on rubocop 1.45.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants