From 621523cfd988f7bd5fa0072763fd1f08d3b79381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 25 Oct 2019 03:41:49 +0200 Subject: [PATCH] Merge basic and standard rubocop files in one file A bit of history in order to understand this change. A year ago we introduced Hound so it would review our pull requests and warn contributors when they weren't following our coding style. However, back then we had many rules we hadn't reviewed yet, and we weren't sure we wanted to ask contributors to follow them. So we decided to split these files: .rubocop_basic.yml would contain rules we had already agreed on and wanted contributors to respect, and .rubocop.yml would contain rules we still had to review. Now we've finally gone through all these rules. We've removed some of them, kept some of them, added new ones, and applied them. Now all rules with a severity level of "convention" or higher return no offenses. The rules with "severity: refactor" return some offenses, though: * Metrics/LineLenght can only be properly accomplished when we define better multi-line indentation standards, while in some cases long lines indicate we need to refactor the code * Rails/DynamicFindBy returns a few false positives * Rails/HasManyOrHasOneDependent should by all means be implemented, although it will not be a trivial task * Rails/SaveBang returns a few false positives and there are a couple of places where we skip it on purpose There are also rules excluding some files: * Rails/InverseOf returns a false positive * Rails/OutputSafety is ignored on purpose when we add auto-links to a text we trust * RSpec/InstanceVariable returns false positives in two files Other than that, everything works as expected. --- .hound.yml | 2 +- .rubocop.yml | 369 ++++++++++++++++++++++++++++++++++++++++++++- .rubocop_basic.yml | 369 --------------------------------------------- 3 files changed, 369 insertions(+), 371 deletions(-) delete mode 100644 .rubocop_basic.yml diff --git a/.hound.yml b/.hound.yml index a8568704c..70fe6df63 100644 --- a/.hound.yml +++ b/.hound.yml @@ -1,5 +1,5 @@ rubocop: - config_file: .rubocop_basic.yml + config_file: .rubocop.yml version: 0.72.0 scss: config_file: .scss-lint.yml diff --git a/.rubocop.yml b/.rubocop.yml index e05f29bf6..d89574c31 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,368 @@ -inherit_from: .rubocop_basic.yml +require: + - rubocop-performance + - rubocop-rails + - rubocop-rspec + +AllCops: + DisplayCopNames: true + DisplayStyleGuide: true + Exclude: + - "db/schema.rb" + DisabledByDefault: true + +Bundler/DuplicatedGem: + Enabled: true + +Bundler/OrderedGems: + Enabled: true + +Capybara/CurrentPathExpectation: + Enabled: true + +Capybara/FeatureMethods: + Enabled: true + EnabledMethods: + - scenario + - xscenario + +FactoryBot/AttributeDefinedStatically: + Enabled: true + +Layout/EmptyLineAfterGuardClause: + Enabled: true + +Layout/EmptyLineBetweenDefs: + Enabled: true + +Layout/EmptyLines: + Enabled: true + +Layout/EmptyLinesAroundAccessModifier: + Enabled: true + +Layout/EmptyLinesAroundBlockBody: + Enabled: true + +Layout/EmptyLinesAroundClassBody: + Enabled: true + +Layout/EmptyLinesAroundMethodBody: + Enabled: true + +Layout/EmptyLinesAroundModuleBody: + Enabled: true + +Layout/EndOfLine: + EnforcedStyle: lf + +Layout/ExtraSpacing: + Enabled: true + +Layout/IndentationConsistency: + EnforcedStyle: indented_internal_methods + +Layout/IndentationWidth: + Enabled: true + +Layout/MultilineBlockLayout: + Enabled: true + +Layout/SpaceAfterColon: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAfterMethodName: + Enabled: true + +Layout/SpaceAfterNot: + Enabled: true + +Layout/SpaceAfterSemicolon: + Enabled: true + +Layout/SpaceAroundBlockParameters: + Enabled: true + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Layout/SpaceAroundOperators: + Enabled: true + +Layout/SpaceBeforeBlockBraces: + Enabled: true + +Layout/SpaceBeforeComma: + Enabled: true + +Layout/SpaceBeforeComment: + Enabled: true + +Layout/SpaceBeforeFirstArg: + Enabled: true + +Layout/SpaceBeforeSemicolon: + Enabled: true + +Layout/SpaceInsideArrayLiteralBrackets: + Enabled: true + +Layout/SpaceInsideArrayPercentLiteral: + Enabled: true + +Layout/SpaceInsideBlockBraces: + Enabled: true + +Layout/SpaceInsideHashLiteralBraces: + Enabled: true + EnforcedStyle: compact + +Layout/SpaceInsideParens: + Enabled: true + +Layout/SpaceInsidePercentLiteralDelimiters: + Enabled: true + +Layout/SpaceInsideRangeLiteral: + Enabled: true + +Layout/SpaceInsideReferenceBrackets: + Enabled: true + +Layout/SpaceInsideStringInterpolation: + Enabled: true + +Layout/Tab: + Enabled: true + +Layout/TrailingBlankLines: + Enabled: true + +Layout/TrailingWhitespace: + Enabled: true + +Lint/AmbiguousRegexpLiteral: + Enabled: true + +Lint/DuplicateMethods: + Enabled: true + +Lint/LiteralAsCondition: + Enabled: true + +Lint/ParenthesesAsGroupedExpression: + Enabled: true + +Lint/ShadowingOuterLocalVariable: + Enabled: true + +Lint/StringConversionInInterpolation: + Enabled: true + +Lint/UselessAssignment: + Enabled: true + +Metrics/LineLength: + Max: 110 + Severity: refactor + +Performance/CompareWithBlock: + Enabled: true + +Performance/Detect: + Enabled: true + +Performance/DoubleStartEndWith: + Enabled: true + +Performance/EndWith: + Enabled: true + +Performance/StartWith: + Enabled: true + +Rails/ActionFilter: + Enabled: true + +Rails/ApplicationJob: + Enabled: true + +Rails/ApplicationRecord: + Enabled: true + +Rails/CreateTableWithTimestamps: + Enabled: true + Exclude: + - "db/migrate/201[5-8]*" + +Rails/Date: + Enabled: true + +Rails/DynamicFindBy: + Enabled: true + Severity: refactor + +Rails/EnumUniqueness: + Enabled: true + +Rails/EnvironmentComparison: + Enabled: true + +Rails/FindBy: + Enabled: true + +Rails/FindEach: + Enabled: true + +Rails/HasAndBelongsToMany: + Enabled: true + +Rails/HasManyOrHasOneDependent: + Enabled: true + Severity: refactor + +Rails/HttpPositionalArguments: + Enabled: true + +Rails/InverseOf: + Enabled: true + Exclude: + - "app/models/related_content.rb" + +Rails/NotNullColumn: + Enabled: true + Exclude: + - "db/migrate/201[5-7]*" + +Rails/OutputSafety: + Enabled: true + Severity: warning + Exclude: + - app/helpers/text_with_links_helper.rb + +Rails/PluralizationGrammar: + Enabled: true + +Rails/Presence: + Enabled: true + +Rails/RelativeDateConstant: + Enabled: true + +Rails/RequestReferer: + Enabled: true + +Rails/ReversibleMigration: + Enabled: true + +Rails/SafeNavigation: + Enabled: true + ConvertTry: true + +Rails/SaveBang: + Enabled: true + Severity: refactor + +Rails/SkipsModelValidations: + Enabled: true + Blacklist: + - update_attribute + Exclude: + - lib/acts_as_paranoid_aliases.rb + +Rails/TimeZone: + Enabled: true + +Rails/UnknownEnv: + Enabled: true + Environments: + - development + - test + - production + - preproduction + - staging + +Rails/Validation: + Enabled: true + +RSpec/AroundBlock: + Enabled: true + +RSpec/BeforeAfterAll: + Enabled: true + +RSpec/DescribedClass: + Enabled: true + EnforcedStyle: explicit + +RSpec/EmptyExampleGroup: + Enabled: true + Exclude: + - spec/factories/**/* + +RSpec/EmptyLineAfterExampleGroup: + Enabled: true + Exclude: + - spec/factories/**/* + +RSpec/ExampleWording: + Enabled: true + +RSpec/Focus: + Enabled: true + +RSpec/HookArgument: + Enabled: true + +RSpec/InstanceVariable: + Enabled: true + Exclude: + - spec/controllers/concerns/has_filters_spec.rb + - spec/controllers/concerns/has_orders_spec.rb + +RSpec/LetBeforeExamples: + Enabled: true + +RSpec/LetSetup: + Enabled: true + +RSpec/NotToNot: + Enabled: true + +RSpec/OverwritingSetup: + Enabled: true + +RSpec/RepeatedExample: + Enabled: true + +RSpec/ScatteredLet: + Enabled: true + +RSpec/ScatteredSetup: + Enabled: true + +RSpec/VoidExpect: + Enabled: true + +Security/Eval: + Enabled: true + +Security/JSONLoad: + Enabled: true + +Security/YAMLLoad: + Enabled: true + +Style/BlockDelimiters: + Enabled: true + +Style/PercentLiteralDelimiters: + Enabled: true + +Style/SafeNavigation: + Enabled: true + +Style/StringLiterals: + EnforcedStyle: double_quotes diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml deleted file mode 100644 index 27332462f..000000000 --- a/.rubocop_basic.yml +++ /dev/null @@ -1,369 +0,0 @@ -require: - - rubocop-performance - - rubocop-rails - - rubocop-rspec - -AllCops: - DisplayCopNames: true - DisplayStyleGuide: true - Exclude: - - "db/schema.rb" - # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop - # to ignore them, so only the ones explicitly set in this file are enabled. - DisabledByDefault: true - -Bundler/DuplicatedGem: - Enabled: true - -Bundler/OrderedGems: - Enabled: true - -Capybara/CurrentPathExpectation: - Enabled: true - -Capybara/FeatureMethods: - Enabled: true - EnabledMethods: - - scenario - - xscenario - -FactoryBot/AttributeDefinedStatically: - Enabled: true - -Layout/EmptyLineAfterGuardClause: - Enabled: true - -Layout/EmptyLineBetweenDefs: - Enabled: true - -Layout/EmptyLinesAroundAccessModifier: - Enabled: true - -Layout/EmptyLinesAroundBlockBody: - Enabled: true - -Layout/EmptyLinesAroundClassBody: - Enabled: true - -Layout/EmptyLinesAroundMethodBody: - Enabled: true - -Layout/EmptyLinesAroundModuleBody: - Enabled: true - -Layout/ExtraSpacing: - Enabled: true - -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: true - -Layout/IndentationConsistency: - EnforcedStyle: indented_internal_methods - -Layout/IndentationWidth: - Enabled: true - -Layout/EmptyLines: - Enabled: true - -Layout/EndOfLine: - EnforcedStyle: lf - -Layout/MultilineBlockLayout: - Enabled: true - -Layout/SpaceAfterColon: - Enabled: true - -Layout/SpaceAfterComma: - Enabled: true - -Layout/SpaceAfterMethodName: - Enabled: true - -Layout/SpaceAfterNot: - Enabled: true - -Layout/SpaceAfterSemicolon: - Enabled: true - -Layout/SpaceAroundBlockParameters: - Enabled: true - -Layout/SpaceAroundOperators: - Enabled: true - -Layout/SpaceBeforeBlockBraces: - Enabled: true - -Layout/SpaceBeforeComma: - Enabled: true - -Layout/SpaceBeforeComment: - Enabled: true - -Layout/SpaceBeforeFirstArg: - Enabled: true - -Layout/SpaceBeforeSemicolon: - Enabled: true - -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: true - -Layout/SpaceInsideArrayPercentLiteral: - Enabled: true - -Layout/SpaceInsideBlockBraces: - Enabled: true - -Layout/SpaceInsideHashLiteralBraces: - Enabled: true - EnforcedStyle: compact - -Layout/SpaceInsideParens: - Enabled: true - -Layout/SpaceInsidePercentLiteralDelimiters: - Enabled: true - -Layout/SpaceInsideRangeLiteral: - Enabled: true - -Layout/SpaceInsideReferenceBrackets: - Enabled: true - -Layout/SpaceInsideStringInterpolation: - Enabled: true - -Layout/Tab: - Enabled: true - -Layout/TrailingBlankLines: - Enabled: true - -Layout/TrailingWhitespace: - Enabled: true - -Lint/AmbiguousRegexpLiteral: - Enabled: true - -Lint/DuplicateMethods: - Enabled: true - -Lint/LiteralAsCondition: - Enabled: true - -Lint/ParenthesesAsGroupedExpression: - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Enabled: true - -Lint/StringConversionInInterpolation: - Enabled: true - -Lint/UselessAssignment: - Enabled: true - -Metrics/LineLength: - Max: 110 - Severity: refactor - -Performance/CompareWithBlock: - Enabled: true - -Performance/Detect: - Enabled: true - -Performance/DoubleStartEndWith: - Enabled: true - -Performance/EndWith: - Enabled: true - -Performance/StartWith: - Enabled: true - -Rails/ActionFilter: - Enabled: true - -Rails/ApplicationJob: - Enabled: true - -Rails/ApplicationRecord: - Enabled: true - -Rails/CreateTableWithTimestamps: - Enabled: true - Exclude: - - "db/migrate/201[5-8]*" - -Rails/Date: - Enabled: true - -Rails/DynamicFindBy: - Enabled: true - Severity: refactor - -Rails/EnumUniqueness: - Enabled: true - -Rails/EnvironmentComparison: - Enabled: true - -Rails/FindBy: - Enabled: true - -Rails/FindEach: - Enabled: true - -Rails/HasManyOrHasOneDependent: - Enabled: true - Severity: refactor - -Rails/HttpPositionalArguments: - Enabled: true - -Rails/HasAndBelongsToMany: - Enabled: true - -Rails/InverseOf: - Enabled: true - Exclude: - - "app/models/related_content.rb" - -Rails/NotNullColumn: - Enabled: true - Exclude: - - "db/migrate/201[5-7]*" - -Rails/OutputSafety: - Enabled: true - Severity: warning - Exclude: - - app/helpers/text_with_links_helper.rb - -Rails/PluralizationGrammar: - Enabled: true - -Rails/Presence: - Enabled: true - -Rails/RelativeDateConstant: - Enabled: true - -Rails/RequestReferer: - Enabled: true - -Rails/ReversibleMigration: - Enabled: true - -Rails/SafeNavigation: - Enabled: true - ConvertTry: true - -Rails/SaveBang: - Enabled: true - Severity: refactor - -Rails/SkipsModelValidations: - Enabled: true - Blacklist: - - update_attribute - Exclude: lib/acts_as_paranoid_aliases.rb - -Rails/TimeZone: - Enabled: true - -Rails/UnknownEnv: - Enabled: true - Environments: - - development - - test - - production - - preproduction - - staging - -Rails/Validation: - Enabled: true - -RSpec/AroundBlock: - Enabled: true - -RSpec/BeforeAfterAll: - Enabled: true - -RSpec/DescribedClass: - Enabled: true - EnforcedStyle: explicit - -RSpec/EmptyExampleGroup: - Enabled: true - Exclude: - - spec/factories/**/* - -RSpec/EmptyLineAfterExampleGroup: - Enabled: true - Exclude: - - spec/factories/**/* - -RSpec/ExampleWording: - Enabled: true - -RSpec/Focus: - Enabled: true - -RSpec/HookArgument: - Enabled: true - -RSpec/InstanceVariable: - Enabled: true - Exclude: - - spec/controllers/concerns/has_filters_spec.rb - - spec/controllers/concerns/has_orders_spec.rb - -RSpec/LetBeforeExamples: - Enabled: true - -RSpec/LetSetup: - Enabled: true - -RSpec/NotToNot: - Enabled: true - -RSpec/OverwritingSetup: - Enabled: true - -RSpec/RepeatedExample: - Enabled: true - -RSpec/ScatteredLet: - Enabled: true - -RSpec/ScatteredSetup: - Enabled: true - -RSpec/VoidExpect: - Enabled: true - -Security/Eval: - Enabled: true - -Security/JSONLoad: - Enabled: true - -Security/YAMLLoad: - Enabled: true - -Style/BlockDelimiters: - Enabled: true - -Style/PercentLiteralDelimiters: - Enabled: true - -Style/SafeNavigation: - Enabled: true - -Style/StringLiterals: - EnforcedStyle: double_quotes