fastruby / dotenv_validator

This gem check if required env variables are present and its format using the .env and .env.sample files from Dotenv.
https://www.fastruby.io/blog/open-source/introducing-dotenv-validator.html
MIT License
50 stars 4 forks source link

[BUG] RuboCop 'New Cops' message causes overcommit to fail #37

Closed kindoflew closed 3 years ago

kindoflew commented 3 years ago

Before we start...:

Version, Branch, or Commit: I made my own local branch, but confirmed with Francois that the issue is also happening on main.

Expected behavior: When commiting changes, RuboCop should only fail when it is supposed to (as per config).

Actual behavior: RuboCop fails because of 'unexpected output' to overcommit. There is a message from RuboCop detailing new cops that have not been configured yet, which seems to trip up overcommit.

Steps to reproduce:

How do I achieve this behavior? Use the following format to provide a step-by-step guide:

Step 1: Clone repo Step 2: Run setup script (ensure both overcommit and rubocop are installed) Step 3: Make changes and commit.

Context and environment: I found some relevant (but old) issues while trying to solve: sds/overcommit#704 rubocop/rubocop#7731

One fix recommended in the linked overcommit issue is to add --disable-pending-cops to RuboCop.flags in the config.

Provide any relevant information about your setup (Customize the list accordingly based on what info is relevant to this project)

  1. Ruby version: 2.7.2
  2. RuboCop version: 1.20.0
  3. Overcommit version: 0.58.0

Logs

Analyze with RuboCop........................................[RuboCop] FAILED
Unexpected output: unable to determine line number or type of error/warning for output:

Please also note that you can opt-in to new cops by default by adding this to your config:
  AllCops:
    NewCops: enable
Gemspec/DateAssignment: # new in 1.10
  Enabled: true
Layout/LineEndStringConcatenationIndentation: # new in 1.18
  Enabled: true
Layout/SpaceBeforeBrackets: # new in 1.7
  Enabled: true
Lint/AmbiguousAssignment: # new in 1.7
  Enabled: true
Lint/AmbiguousRange: # new in 1.19
  Enabled: true
Lint/DeprecatedConstants: # new in 1.8
  Enabled: true
Lint/DuplicateBranch: # new in 1.3
  Enabled: true
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
  Enabled: true
Lint/EmptyBlock: # new in 1.1
  Enabled: true
Lint/EmptyClass: # new in 1.3
  Enabled: true
Lint/EmptyInPattern: # new in 1.16
  Enabled: true
Lint/LambdaWithoutLiteralBlock: # new in 1.8
  Enabled: true
Lint/NoReturnInBeginEndBlocks: # new in 1.2
  Enabled: true
Lint/NumberedParameterAssignment: # new in 1.9
  Enabled: true
Lint/OrAssignmentToConstant: # new in 1.9
  Enabled: true
Lint/RedundantDirGlobSort: # new in 1.8
  Enabled: true
Lint/SymbolConversion: # new in 1.9
  Enabled: true
Lint/ToEnumArguments: # new in 1.1
  Enabled: true
Lint/TripleQuotes: # new in 1.9
  Enabled: true
Lint/UnexpectedBlockArity: # new in 1.5
  Enabled: true
Lint/UnmodifiedReduceAccumulator: # new in 1.1
  Enabled: true
Naming/InclusiveLanguage: # new in 1.18
  Enabled: true
Style/ArgumentsForwarding: # new in 1.1
  Enabled: true
Style/CollectionCompact: # new in 1.2
  Enabled: true
Style/DocumentDynamicEvalDefinition: # new in 1.1
  Enabled: true
Style/EndlessMethod: # new in 1.8
  Enabled: true
Style/HashConversion: # new in 1.10
  Enabled: true
Style/HashExcept: # new in 1.7
  Enabled: true
Style/IfWithBooleanLiteralBranches: # new in 1.9
  Enabled: true
Style/InPatternThen: # new in 1.16
  Enabled: true
Style/MultilineInPatternThen: # new in 1.16
  Enabled: true
Style/NegatedIfElseCondition: # new in 1.2
  Enabled: true
Style/NilLambda: # new in 1.3
  Enabled: true
Style/QuotedSymbols: # new in 1.16
  Enabled: true
Style/RedundantArgument: # new in 1.4
  Enabled: true
Style/RedundantSelfAssignmentBranch: # new in 1.19
  Enabled: true
Style/StringChars: # new in 1.12
  Enabled: true
Style/SwapValues: # new in 1.1
  Enabled: true
For more information: https://docs.rubocop.org/rubocop/versioning.html

✗ One or more pre-commit hooks failed

I will abide by the code of conduct

arielj commented 3 years ago

Maybe running bundle exec standardrb it shows the lines with the problems?

arielj commented 3 years ago

also, I think we should use a fixed version of standardrb and RuboCop, so we don't have this issue every time those are updated and we do update them manually on purpose to prevent these problems when needed

kindoflew commented 3 years ago

bundle exec standardrb output a bunch of style violations, but none of the ones listed in the above error message. They were almost all about using double-quoted strings.

arielj commented 3 years ago

hey @etagwerker, do you remember the reason to ignore the Gemfile.lock here? https://github.com/fastruby/dotenv_validator/commit/ce918f1fbec3caee1893e9ab595ab624ea019aaa

maybe it's better to add the .lock file so everybody uses the same versions of rubocop/standardrb to prevent newer versions adding newer cops to make it fail?

etagwerker commented 3 years ago

@arielj Last I remember it is not a best practice to add the Gemfile.lock to repositories of libraries? I think @bronzdoc might have more info about this.

I think we should use a fixed version of standardrb and RuboCop

I think this is the best way to go to avoid this issue in the future. ☝️

kindoflew commented 3 years ago

@arielj i'll close #41 then? The eventual PR to add fixed versions will probably involve enabling/disabling what new cops we want and will resolve this issue as well.

i could also open a new issue for adding those fixed versions so we can keep track of it.