diff --git a/.rubocop.yml b/.rubocop.yml index 9fb3b502e0..c49c491a2c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,21 +1,15 @@ +# Extends defaults from: https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml + AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Include: - "**/*.gemspec" - "**/*.podspec" - - "**/*.jbuilder" - "**/*.rake" - - "**/*.opal" - "**/Gemfile" - "**/Rakefile" - "**/Capfile" - "**/Guardfile" - - "**/Podfile" - - "**/Thorfile" - - "**/Vagrantfile" - - "**/Berksfile" - - "**/Cheffile" - - "**/Vagabondfile" Exclude: - "vendor/**/*" - "db/schema.rb" @@ -31,611 +25,77 @@ AllCops: - "script" - "tmp" - "vendor" - DisplayCopNames: false - StyleGuideCopsOnly: false - -# -# Layout config -# - - -Layout/AccessModifierIndentation: - Enabled: true - EnforcedStyle: indent - -Layout/HashAlignment: - Enabled: true - EnforcedHashRocketStyle: key - EnforcedColonStyle: key - EnforcedLastArgumentHashStyle: always_inspect - -Layout/ParameterAlignment: - Enabled: true - EnforcedStyle: with_first_parameter - -Layout/CaseIndentation: - Enabled: true - EnforcedStyle: case - IndentOneStep: false - -Layout/EmptyLineBetweenDefs: - Enabled: true - AllowAdjacentOneLineDefs: false - -Layout/EmptyLinesAroundModuleBody: - Enabled: true - EnforcedStyle: no_empty_lines - -Layout/ExtraSpacing: - Enabled: true - -Layout/FirstArgumentIndentation: - Enabled: true - EnforcedStyle: special_for_inner_method_call_in_parentheses - -Layout/IndentationWidth: - Enabled: true - Width: 2 - -Layout/FirstHashElementIndentation: - Description: Checks the indentation of the first key in a hash literal. - Enabled: true - EnforcedStyle: special_inside_parentheses - SupportedStyles: - - special_inside_parentheses - - consistent - -Layout/MultilineOperationIndentation: - Enabled: true - EnforcedStyle: aligned - -Layout/SpaceAroundBlockParameters: - Enabled: true - EnforcedStyleInsidePipes: no_space - -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: true - EnforcedStyle: space - -Layout/SpaceBeforeBlockBraces: - Enabled: true - EnforcedStyle: space - -Layout/SpaceInsideBlockBraces: - Enabled: true - EnforcedStyle: space - EnforcedStyleForEmptyBraces: no_space - SpaceBeforeBlockParameters: true - -Layout/SpaceInsideHashLiteralBraces: - Enabled: true - EnforcedStyle: space - EnforcedStyleForEmptyBraces: no_space - -Layout/TrailingEmptyLines: - Enabled: true - EnforcedStyle: final_newline - -Layout/ArrayAlignment: - Enabled: true - -Layout/BlockEndNewline: - Enabled: true - -Layout/CommentIndentation: - Enabled: true - -Layout/ElseAlignment: - Enabled: true - -Layout/EmptyLines: - Enabled: true - -Layout/EmptyLinesAroundAccessModifier: - Enabled: true - -Layout/EmptyLinesAroundMethodBody: - Enabled: true - -Layout/EndOfLine: - Enabled: true - -Layout/IndentationConsistency: - Enabled: true - -Layout/FirstArrayElementIndentation: - Enabled: true - -Layout/LeadingCommentSpace: - Enabled: true - -Layout/MultilineBlockLayout: - Enabled: true - -Layout/SpaceBeforeFirstArg: - Enabled: true - -Layout/SpaceAfterColon: - Enabled: true - -Layout/SpaceAfterComma: - Enabled: true - -Layout/SpaceAroundKeyword: - Enabled: true - -Layout/SpaceAfterMethodName: - Enabled: true - -Layout/SpaceAfterNot: - Enabled: true - -Layout/SpaceAfterSemicolon: - Enabled: true - -Layout/SpaceBeforeComma: - Enabled: true - -Layout/SpaceBeforeComment: - Enabled: true - -Layout/SpaceBeforeSemicolon: - Enabled: true - -Layout/SpaceAroundOperators: - Enabled: true - -Layout/SpaceInsideParens: - Enabled: true - -Layout/SpaceInsideRangeLiteral: - Enabled: true - -Layout/IndentationStyle: - Enabled: true - -Layout/TrailingWhitespace: - Enabled: true - - - -# -# Style config -# - -Style/AndOr: - Enabled: true - EnforcedStyle: always - -Style/BarePercentLiterals: - Enabled: true - EnforcedStyle: bare_percent - -Style/ClassCheck: - Enabled: true - EnforcedStyle: is_a? - -Style/CollectionMethods: - Enabled: true - PreferredMethods: - collect: map - collect!: map! - inject: reduce - detect: find - find_all: select - -Style/For: - Enabled: true - EnforcedStyle: each - -Style/HashSyntax: - Enabled: true - EnforcedStyle: ruby19 + NewCops: disable -Style/NonNilCheck: - Enabled: true - IncludeSemanticChanges: false - -Style/MethodDefParentheses: - Enabled: true - EnforcedStyle: require_parentheses - -Naming/MethodName: - Enabled: true - EnforcedStyle: snake_case - -Style/ParenthesesAroundCondition: - Enabled: true - AllowSafeAssignment: true - -Style/PercentQLiterals: - Enabled: true - EnforcedStyle: lower_case_q - -Naming/PredicateName: - Enabled: true - -Style/RedundantReturn: - Enabled: true - AllowMultipleReturnValues: false - -Style/Semicolon: - Enabled: true - AllowAsExpressionSeparator: false - -Style/StringLiteralsInInterpolation: - Enabled: true - EnforcedStyle: single_quotes - -Style/SymbolProc: - Enabled: true - IgnoredMethods: - - respond_to - -Style/TrailingCommaInArguments: - Enabled: true - EnforcedStyleForMultiline: no_comma - -Style/TrailingCommaInArrayLiteral: - Enabled: true - EnforcedStyleForMultiline: no_comma - -Style/TrailingCommaInHashLiteral: - Enabled: true - EnforcedStyleForMultiline: no_comma - -Naming/VariableName: - Enabled: true - EnforcedStyle: snake_case - -Style/BeginBlock: - Enabled: true - -Style/BlockComments: - Enabled: true - -Style/BlockDelimiters: - Enabled: true - EnforcedStyle: braces_for_chaining - -Naming/ClassAndModuleCamelCase: - Enabled: true - -Style/ClassMethods: - Enabled: true - -Naming/ConstantName: - Enabled: true - -Style/DefWithParentheses: - Enabled: true - -Style/EmptyElse: - Enabled: true - -Style/EndBlock: - Enabled: true - -Style/InfiniteLoop: - Enabled: true - -Style/MethodCallWithoutArgsParentheses: - Enabled: true - -Style/MultilineBlockChain: - Enabled: true - -Style/MultilineIfThen: - Enabled: true - -Style/MultilineTernaryOperator: - Enabled: true - -Style/NestedTernaryOperator: - Enabled: true - -Style/RedundantBegin: - Enabled: true - -Style/RedundantException: - Enabled: true - -Style/RedundantSelf: - Enabled: true - -Style/RescueModifier: - Enabled: true - -Style/StructInheritance: - Enabled: true - -Style/UnlessElse: - Enabled: true - -Style/RedundantCapitalW: - Enabled: true - -Style/RedundantPercentQ: - Enabled: true - -Style/WhileUntilDo: - Enabled: true - -Style/HashEachMethods: - Enabled: true - -Style/HashTransformKeys: - Enabled: true - -Style/HashTransformValues: - Enabled: true - - -# -# Metrics cops -# - -Metrics/AbcSize: - Enabled: true - Max: 35 +#################### +# Layout +#################### Layout/LineLength: - Enabled: true + Description: Checks that line length does not exceed the configured limit. Max: 120 - AllowURI: true - URISchemes: - - http - - https - -Metrics/BlockLength: - Enabled: true - Exclude: - - spec/**/* - - -# -# Lint cops -# - -Layout/EndAlignment: - Enabled: true - EnforcedStyleAlignWith: keyword - -Layout/DefEndAlignment: - Enabled: true - EnforcedStyleAlignWith: start_of_line - -Lint/RescueException: - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Enabled: true - -Lint/RedundantStringCoercion: - Enabled: true - -Lint/UnusedBlockArgument: - Enabled: true -Lint/UnusedMethodArgument: - Enabled: true - -Lint/UnreachableCode: - Enabled: true - -Lint/UselessAccessModifier: - Enabled: true - -Lint/UselessAssignment: - Enabled: true - -Lint/UselessComparison: - Enabled: true - -Lint/UselessElseWithoutRescue: - Enabled: true - -Lint/UselessSetterCall: - Enabled: true - -Layout/BlockAlignment: - Enabled: true - -Lint/Debugger: - Enabled: true - -Lint/DuplicateMethods: - Enabled: true - -Lint/EmptyEnsure: - Enabled: true - -Lint/EmptyInterpolation: - Enabled: true - -Lint/EnsureReturn: - Enabled: true +Layout/EmptyLinesAroundClassBody: + Description: Keeps track of empty lines around class bodies. + EnforcedStyle: empty_lines_except_namespace -Lint/RaiseException: - Enabled: true +#################### +# Metrics +#################### -Lint/StructNewOverride: - Enabled: true +Metrics/BlockLength: + Description: Avoid long blocks with many lines. + Max: 50 + Exclude: + - '**/*.gemspec' + - spec/**/*_spec.rb +Metrics/ClassLength: + Description: Avoid classes longer than 400 lines of code. + Max: 400 -# -# Security cops -# +Metrics/CyclomaticComplexity: + Description: >- + A complexity metric that is strongly correlated to the number + of test cases needed to validate a method. + Max: 15 -Security/Eval: - Description: The use of eval represents a serious security risk. - Enabled: true +Metrics/MethodLength: + Description: Avoid methods longer than 50 lines of code. + Max: 50 +Metrics/ModuleLength: + Description: Avoid modules longer than 100 lines of code. + Max: 400 +Metrics/PerceivedComplexity: + Description: >- + A complexity metric geared towards measuring complexity for a + human reader. + Max: 15 -# -# Disabled cops -# +#################### +# Style +#################### -Layout/DotPosition: - Enabled: false -Layout/EmptyLinesAroundBlockBody: - Enabled: false -Layout/EmptyLinesAroundClassBody: - Enabled: false -Style/ClassAndModuleChildren: - Enabled: false -Style/CommentAnnotation: - Enabled: false -Style/Encoding: - Enabled: false -Naming/FileName: - Enabled: false -Style/FormatString: - Enabled: false -Style/GlobalVars: - Enabled: false -Style/GuardClause: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/LambdaCall: - Enabled: false -Style/Next: - Enabled: false -Style/NumericLiterals: - Enabled: false -Style/PercentLiteralDelimiters: - Enabled: false -Style/RaiseArgs: - Enabled: false -Style/RegexpLiteral: - Enabled: false -Style/SignalException: - Enabled: false -Style/SingleLineBlockParams: - Enabled: false -Style/SingleLineMethods: - Enabled: false Style/StringLiterals: - Enabled: false -Style/TrivialAccessors: - Enabled: false -Style/WhileUntilModifier: - Enabled: false -Style/WordArray: - Enabled: false -Style/InlineComment: - Enabled: false -Style/MethodCalledOnDoEndBlock: - Enabled: false -Style/SymbolArray: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Style/Alias: - Enabled: false -Style/ArrayJoin: - Enabled: false -Style/AsciiComments: - Enabled: false -Naming/AsciiIdentifiers: - Enabled: false -Style/Attr: - Enabled: false -Style/CaseEquality: - Enabled: false -Style/CharacterLiteral: - Enabled: false -Style/ClassVars: - Enabled: false -Style/ColonMethodCall: - Enabled: false -Style/PreferredHashMethods: - Enabled: false + Description: Checks if uses of quotes match the configured preference. + EnforcedStyle: single_quotes + Style/Documentation: + Description: Document classes and non-namespace modules. Enabled: false + Style/DoubleNegation: + Description: Checks for uses of double negation (!!). Enabled: false -Style/EachWithObject: - Enabled: false -Style/EmptyLiteral: - Enabled: false -Style/EvenOdd: - Enabled: false -Lint/FlipFlop: - Enabled: false -Style/IfWithSemicolon: - Enabled: false -Style/Lambda: - Enabled: false -Style/LineEndConcatenation: - Enabled: false -Style/ModuleFunction: - Enabled: false -Style/NegatedIf: - Enabled: false -Style/NegatedWhile: - Enabled: false -Style/NilComparison: - Enabled: false -Style/Not: - Enabled: false -Style/OneLineConditional: - Enabled: false -Naming/BinaryOperatorParameterName: - Enabled: false -Style/PerlBackrefs: - Enabled: false -Style/Proc: - Enabled: false -Style/SelfAssignment: - Enabled: false -Style/SpecialGlobalVars: - Enabled: false -Style/VariableInterpolation: - Enabled: false -Style/WhenThen: - Enabled: false + Style/FrozenStringLiteralComment: + Description: >- + Add the frozen_string_literal comment to the top of files + to help transition to frozen string literals by default. Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Lint/AssignmentInCondition: - Enabled: false -Lint/AmbiguousOperator: - Enabled: false -Lint/AmbiguousRegexpLiteral: - Enabled: false -Layout/ConditionPosition: - Enabled: false -Lint/DeprecatedClassMethods: - Enabled: false -Lint/ElseLayout: - Enabled: false -Lint/SuppressedException: - Enabled: false -Lint/LiteralInInterpolation: - Enabled: false -Lint/Loop: - Enabled: false -Lint/ParenthesesAsGroupedExpression: - Enabled: false -Lint/RequireParentheses: - Enabled: false -Lint/UnderscorePrefixedVariableName: - Enabled: false -Lint/Void: + +Style/WordArray: + Description: Use %w or %W for arrays of words. Enabled: false diff --git a/Gemfile b/Gemfile index 0d26949b6d..2eeeaf7a55 100644 --- a/Gemfile +++ b/Gemfile @@ -115,15 +115,16 @@ group :test, :development do end group :development, :test do - gem 'rspec-rails', '2.12.0' - gem 'rb-readline' gem 'byebug' - gem 'pry-byebug', '3.9.0' + gem 'pry-byebug', '3.9.0' gem 'rack' + gem 'rb-readline' + gem 'rspec-rails', '2.12.0' + gem 'rubocop', '~> 0.92' + gem 'rubocop-rails' + gem 'rubocop-rspec' + gem 'thin', require: false gem 'zeus' - - # Server - gem 'thin', require: false end # segment metrics diff --git a/Gemfile.lock b/Gemfile.lock index c715ebf5ea..b69a3e973d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,7 @@ GEM argon2 (2.0.2) ffi (~> 1.9) ffi-compiler (>= 0.1) + ast (2.4.1) avro (1.10.0) multi_json (~> 1) aws-eventstream (1.0.3) @@ -291,6 +292,9 @@ GEM multi_xml (~> 0.5) rack (>= 1.2, < 3) os (1.1.1) + parallel (1.19.2) + parser (2.7.1.5) + ast (~> 2.4.1) pg (0.20.0) poltergeist (1.18.1) capybara (>= 2.1, < 4) @@ -337,6 +341,7 @@ GEM activesupport (= 4.2.11.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) raindrops (0.15.0) rake (0.9.2.2) rb-fsevent (0.10.4) @@ -351,6 +356,7 @@ GEM redis (3.3.5) redis-namespace (1.7.0) redis (>= 3.0.4) + regexp_parser (1.8.0) representable (3.0.4) declarative (< 0.1.0) declarative-option (< 0.2.0) @@ -368,6 +374,7 @@ GEM resque-metrics (0.1.1) resque (~> 1.19) retriable (3.1.2) + rexml (3.2.4) rly (0.2.3) rollbar (2.11.5) multi_json @@ -389,8 +396,26 @@ GEM rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) + rubocop (0.92.0) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) + rexml + rubocop-ast (>= 0.5.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (0.5.0) + parser (>= 2.7.1.5) + rubocop-rails (2.8.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 0.87.0) + rubocop-rspec (1.43.2) + rubocop (~> 0.87) ruby-ole (1.2.12.2) ruby-prof (0.15.1) + ruby-progressbar (1.10.1) ruby-saml (1.7.0) nokogiri (>= 1.5.10) rubyzip (2.3.0) @@ -465,6 +490,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.7) + unicode-display_width (1.7.0) unicorn (4.8.2) kgio (~> 2.6) rack @@ -558,6 +584,9 @@ DEPENDENCIES rotp (~> 3.3, >= 3.3.1) rqrcode (~> 0.10.1) rspec-rails (= 2.12.0) + rubocop (~> 0.92) + rubocop-rails + rubocop-rspec ruby-prof (= 0.15.1) ruby-saml (= 1.7.0) rubyzip (>= 2.0.0) diff --git a/NEWS.md b/NEWS.md index bb2063386d..71064a90be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -45,6 +45,7 @@ Development * Added a script to generate a graph of Sequel models associations [#15865](https://github.com/CartoDB/cartodb/pull/15865) * Migrate `::FeatureFlagsUser` to `ActiveRecord` [#15841](https://github.com/CartoDB/cartodb/pull/15841) * Migrate `::SearchTweet` to ActiveRecord [#15859](https://github.com/CartoDB/cartodb/pull/15859) +* Revamp Rubocop config 4.41.1 (2020-09-03) -------------------