Commit 217d4a19 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'rc/use-gitlab-styles' into 'master'

Use gitlab-styles which provides shared RuboCop config and cops

Closes #37711

See merge request gitlab-org/gitlab-ce!14337
parents 299e04e3 a2d39b80
......@@ -16,6 +16,7 @@ engines:
enabled: true
rubocop:
enabled: true
channel: "gitlab-rubocop-0-52"
ratings:
paths:
- Gemfile.lock
......
......@@ -594,7 +594,7 @@ codequality:
script:
- cp .rubocop.yml .rubocop.yml.bak
- grep -v "rubocop-gitlab-security" .rubocop.yml.bak > .rubocop.yml
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate analyze -f json > raw_codeclimate.json
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc dev.gitlab.org:5005/gitlab/gitlab-build-images:gitlab-codeclimate-v2 analyze -f json > raw_codeclimate.json
- cat raw_codeclimate.json | docker run -i stedolan/jq -c 'map({check_name,fingerprint,location})' > codeclimate.json
- mv .rubocop.yml.bak .rubocop.yml
artifacts:
......
require:
- rubocop-rspec
- rubocop-gitlab-security
- ./rubocop/rubocop
inherit_gem:
gitlab-styles:
- rubocop-default.yml
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.3
TargetRailsVersion: 4.2
# Cop names are not d§splayed in offense messages by default. Change behavior
# by overriding DisplayCopNames, or by giving the -D/--display-cop-names
# option.
DisplayCopNames: true
# Style guide URLs are not displayed in offense messages by default. Change
# behavior by overriding DisplayStyleGuide, or by giving the
# -S/--display-style-guide option.
DisplayStyleGuide: false
# Exclude some GitLab files
Exclude:
- 'vendor/**/*'
- 'node_modules/**/*'
- 'db/*'
- 'db/fixtures/**/*'
- 'db/geo/*'
- 'tmp/**/*'
- 'bin/**/*'
- 'generator_templates/**/*'
- 'builds/**/*'
# Gems in consecutive lines should be alphabetically sorted
Bundler/OrderedGems:
Enabled: false
# Layout ######################################################################
# Check indentation of private/protected visibility modifiers.
Layout/AccessModifierIndentation:
Enabled: true
# Align the elements of an array literal if they span more than one line.
Layout/AlignArray:
Enabled: true
# Align the elements of a hash literal if they span more than one line.
Layout/AlignHash:
Enabled: true
# Here we check if the parameters on a multi-line method call or
# definition are aligned.
Layout/AlignParameters:
Enabled: false
# Put end statement of multiline block on its own line.
Layout/BlockEndNewline:
Enabled: true
# Indentation of when in a case/when/[else/]end.
Layout/CaseIndentation:
Enabled: true
# Indentation of comments.
Layout/CommentIndentation:
Enabled: true
# Multi-line method chaining should be done with leading dots.
Layout/DotPosition:
Enabled: true
EnforcedStyle: leading
# Align elses and elsifs correctly.
Layout/ElseAlignment:
Enabled: true
# Add an empty line after magic comments to separate them from code.
Layout/EmptyLineAfterMagicComment:
Enabled: false
# Use empty lines between defs.
Layout/EmptyLineBetweenDefs:
Enabled: true
# Don't use several empty lines in a row.
Layout/EmptyLines:
Enabled: true
# Keep blank lines around access modifiers.
Layout/EmptyLinesAroundAccessModifier:
Enabled: true
# Keeps track of empty lines around block bodies.
Layout/EmptyLinesAroundBlockBody:
Enabled: true
# Keeps track of empty lines around class bodies.
Layout/EmptyLinesAroundClassBody:
Enabled: true
# Keeps track of empty lines around exception handling keywords.
Layout/EmptyLinesAroundExceptionHandlingKeywords:
Enabled: false
# Keeps track of empty lines around method bodies.
Layout/EmptyLinesAroundMethodBody:
Enabled: true
# Keeps track of empty lines around module bodies.
Layout/EmptyLinesAroundModuleBody:
Enabled: true
# Use Unix-style line endings.
Layout/EndOfLine:
Enabled: true
# Checks for a line break before the first parameter in a multi-line method
# parameter definition.
Layout/FirstMethodParameterLineBreak:
Enabled: true
# Keep indentation straight.
Layout/IndentationConsistency:
Enabled: true
# Use 2 spaces for indentation.
Layout/IndentationWidth:
Enabled: true
# Checks the indentation of the first line of the right-hand-side of a
# multi-line assignment.
Layout/IndentAssignment:
Enabled: true
# This cops checks the indentation of the here document bodies.
Layout/IndentHeredoc:
Enabled: false
# Comments should start with a space.
Layout/LeadingCommentSpace:
Enabled: true
# Checks that the closing brace in an array literal is either on the same line
# as the last array element, or a new line.
Layout/MultilineArrayBraceLayout:
Enabled: true
EnforcedStyle: symmetrical
# Ensures newlines after multiline block do statements.
Layout/MultilineBlockLayout:
Enabled: true
# Checks that the closing brace in a hash literal is either on the same line as
# the last hash element, or a new line.
Layout/MultilineHashBraceLayout:
Enabled: true
EnforcedStyle: symmetrical
# Checks that the closing brace in a method call is either on the same line as
# the last method argument, or a new line.
Layout/MultilineMethodCallBraceLayout:
Enabled: false
EnforcedStyle: symmetrical
# Checks indentation of method calls with the dot operator that span more than
# one line.
Layout/MultilineMethodCallIndentation:
Enabled: false
# Checks that the closing brace in a method definition is symmetrical with
# respect to the opening brace and the method parameters.
Layout/MultilineMethodDefinitionBraceLayout:
Enabled: false
# Checks indentation of binary operations that span more than one line.
Layout/MultilineOperationIndentation:
Enabled: true
EnforcedStyle: indented
# Use spaces after colons.
Layout/SpaceAfterColon:
Enabled: true
# Use spaces after commas.
Layout/SpaceAfterComma:
Enabled: true
# Do not put a space between a method name and the opening parenthesis in a
# method definition.
Layout/SpaceAfterMethodName:
Enabled: true
# Tracks redundant space after the ! operator.
Layout/SpaceAfterNot:
Enabled: true
# Use spaces after semicolons.
Layout/SpaceAfterSemicolon:
Enabled: true
# Use space around equals in parameter default
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
# Use a space around keywords if appropriate.
Layout/SpaceAroundKeyword:
Enabled: true
# Use a single space around operators.
Layout/SpaceAroundOperators:
Enabled: true
# Checks that block braces have or don't have a space before the opening
# brace depending on configuration.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Layout/SpaceBeforeBlockBraces:
Enabled: true
# No spaces before commas.
Layout/SpaceBeforeComma:
Enabled: true
# Checks for missing space between code and a comment on the same line.
Layout/SpaceBeforeComment:
Enabled: true
# No spaces before semicolons.
Layout/SpaceBeforeSemicolon:
Enabled: true
# Checks for spaces inside square brackets.
Layout/SpaceInsideBrackets:
Enabled: true
# Use spaces inside hash literal braces - or don't.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
# No spaces inside range literals.
Layout/SpaceInsideRangeLiteral:
Enabled: true
# Checks for padding/surrounding spaces inside string interpolation.
Layout/SpaceInsideStringInterpolation:
EnforcedStyle: no_space
Enabled: true
# No hard tabs.
Layout/Tab:
Enabled: true
# Checks trailing blank lines and final newline.
Layout/TrailingBlankLines:
Enabled: true
# Avoid trailing whitespace.
Layout/TrailingWhitespace:
Enabled: true
# Style #######################################################################
# Check the naming of accessor methods for get_/set_.
Style/AccessorMethodName:
Enabled: false
# Use alias_method instead of alias.
Style/Alias:
EnforcedStyle: prefer_alias_method
Enabled: true
# Whether `and` and `or` are banned only in conditionals (conditionals)
# or completely (always).
Style/AndOr:
Enabled: true
# Use `Array#join` instead of `Array#*`.
Style/ArrayJoin:
Enabled: true
# Use only ascii symbols in comments.
Style/AsciiComments:
Enabled: true
# Use only ascii symbols in identifiers.
Style/AsciiIdentifiers:
Enabled: true
# Checks for uses of Module#attr.
Style/Attr:
Enabled: true
# Avoid the use of BEGIN blocks.
Style/BeginBlock:
Enabled: true
# Do not use block comments.
Style/BlockComments:
Enabled: true
# Avoid using {...} for multi-line blocks (multiline chaining is # always
# ugly). Prefer {...} over do...end for single-line blocks.
Style/BlockDelimiters:
Enabled: true
# This cop checks for braces around the last parameter in a method call
# if the last parameter is a hash.
Style/BracesAroundHashParameters:
Enabled: false
# This cop checks for uses of the case equality operator(===).
Style/CaseEquality:
Enabled: false
# Checks for uses of character literals.
Style/CharacterLiteral:
Enabled: true
# Use CamelCase for classes and modules.'
Style/ClassAndModuleCamelCase:
Enabled: true
# Checks style of children classes and modules.
Style/ClassAndModuleChildren:
Enabled: false
# Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.
Style/ClassCheck:
Enabled: true
# Use self when defining module/class methods.
Style/ClassMethods:
Enabled: true
# Avoid the use of class variables.
Style/ClassVars:
Enabled: true
# This cop checks for methods invoked via the :: operator instead
# of the . operator (like FileUtils::rmdir instead of FileUtils.rmdir).
Style/ColonMethodCall:
Enabled: true
# This cop checks that comment annotation keywords are written according
# to guidelines.
Style/CommentAnnotation:
Enabled: false
# Check for `if` and `case` statements where each branch is used for
# assignment to the same variable when using the return of the
# condition can be used instead.
Style/ConditionalAssignment:
Enabled: true
# Constants should use SCREAMING_SNAKE_CASE.
Style/ConstantName:
Enabled: true
# Use def with parentheses when there are arguments.
Style/DefWithParentheses:
Enabled: true
# Document classes and non-namespace modules.
Style/Documentation:
Enabled: false
# This cop checks for uses of double negation (!!) to convert something
# to a boolean value. As this is both cryptic and usually redundant, it
# should be avoided.
Style/DoubleNegation:
Enabled: false
# Avoid the use of END blocks.
Style/EndBlock:
Enabled: true
# Favor the use of Fixnum#even? && Fixnum#odd?
Style/EvenOdd:
Enabled: true
# Use snake_case for source file names.
Style/FileName:
Enabled: true
# Checks for flip flops.
Style/FlipFlop:
Enabled: true
# Checks use of for or each in multiline loops.
Style/For:
Enabled: true
# Use a consistent style for format string tokens.
Style/FormatStringToken:
Enabled: false
# Checks if there is a magic comment to enforce string literals
Style/FrozenStringLiteralComment:
Enabled: false
# Do not introduce global variables.
Style/GlobalVars:
Enabled: true
Exclude:
- 'lib/backup/**/*'
- 'lib/tasks/**/*'
# Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }`
# over 1.8 syntax `{ :a => 1, :b => 2 }`.
Style/HashSyntax:
Enabled: true
# Checks that conditional statements do not have an identical line at the
# end of each branch, which can validly be moved out of the conditional.
Style/IdenticalConditionalBranches:
Enabled: true
# Do not use if x; .... Use the ternary operator instead.
Style/IfWithSemicolon:
Enabled: true
# Use Kernel#loop for infinite loops.
Style/InfiniteLoop:
Enabled: true
# Use the inverse method instead of `!.method`
# if an inverse method is defined.
Style/InverseMethods:
Enabled: false
# Use lambda.call(...) instead of lambda.(...).
Style/LambdaCall:
Enabled: true
# Checks if the method definitions have or don't have parentheses.
Style/MethodDefParentheses:
Enabled: true
# Use the configured style when naming methods.
Style/MethodName:
Enabled: true
# Checks for usage of `extend self` in modules.
Style/ModuleFunction:
Enabled: false
# Avoid multi-line chains of blocks.
Style/MultilineBlockChain:
Enabled: true
# Do not use then for multi-line if/unless.
Style/MultilineIfThen:
Enabled: true
# Avoid multi-line `? :` (the ternary operator), use if/unless instead.
Style/MultilineTernaryOperator:
Enabled: true
# Avoid comparing a variable with multiple items in a conditional,
# use Array#include? instead.
Style/MultipleComparison:
Enabled: false
# This cop checks whether some constant value isn't a
# mutable literal (e.g. array or hash).
Style/MutableConstant:
Enabled: true
Exclude:
- 'db/migrate/**/*'
- 'db/post_migrate/**/*'
# Favor unless over if for negative conditions (or control flow or).
Style/NegatedIf:
Enabled: true
# Avoid using nested modifiers.
Style/NestedModifier:
Enabled: true
# Use one expression per branch in a ternary operator.
Style/NestedTernaryOperator:
Enabled: true
# Prefer x.nil? to x == nil.
Style/NilComparison:
Enabled: true
# Checks for redundant nil checks.
Style/NonNilCheck:
Enabled: true
# Use ! instead of not.
Style/Not:
Enabled: true
# Add underscores to large numeric literals to improve their readability.
Style/NumericLiterals:
Enabled: false
# Favor the ternary operator(?:) over if/then/else/end constructs.
Style/OneLineConditional:
Enabled: true
# When defining binary operators, name the argument other.
Style/OpMethod:
Enabled: true
# Don't use parentheses around the condition of an if/unless/while.
Style/ParenthesesAroundCondition:
Enabled: true
# This cop (by default) checks for uses of methods Hash#has_key? and
# Hash#has_value? where it enforces Hash#key? and Hash#value?
# It is configurable to enforce the inverse, using `verbose` method
# names also.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: short, verbose
Style/PreferredHashMethods:
Enabled: false
# Checks for an obsolete RuntimeException argument in raise/fail.
Style/RedundantException:
Enabled: true
# Checks for parentheses that seem not to serve any purpose.
Style/RedundantParentheses:
Enabled: true
# Don't use semicolons to terminate expressions.
Style/Semicolon:
Enabled: true
# Checks for proper usage of fail and raise.
Style/SignalException:
EnforcedStyle: only_raise
Enabled: true
# Check for the usage of parentheses around stabby lambda arguments.
Style/StabbyLambdaParentheses:
EnforcedStyle: require_parentheses
Enabled: true
# Checks if uses of quotes match the configured preference.
Style/StringLiterals:
Enabled: false
# Checks if configured preferred methods are used over non-preferred.
Style/StringMethods:
PreferredMethods:
intern: to_sym
Enabled: true
# Use %i or %I for arrays of symbols.
Style/SymbolArray:
Enabled: false
# This cop checks for trailing comma in array and hash literals.
Style/TrailingCommaInLiteral:
Enabled: true
EnforcedStyleForMultiline: no_comma
# This cop checks for trailing comma in argument lists.
Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: no_comma
# Checks for %W when interpolation is not needed.
Style/UnneededCapitalW:
Enabled: true
# Checks for %q/%Q when single quotes or double quotes would do.
Style/UnneededPercentQ:
Enabled: false
# Don't interpolate global, instance and class variables directly in strings.
Style/VariableInterpolation:
Enabled: true
# Use the configured style when naming variables.
Style/VariableName:
EnforcedStyle: snake_case
Enabled: true
# Use the configured style when numbering variables.
Style/VariableNumber:
Enabled: false
# Use when x then ... for one-line cases.
Style/WhenThen:
Enabled: true
# Checks for redundant do after while or until.
Style/WhileUntilDo:
Enabled: true
# Favor modifier while/until usage when you have a single-line body.
Style/WhileUntilModifier:
Enabled: true
# Use %w or %W for arrays of words.
Style/WordArray:
Enabled: true
# Do not use literals as the first operand of a comparison.
Style/YodaCondition:
Enabled: false
# Use `proc` instead of `Proc.new`.
Style/Proc:
Enabled: true
# Use `spam?` instead of `is_spam?`
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
# NameWhitelist: is_a?
Style/PredicateName:
Enabled: true
NamePrefixBlacklist: is_
Exclude:
- 'spec/**/*'
- 'features/**/*'
# Metrics #####################################################################
# A calculated magnitude based on number of assignments,
# branches, and conditions.
Metrics/AbcSize:
Enabled: true
Max: 54.28
# This cop checks if the length of a block exceeds some maximum value.
Metrics/BlockLength:
Enabled: false
# Avoid excessive block nesting.
Metrics/BlockNesting:
Enabled: true
Max: 4
# Avoid classes longer than 100 lines of code.
Metrics/ClassLength:
Enabled: false
# A complexity metric that is strongly correlated to the number
# of test cases needed to validate a method.
Metrics/CyclomaticComplexity:
Enabled: true
Max: 13
# Limit lines to 80 characters.
Metrics/LineLength:
Enabled: false
# Avoid methods longer than 10 lines of code.
Metrics/MethodLength:
Enabled: false
# Avoid modules longer than 100 lines of code.
Metrics/ModuleLength:
Enabled: false
# Avoid parameter lists longer than three or four parameters.
Metrics/ParameterLists:
Enabled: true
Max: 8
# A complexity metric geared towards measuring complexity for a human reader.
Metrics/PerceivedComplexity:
Enabled: true
Max: 14
# Lint ########################################################################
# Checks for ambiguous block association with method when param passed without
# parentheses.
Lint/AmbiguousBlockAssociation:
Enabled: false
# Checks for ambiguous operators in the first argument of a method invocation
# without parentheses.
Lint/AmbiguousOperator:
Enabled: true
# This cop checks for ambiguous regexp literals in the first argument of
# a method invocation without parentheses.
Lint/AmbiguousRegexpLiteral:
Enabled: false
# This cop checks for assignments in the conditions of
# if/while/until.
Lint/AssignmentInCondition:
Enabled: false
# Align block ends correctly.
Lint/BlockAlignment:
Enabled: true
# Default values in optional keyword arguments and optional ordinal arguments
# should not refer back to the name of the argument.
Lint/CircularArgumentReference:
Enabled: true
# Checks for condition placed in a confusing position relative to the keyword.
Lint/ConditionPosition:
Enabled: true
# Check for debugger calls.
Lint/Debugger:
Enabled: true
# Align ends corresponding to defs correctly.
Lint/DefEndAlignment:
Enabled: true
# Check for deprecated class method calls.
Lint/DeprecatedClassMethods:
Enabled: true
# Check for immutable argument given to each_with_object.
Lint/EachWithObjectArgument:
Enabled: true
# Check for odd code arrangement in an else block.
Lint/ElseLayout:
Enabled: true
# Checks for empty ensure block.
Lint/EmptyEnsure:
Enabled: true
# Checks for the presence of `when` branches without a body.
Lint/EmptyWhen:
Enabled: true
# Align ends correctly.
Lint/EndAlignment:
Enabled: true
# END blocks should not be placed inside method definitions.
Lint/EndInMethod:
Enabled: true
# Do not use return in an ensure block.
Lint/EnsureReturn:
Enabled: true
# Catches floating-point literals too large or small for Ruby to represent.
Lint/FloatOutOfRange:
Enabled: true
# The number of parameters to format/sprint must match the fields.
Lint/FormatParameterMismatch:
Enabled: true
# This cop checks for *rescue* blocks with no body.
Lint/HandleExceptions:
Enabled: false
# Checks for adjacent string literals on the same line, which could better be
# represented as a single string literal.
Lint/ImplicitStringConcatenation:
Enabled: true
# Checks for attempts to use `private` or `protected` to set the visibility
# of a class method, which does not work.
Lint/IneffectiveAccessModifier:
Enabled: false
# Checks for invalid character literals with a non-escaped whitespace
# character.
Lint/InvalidCharacterLiteral:
Enabled: true
# Checks of literals used in conditions.
Lint/LiteralInCondition:
Enabled: true
# Checks for literals used in interpolation.
Lint/LiteralInInterpolation:
Enabled: true
# This cop checks for uses of *begin...end while/until something*.
Lint/Loop:
Enabled: false
# Do not use nested method definitions.
Lint/NestedMethodDefinition:
Enabled: true
# Do not omit the accumulator when calling `next` in a `reduce`/`inject` block.
Lint/NextWithoutAccumulator:
Enabled: true
# Checks for method calls with a space before the opening parenthesis.
Lint/ParenthesesAsGroupedExpression:
Enabled: true
# Checks for `rand(1)` calls. Such calls always return `0` and most likely
# a mistake.
Lint/RandOne:
Enabled: true
# Use parentheses in the method call to avoid confusion about precedence.
Lint/RequireParentheses:
Enabled: true
# Avoid rescuing the Exception class.
Lint/RescueException:
Enabled: true
# Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception.
Lint/ShadowedException:
Enabled: false
# This cop looks for use of the same name as outer local variables
# for block arguments or block local variables.
Lint/ShadowingOuterLocalVariable:
Enabled: false
# Checks for Object#to_s usage in string interpolation.
Lint/StringConversionInInterpolation:
Enabled: true
# Do not use prefix `_` for a variable that is used.
Lint/UnderscorePrefixedVariableName:
Enabled: true
# This cop checks for using Fixnum or Bignum constant
Lint/UnifiedInteger:
Enabled: true
# Checks for rubocop:disable comments that can be removed.
# Note: this cop is not disabled when disabling all cops.
# It must be explicitly disabled.
Lint/UnneededDisable:
Enabled: false
# This cop checks for unneeded usages of splat expansion
Lint/UnneededSplatExpansion:
Enabled: false
# Unreachable code.
Lint/UnreachableCode:
Enabled: true
# This cop checks for unused block arguments.
Lint/UnusedBlockArgument:
Enabled: false
# This cop checks for unused method arguments.
Lint/UnusedMethodArgument:
Enabled: false
# Checks for useless access modifiers.
Lint/UselessAccessModifier:
Enabled: true
# Checks for useless assignment to a local variable.
Lint/UselessAssignment:
Enabled: true
# Checks for comparison of something with itself.
Lint/UselessComparison:
Enabled: true
# Checks for useless `else` in `begin..end` without `rescue`.
Lint/UselessElseWithoutRescue:
Enabled: true
# Checks for useless setter call to a local variable.
Lint/UselessSetterCall:
Enabled: true
# Possible use of operator/literal/variable in void context.
Lint/Void:
Enabled: true
# Performance #################################################################
# Use `caller(n..n)` instead of `caller`.
Performance/Caller:
Enabled: false
# Use `casecmp` rather than `downcase ==`.
Performance/Casecmp:
Enabled: true
# Use `str.{start,end}_with?(x, ..., y, ...)` instead of
# `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
Performance/DoubleStartEndWith:
Enabled: true
# Use `strip` instead of `lstrip.rstrip`.
Performance/LstripRstrip:
Enabled: true
# Use `Range#cover?` instead of `Range#include?`.
Performance/RangeInclude:
Enabled: true
# This cop identifies the use of a `&block` parameter and `block.call`
# where `yield` would do just as well.
Performance/RedundantBlockCall:
Enabled: true
# This cop identifies use of `Regexp#match` or `String#match in a context
# where the integral return value of `=~` would do just as well.
Performance/RedundantMatch:
Enabled: true
# This cop identifies places where `Hash#merge!` can be replaced by
# `Hash#[]=`.
Performance/RedundantMerge:
Enabled: true
MaxKeyValuePairs: 1
# Use `sort` instead of `sort_by { |x| x }`.
Performance/RedundantSortBy:
Enabled: true
# Use `start_with?` instead of a regex match anchored to the beginning of a
# string.
Performance/StartWith:
Enabled: true
# Use `tr` instead of `gsub` when you are replacing the same number of
# characters. Use `delete` instead of `gsub` when you are deleting
# characters.
Performance/StringReplacement:
Enabled: true
# Checks for `.times.map` calls.
Performance/TimesMap:
Enabled: true
# Security ####################################################################
# This cop checks for the use of JSON class methods which have potential
# security issues.
Security/JSONLoad:
Enabled: true
# This cop checks for the use of *Kernel#eval*.
Security/Eval:
Enabled: true
# Rails #######################################################################
# Enables Rails cops.
Rails:
Enabled: true
# Enforces consistent use of action filter methods.
Rails/ActionFilter:
Enabled: true
EnforcedStyle: action
# Check that models subclass ApplicationRecord.
Rails/ApplicationRecord:
Enabled: false
# Enforce using `blank?` and `present?`.
Rails/Blank:
Enabled: false
# Checks the correct usage of date aware methods, such as `Date.today`,
# `Date.current`, etc.
Rails/Date:
Enabled: false
# Prefer delegate method for delegations.
# Disabled per https://gitlab.com/gitlab-org/gitlab-ce/issues/35869
Rails/Delegate:
Enabled: false
# This cop checks dynamic `find_by_*` methods.
Rails/DynamicFindBy:
Enabled: false
# This cop enforces that 'exit' calls are not used within a rails app.
Rails/Exit:
Enabled: true
Exclude:
- lib/gitlab/upgrader.rb
- 'lib/backup/**/*'
# Prefer `find_by` over `where.first`.
Rails/FindBy:
Enabled: true
# Prefer `all.find_each` over `all.find`.
Rails/FindEach:
Enabled: true
# Prefer has_many :through to has_and_belongs_to_many.
Rails/HasAndBelongsToMany:
Enabled: true
# This cop is used to identify usages of http methods like `get`, `post`,
# `put`, `patch` without the usage of keyword arguments in your tests and
# change them to use keyword args.
Rails/HttpPositionalArguments:
Enabled: false
# Checks for calls to puts, print, etc.
Rails/Output:
Enabled: true
Exclude:
- lib/gitlab/seeder.rb
- lib/gitlab/upgrader.rb
- 'lib/backup/**/*'
- 'lib/tasks/**/*'
# This cop checks for the use of output safety calls like html_safe and
# raw.
Rails/OutputSafety:
Enabled: false
# Checks for incorrect grammar when using methods like `3.day.ago`.
Rails/PluralizationGrammar:
Enabled: true
# Enforce using `blank?` and `present?`.
Rails/Present:
Enabled: false
# Checks for `read_attribute(:attr)` and `write_attribute(:attr, val)`.
Rails/ReadWriteAttribute:
Enabled: false
# Do not assign relative date to constants.
Rails/RelativeDateConstant:
Enabled: false
# Checks the arguments of ActiveRecord scopes.
Rails/ScopeArgs:
Enabled: true
# This cop checks for the use of Time methods without zone.
Rails/TimeZone:
Enabled: false
# This cop checks for the use of old-style attribute validation macros.
Rails/Validation:
Enabled: true
# RSpec #######################################################################
# Check that instances are not being stubbed globally.
RSpec/AnyInstance:
Enabled: false
# Check for expectations where `be(...)` can replace `eql(...)`.
RSpec/BeEql:
Enabled: true
# We don't enforce this as we use this technique in a few places.
RSpec/BeforeAfterAll:
Enabled: false
# Check that the first argument to the top level describe is the tested class or
# module.
RSpec/DescribeClass:
Enabled: false
# Checks that the second argument to `describe` specifies a method.
RSpec/DescribeMethod:
Enabled: false
# Avoid describing symbols.
RSpec/DescribeSymbol:
Enabled: true
# Checks that tests use `described_class`.
RSpec/DescribedClass:
Enabled: true
# Checks if an example group does not include any tests.
RSpec/EmptyExampleGroup:
Enabled: true
CustomIncludeMethods:
- run_permission_checks
# Checks for long example.
RSpec/ExampleLength:
Enabled: false
Max: 5
# Do not use should when describing your tests.
RSpec/ExampleWording:
Enabled: false
CustomTransform:
be: is
have: has
not: does not
IgnoredWords: []
# Checks for `expect(...)` calls containing literal values.
RSpec/ExpectActual:
Enabled: true
# Checks for opportunities to use `expect { … }.to output`.
RSpec/ExpectOutput:
Enabled: true
# Checks the file and folder naming of the spec file.
RSpec/FilePath:
Enabled: true
IgnoreMethods: true
Exclude:
- 'qa/**/*'
- 'spec/javascripts/fixtures/*'
- 'spec/requests/api/v3/*'
# Checks if there are focused specs.
RSpec/Focus:
Enabled: true
# Checks the arguments passed to `before`, `around`, and `after`.
RSpec/HookArgument:
Enabled: true
EnforcedStyle: implicit
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: is_expected, should
RSpec/ImplicitExpect:
Enabled: true
EnforcedStyle: is_expected
# Checks for the usage of instance variables.
RSpec/InstanceVariable:
Enabled: false
# Checks for `subject` definitions that come after `let` definitions.
RSpec/LeadingSubject:
Enabled: false
# Checks unreferenced `let!` calls being used for test setup.
RSpec/LetSetup:
Enabled: false
# Check that chains of messages are not being stubbed.
RSpec/MessageChain:
Enabled: false
# Checks that message expectations are set using spies.
RSpec/MessageSpies:
Enabled: false
# Checks for multiple top-level describes.
RSpec/MultipleDescribes:
Enabled: false
# Checks if examples contain too many `expect` calls.
RSpec/MultipleExpectations:
Enabled: false
# Checks for explicitly referenced test subjects.
RSpec/NamedSubject:
Enabled: false
# Checks for nested example groups.
RSpec/NestedGroups:
Enabled: false
# Enforces the usage of the same method on all negative message expectations.
RSpec/NotToNot:
EnforcedStyle: not_to
Enabled: true
# Check for repeated description strings in example groups.
RSpec/RepeatedDescription:
Enabled: false
# Ensure RSpec hook blocks are always multi-line.
RSpec/SingleLineHook:
Enabled: true
Exclude:
- 'spec/factories/*'
- 'spec/requests/api/v3/*'
# Checks for stubbed test subjects.
RSpec/SubjectStub:
Enabled: false
# Prefer using verifying doubles over normal doubles.
RSpec/VerifiedDoubles:
Enabled: false
# Gitlab ###################################################################
Gitlab/ModuleWithInstanceVariables:
......@@ -1197,43 +29,3 @@ Gitlab/ModuleWithInstanceVariables:
# We ignore spec helpers because it usually doesn't matter
- spec/support/**/*.rb
- features/steps/**/*.rb
# GitlabSecurity ###########################################################
GitlabSecurity/DeepMunge:
Enabled: true
Exclude:
- 'lib/**/*.rake'
- 'spec/**/*'
# To be enabled by https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13610
GitlabSecurity/JsonSerialization:
Enabled: false
GitlabSecurity/PublicSend:
Enabled: true
Exclude:
- 'config/**/*'
- 'db/**/*'
- 'features/**/*'
- 'lib/**/*.rake'
- 'qa/**/*'
- 'spec/**/*'
GitlabSecurity/RedirectToParamsUpdate:
Enabled: true
Exclude:
- 'lib/**/*.rake'
- 'spec/**/*'
GitlabSecurity/SqlInjection:
Enabled: true
Exclude:
- 'lib/**/*.rake'
- 'spec/**/*'
GitlabSecurity/SystemCommandInjection:
Enabled: true
Exclude:
- 'lib/**/*.rake'
- 'spec/**/*'
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 0`
# on 2017-07-10 01:48:30 +0900 using RuboCop version 0.49.1.
# `rubocop --auto-gen-config`
# on 2017-12-14 12:04:26 +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: 181
# Offense count: 174
Capybara/CurrentPathExpectation:
Enabled: false
# Offense count: 951
Capybara/FeatureMethods:
Enabled: false
# Offense count: 24
FactoryBot/DynamicAttributeDefinedStatically:
Exclude:
- 'spec/factories/broadcast_messages.rb'
- 'spec/factories/ci/builds.rb'
- 'spec/factories/ci/runners.rb'
- 'spec/factories/clusters/applications/helm.rb'
- 'spec/factories/clusters/applications/ingress.rb'
- 'spec/factories/clusters/platforms/kubernetes.rb'
- 'spec/factories/emails.rb'
- 'spec/factories/gpg_keys.rb'
- 'spec/factories/group_members.rb'
- 'spec/factories/merge_requests.rb'
- 'spec/factories/notes.rb'
- 'spec/factories/oauth_access_grants.rb'
- 'spec/factories/project_members.rb'
- 'spec/factories/todos.rb'
- 'spec/factories/uploads.rb'
# Offense count: 65
# Cop supports --auto-correct.
Layout/EmptyLinesAroundArguments:
Enabled: false
# Offense count: 249
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Enabled: false
# Offense count: 119
# Offense count: 82
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Layout/IndentArray:
Enabled: false
# Offense count: 208
# Offense count: 239
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/IndentHash:
Enabled: false
# Offense count: 8
# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Layout/SpaceBeforeFirstArg:
Enabled: false
# Configuration parameters: .
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
EnforcedStyle: space
EnforcedStyleForEmptyBraces: space
# Offense count: 64
# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: AllowForAlignment.
Layout/SpaceBeforeFirstArg:
Exclude:
- 'config/routes/project.rb'
- 'db/migrate/20170506185517_add_foreign_key_pipeline_schedules_and_pipelines.rb'
- 'features/steps/project/source/browse_files.rb'
- 'features/steps/project/source/markdown_render.rb'
- 'lib/api/runners.rb'
- 'spec/features/search/user_uses_search_filters_spec.rb'
- 'spec/routing/project_routing_spec.rb'
- 'spec/services/system_note_service_spec.rb'
# Offense count: 93
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: require_no_space, require_space
Layout/SpaceInLambdaLiteral:
Enabled: false
# Offense count: 256
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBrackets: space, no_space
Layout/SpaceInsideArrayLiteralBrackets:
Exclude:
- 'spec/lib/gitlab/import_export/relation_factory_spec.rb'
# Offense count: 323
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Enabled: false
# Offense count: 135
# Offense count: 146
# Cop supports --auto-correct.
Layout/SpaceInsideParens:
Enabled: false
......@@ -55,178 +113,535 @@ Layout/SpaceInsideParens:
# Offense count: 14
# Cop supports --auto-correct.
Layout/SpaceInsidePercentLiteralDelimiters:
Exclude:
- 'lib/gitlab/git_access.rb'
- 'lib/gitlab/health_checks/fs_shards_check.rb'
- 'spec/lib/gitlab/health_checks/fs_shards_check_spec.rb'
# Offense count: 25
Lint/DuplicateMethods:
Exclude:
- 'app/models/application_setting.rb'
- 'app/models/commit.rb'
- 'app/models/note.rb'
- 'app/services/merge_requests/merge_service.rb'
- 'lib/bitbucket/representation/repo.rb'
- 'lib/declarative_policy/base.rb'
- 'lib/gitlab/ci/build/artifacts/metadata/entry.rb'
- 'lib/gitlab/cycle_analytics/base_event_fetcher.rb'
- 'lib/gitlab/diff/formatters/base_formatter.rb'
- 'lib/gitlab/git/blob.rb'
- 'lib/gitlab/git/repository.rb'
- 'lib/gitlab/git/tree.rb'
- 'lib/gitlab/git/wiki_page.rb'
- 'lib/gitlab/ldap/person.rb'
- 'lib/gitlab/o_auth/user.rb'
# Offense count: 4
Lint/InterpolationCheck:
Exclude:
- 'spec/features/issues/filtered_search/filter_issues_spec.rb'
- 'spec/features/users_spec.rb'
- 'spec/services/quick_actions/interpret_service_spec.rb'
# Offense count: 198
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Enabled: false
# Offense count: 2
Lint/NestedPercentLiteral:
Exclude:
- 'lib/gitlab/git/repository.rb'
- 'spec/support/email_format_shared_examples.rb'
# Offense count: 1
Lint/ReturnInVoidContext:
Exclude:
- 'app/models/project.rb'
# Offense count: 1
# Configuration parameters: IgnoreImplicitReferences.
Lint/ShadowedArgument:
Exclude:
- 'lib/gitlab/database/sha_attribute.rb'
# Offense count: 3
# Cop supports --auto-correct.
Lint/UnneededRequireStatement:
Exclude:
- 'db/post_migrate/20161221153951_rename_reserved_project_names.rb'
- 'db/post_migrate/20170313133418_rename_more_reserved_project_names.rb'
- 'lib/declarative_policy.rb'
# Offense count: 9
Lint/UriEscapeUnescape:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/models/project_services/drone_ci_service.rb'
- 'spec/lib/google_api/auth_spec.rb'
- 'spec/requests/api/files_spec.rb'
- 'spec/requests/api/internal_spec.rb'
- 'spec/requests/api/issues_spec.rb'
- 'spec/requests/api/v3/issues_spec.rb'
# Offense count: 2
Naming/ConstantName:
Exclude:
- 'lib/gitlab/import_sources.rb'
- 'lib/gitlab/ssh_public_key.rb'
# Offense count: 11
# Configuration parameters: EnforcedStyle.
# SupportedStyles: lowercase, uppercase
Naming/HeredocDelimiterCase:
Exclude:
- 'spec/lib/gitlab/diff/parser_spec.rb'
- 'spec/lib/json_web_token/rsa_token_spec.rb'
- 'spec/models/commit_spec.rb'
- 'spec/support/repo_helpers.rb'
- 'spec/support/seed_repo.rb'
# Offense count: 101
# Configuration parameters: Blacklist.
# Blacklist: END, (?-mix:EO[A-Z]{1})
Naming/HeredocDelimiterNaming:
Enabled: false
# Offense count: 28
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/HashEachMethods:
Enabled: false
# Offense count: 1
Performance/UnfreezeString:
Exclude:
- 'features/steps/project/commits/commits.rb'
# Offense count: 1
# Cop supports --auto-correct.
Performance/UriDefaultParser:
Exclude:
- 'lib/gitlab/url_sanitizer.rb'
# Offense count: 3745
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false
# Offense count: 272
# Offense count: 291
RSpec/EmptyLineAfterFinalLet:
Enabled: false
# Offense count: 181
# Offense count: 180
RSpec/EmptyLineAfterSubject:
Enabled: false
# Offense count: 9
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Offense count: 220
RSpec/ExpectInHook:
Enabled: false
# Offense count: 7
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, each, example
RSpec/HookArgument:
Exclude:
- 'spec/spec_helper.rb'
- 'spec/support/carrierwave.rb'
- 'spec/support/db_cleaner.rb'
- 'spec/support/gitaly.rb'
- 'spec/support/setup_builds_storage.rb'
# Offense count: 19
# Configuration parameters: EnforcedStyle.
# SupportedStyles: it_behaves_like, it_should_behave_like
RSpec/ItBehavesLike:
Enabled: false
Exclude:
- 'spec/lib/gitlab/git/commit_spec.rb'
- 'spec/lib/gitlab/git/repository_spec.rb'
- 'spec/lib/gitlab/shell_spec.rb'
- 'spec/services/notification_service_spec.rb'
- 'spec/workers/git_garbage_collect_worker_spec.rb'
# Offense count: 4
# Offense count: 5
RSpec/IteratedExpectation:
Enabled: false
Exclude:
- 'spec/features/admin/admin_settings_spec.rb'
- 'spec/features/merge_requests/diff_notes_resolve_spec.rb'
- 'spec/features/projects/awards/user_interacts_with_awards_in_issue_spec.rb'
- 'spec/lib/gitlab/gitlab_import/client_spec.rb'
- 'spec/lib/gitlab/legacy_github_import/client_spec.rb'
# Offense count: 75
RSpec/LetBeforeExamples:
Exclude:
- 'spec/controllers/projects/commit_controller_spec.rb'
- 'spec/lib/banzai/filter/issue_reference_filter_spec.rb'
- 'spec/lib/banzai/filter/user_reference_filter_spec.rb'
- 'spec/lib/gitlab/email/handler/create_issue_handler_spec.rb'
- 'spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb'
- 'spec/lib/gitlab/email/handler/create_note_handler_spec.rb'
- 'spec/models/commit_range_spec.rb'
- 'spec/models/milestone_spec.rb'
- 'spec/models/project_services/packagist_service_spec.rb'
- 'spec/models/repository_spec.rb'
- 'spec/rubocop/cop/migration/update_column_in_batches_spec.rb'
- 'spec/serializers/pipeline_details_entity_spec.rb'
- 'spec/views/ci/lints/show.html.haml_spec.rb'
# Offense count: 2
# Offense count: 1
RSpec/MultipleSubjects:
Exclude:
- 'spec/services/merge_requests/create_from_issue_service_spec.rb'
# Offense count: 4
RSpec/OverwritingSetup:
Exclude:
- 'spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb'
- 'spec/models/email_spec.rb'
- 'spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb'
- 'spec/services/notes/quick_actions_service_spec.rb'
# Offense count: 917
# Configuration parameters: Strict, EnforcedStyle.
# SupportedStyles: inflected, explicit
RSpec/PredicateMatcher:
Enabled: false
# Offense count: 36
# Offense count: 35
RSpec/RepeatedExample:
Enabled: false
# Offense count: 86
# Offense count: 132
# Configuration parameters: EnforcedStyle.
# SupportedStyles: and_return, block
RSpec/ReturnFromStub:
Enabled: false
# Offense count: 105
RSpec/ScatteredLet:
Enabled: false
# Offense count: 20
# Offense count: 22
RSpec/ScatteredSetup:
Enabled: false
Exclude:
- 'spec/controllers/projects/templates_controller_spec.rb'
- 'spec/lib/gitlab/bitbucket_import/importer_spec.rb'
- 'spec/lib/gitlab/git/env_spec.rb'
- 'spec/requests/api/jobs_spec.rb'
- 'spec/requests/api/v3/builds_spec.rb'
- 'spec/requests/api/v3/projects_spec.rb'
- 'spec/services/projects/create_service_spec.rb'
# Offense count: 1
RSpec/SharedContext:
Exclude:
- 'spec/features/admin/admin_groups_spec.rb'
# Offense count: 90
RSpec/SingleLineHook:
Enabled: false
# Offense count: 5
RSpec/VoidExpect:
Exclude:
- 'spec/features/projects/artifacts/download_spec.rb'
- 'spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb'
- 'spec/models/ci/group_spec.rb'
- 'spec/models/ci/runner_spec.rb'
- 'spec/services/users/destroy_service_spec.rb'
# Offense count: 40
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Rails/CreateTableWithTimestamps:
Enabled: false
# Offense count: 115
# Offense count: 149
Rails/FilePath:
Enabled: false
# Offense count: 119
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Enabled: false
# Offense count: 113
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Enabled: false
# Offense count: 48
# Configuration parameters: Include.
# Include: app/controllers/**/*.rb
Rails/LexicallyScopedActionFilter:
Enabled: false
# Offense count: 14
# Cop supports --auto-correct.
Rails/Presence:
Exclude:
- 'app/controllers/projects/blob_controller.rb'
- 'app/models/ci/pipeline.rb'
- 'app/models/clusters/platforms/kubernetes.rb'
- 'app/models/concerns/mentionable.rb'
- 'app/models/concerns/token_authenticatable.rb'
- 'app/models/project_services/hipchat_service.rb'
- 'app/models/project_services/irker_service.rb'
- 'app/models/project_services/jira_service.rb'
- 'app/models/project_services/kubernetes_service.rb'
- 'app/models/project_services/packagist_service.rb'
- 'app/models/wiki_page.rb'
- 'lib/gitlab/git/hook.rb'
- 'lib/gitlab/github_import/importer/releases_importer.rb'
# Offense count: 14
# Cop supports --auto-correct.
Rails/RedundantReceiverInWithOptions:
Exclude:
- 'config/initializers/doorkeeper_openid_connect.rb'
# Offense count: 2
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Rails/ReversibleMigration:
Enabled: false
Exclude:
- 'db/migrate/20160824103857_drop_unused_ci_tables.rb'
# Offense count: 336
# Offense count: 430
# Configuration parameters: Blacklist.
# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
Rails/SkipsModelValidations:
Enabled: false
# Offense count: 11
# Cop supports --auto-correct.
Security/YAMLLoad:
Enabled: false
# Offense count: 1
# Configuration parameters: Environments.
# Environments: development, test, production
Rails/UnknownEnv:
Exclude:
- 'db/migrate/20171124125748_populate_missing_merge_request_statuses.rb'
# Offense count: 58
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Security/YAMLLoad:
Exclude:
- 'config/initializers/carrierwave.rb'
- 'lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb'
- 'lib/gitlab/redis/wrapper.rb'
- 'lib/system_check/incoming_email/imap_authentication_check.rb'
- 'spec/config/mail_room_spec.rb'
- 'spec/initializers/secret_token_spec.rb'
- 'spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb'
- 'spec/models/clusters/platforms/kubernetes_spec.rb'
- 'spec/models/project_services/kubernetes_service_spec.rb'
# Offense count: 63
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: percent_q, bare_percent
Style/BarePercentLiterals:
Enabled: false
# Offense count: 6
# Cop supports --auto-correct.
Style/EachWithObject:
# Offense count: 5
Style/CommentedKeyword:
Exclude:
- 'lib/tasks/gitlab/backup.rake'
- 'spec/tasks/gitlab/backup_rake_spec.rb'
# Offense count: 30
Style/DateTime:
Enabled: false
# Offense count: 31
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/Dir:
Exclude:
- 'qa/qa.rb'
# Offense count: 9
# Cop supports --auto-correct.
Style/EachWithObject:
Exclude:
- 'config/initializers/gollum.rb'
- 'lib/expand_variables.rb'
- 'lib/gitlab/ci/ansi2html.rb'
- 'lib/gitlab/ee_compat_check.rb'
- 'lib/gitlab/hook_data/issuable_builder.rb'
- 'lib/gitlab/i18n/po_linter.rb'
- 'lib/gitlab/import_export/members_mapper.rb'
- 'lib/gitlab/import_export/relation_factory.rb'
- 'scripts/static-analysis'
# Offense count: 24
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty, nil, both
Style/EmptyElse:
Enabled: false
# Offense count: 9
# Offense count: 14
# Cop supports --auto-correct.
Style/EmptyLambdaParameter:
Exclude:
- 'app/models/ci/build.rb'
- 'app/models/ci/runner.rb'
# Offense count: 12
# Cop supports --auto-correct.
Style/EmptyLiteral:
Enabled: false
Exclude:
- 'features/steps/project/commits/commits.rb'
- 'lib/gitlab/fogbugz_import/importer.rb'
- 'lib/gitlab/git/diff_collection.rb'
- 'lib/gitlab/gitaly_client.rb'
- 'scripts/trigger-build-omnibus'
- 'spec/features/merge_requests/versions_spec.rb'
- 'spec/helpers/merge_requests_helper_spec.rb'
- 'spec/lib/gitlab/request_context_spec.rb'
- 'spec/lib/gitlab/workhorse_spec.rb'
- 'spec/requests/api/jobs_spec.rb'
- 'spec/support/chat_slash_commands_shared_examples.rb'
# Offense count: 78
# Offense count: 98
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, expanded
Style/EmptyMethod:
Enabled: false
# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/Encoding:
Enabled: false
# Offense count: 2
Style/EvalWithLocation:
Exclude:
- 'app/models/service.rb'
# Offense count: 52
# Cop supports --auto-correct.
# Configuration parameters: Autocorrect, EnforcedStyle.
# SupportedStyles: module_function, extend_self
Style/ExtendSelf:
Enabled: false
# Offense count: 34
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Enabled: false
# Offense count: 301
# Offense count: 371
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false
# Offense count: 18
# Offense count: 21
Style/IfInsideElse:
Enabled: false
# Offense count: 182
# Offense count: 781
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Enabled: false
# Offense count: 52
# Offense count: 71
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: line_count_dependent, lambda, literal
Style/Lambda:
Enabled: false
# Offense count: 6
# Offense count: 11
# Cop supports --auto-correct.
Style/LineEndConcatenation:
Enabled: false
Exclude:
- 'app/helpers/tree_helper.rb'
- 'spec/features/issuables/markdown_references_spec.rb'
- 'spec/lib/gitlab/checks/project_moved_spec.rb'
- 'spec/lib/gitlab/gfm/reference_rewriter_spec.rb'
- 'spec/lib/gitlab/incoming_email_spec.rb'
# Offense count: 40
# Offense count: 39
# Cop supports --auto-correct.
Style/MethodCallWithoutArgsParentheses:
Enabled: false
# Offense count: 13
# Offense count: 17
Style/MethodMissing:
Enabled: false
# Offense count: 7
Style/MixinUsage:
Exclude:
- 'features/support/env.rb'
- 'spec/factories/ci/builds.rb'
- 'spec/factories/ci/job_artifacts.rb'
- 'spec/factories/lfs_objects.rb'
- 'spec/factories/notes.rb'
- 'spec/lib/gitlab/import_export/project_tree_restorer_spec.rb'
- 'spec/lib/gitlab/import_export/version_checker_spec.rb'
# Offense count: 6
# Cop supports --auto-correct.
Style/MultilineIfModifier:
Enabled: false
Exclude:
- 'app/helpers/snippets_helper.rb'
- 'app/models/project_wiki.rb'
- 'app/services/ci/process_pipeline_service.rb'
- 'app/services/create_deployment_service.rb'
- 'lib/api/commit_statuses.rb'
- 'lib/gitlab/ci/trace.rb'
# Offense count: 26
# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: Whitelist.
# Whitelist: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
Style/NestedParenthesizedCalls:
Enabled: false
# Offense count: 20
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# Configuration parameters: EnforcedStyle, MinBodyLength.
# SupportedStyles: skip_modifier_ifs, always
Style/Next:
Enabled: false
# Offense count: 45
# Offense count: 58
# Cop supports --auto-correct.
# Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles.
# Configuration parameters: EnforcedOctalStyle.
# SupportedOctalStyles: zero_with_o, zero_only
Style/NumericLiteralPrefix:
Enabled: false
# Offense count: 98
# Offense count: 112
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Enabled: false
# Offense count: 42
# Offense count: 4
# Cop supports --auto-correct.
Style/OrAssignment:
Exclude:
- 'app/models/concerns/token_authenticatable.rb'
- 'lib/api/commit_statuses.rb'
- 'lib/api/v3/members.rb'
- 'lib/gitlab/project_transfer.rb'
# Offense count: 50
# Cop supports --auto-correct.
Style/ParallelAssignment:
Enabled: false
# Offense count: 800
# Offense count: 891
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
......@@ -235,106 +650,194 @@ Style/PercentLiteralDelimiters:
# Offense count: 15
# Cop supports --auto-correct.
Style/PerlBackrefs:
Enabled: false
# Offense count: 58
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Exclude:
- 'app/controllers/projects/application_controller.rb'
- 'app/helpers/submodule_helper.rb'
- 'lib/backup/manager.rb'
- 'lib/banzai/filter/abstract_reference_filter.rb'
- 'lib/banzai/filter/autolink_filter.rb'
- 'lib/banzai/filter/emoji_filter.rb'
- 'lib/banzai/filter/gollum_tags_filter.rb'
- 'lib/expand_variables.rb'
- 'lib/gitlab/diff/highlight.rb'
- 'lib/gitlab/search_results.rb'
- 'lib/gitlab/sherlock/query.rb'
# Offense count: 82
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Enabled: false
# Offense count: 6
# Offense count: 8
# Cop supports --auto-correct.
Style/RedundantBegin:
Enabled: false
Exclude:
- 'app/controllers/projects/clusters/gcp_controller.rb'
- 'app/models/merge_request.rb'
- 'app/services/projects/import_service.rb'
- 'lib/api/branches.rb'
- 'lib/gitlab/current_settings.rb'
- 'lib/gitlab/git/commit.rb'
- 'lib/gitlab/health_checks/base_abstract_check.rb'
- 'lib/tasks/gitlab/task_helpers.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantConditional:
Exclude:
- 'lib/system_check/helpers.rb'
# Offense count: 37
# Offense count: 58
# Cop supports --auto-correct.
Style/RedundantFreeze:
Enabled: false
# Offense count: 14
# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Enabled: false
# Offense count: 406
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/concerns/issuable_actions.rb'
- 'app/controllers/groups/application_controller.rb'
- 'app/controllers/omniauth_callbacks_controller.rb'
- 'app/controllers/profiles/keys_controller.rb'
- 'app/controllers/projects/application_controller.rb'
- 'app/services/access_token_validation_service.rb'
- 'lib/gitlab/utils.rb'
- 'lib/google_api/auth.rb'
# Offense count: 454
# Cop supports --auto-correct.
Style/RedundantSelf:
Enabled: false
# Offense count: 115
# Offense count: 140
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Enabled: false
# Offense count: 29
# Offense count: 35
# Cop supports --auto-correct.
Style/RescueModifier:
Enabled: false
# Offense count: 105
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Enabled: false
# Offense count: 91
# Cop supports --auto-correct.
# Configuration parameters: ConvertCodeThatCanStartToReturnNil.
Style/SafeNavigation:
Enabled: false
# Offense count: 8
# Cop supports --auto-correct.
Style/SelfAssignment:
Enabled: false
Exclude:
- 'app/models/concerns/bulk_member_access_load.rb'
- 'app/serializers/base_serializer.rb'
- 'app/services/notification_service.rb'
- 'lib/api/runners.rb'
- 'spec/features/merge_requests/diff_notes_resolve_spec.rb'
- 'spec/features/projects/clusters/interchangeability_spec.rb'
- 'spec/support/import_export/configuration_helper.rb'
# Offense count: 50
# Cop supports --auto-correct.
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Enabled: false
Exclude:
- 'lib/gitlab/ci/ansi2html.rb'
# Offense count: 64
# Offense count: 66
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# Configuration parameters: .
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names
# Offense count: 44
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StderrPuts:
Exclude:
- 'config/initializers/rspec_profiling.rb'
# Offense count: 45
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Enabled: false
# Offense count: 84
# Offense count: 99
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Enabled: false
# Offense count: 8
# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
Enabled: false
Exclude:
- 'app/finders/projects_finder.rb'
- 'app/helpers/namespaces_helper.rb'
- 'features/support/capybara.rb'
- 'lib/api/v3/projects.rb'
- 'lib/gitlab/ci/build/artifacts/metadata/entry.rb'
- 'spec/requests/api/pipeline_schedules_spec.rb'
- 'spec/support/capybara.rb'
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: AllowNamedUnderscoreVariables.
Style/TrailingUnderscoreVariable:
Enabled: false
Exclude:
- 'app/controllers/admin/background_jobs_controller.rb'
- 'app/controllers/invites_controller.rb'
- 'app/helpers/tab_helper.rb'
- 'lib/backup/manager.rb'
- 'lib/gitlab/logger.rb'
- 'lib/gitlab/upgrader.rb'
- 'lib/system_check/app/migrations_are_up_check.rb'
- 'lib/system_check/incoming_email/mail_room_running_check.rb'
- 'lib/tasks/gitlab/check.rake'
- 'lib/tasks/gitlab/task_helpers.rb'
- 'spec/lib/gitlab/etag_caching/middleware_spec.rb'
- 'spec/services/quick_actions/interpret_service_spec.rb'
# Offense count: 4
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
Style/TrivialAccessors:
Enabled: false
Exclude:
- 'app/models/external_issue.rb'
- 'app/serializers/base_serializer.rb'
- 'lib/gitlab/ldap/person.rb'
- 'lib/system_check/base_check.rb'
# Offense count: 5
# Offense count: 4
# Cop supports --auto-correct.
Style/UnlessElse:
Enabled: false
Exclude:
- 'lib/backup/manager.rb'
- 'lib/gitlab/project_search_results.rb'
- 'lib/tasks/gitlab/check.rake'
- 'spec/features/issues/award_emoji_spec.rb'
# Offense count: 28
# Offense count: 30
# Cop supports --auto-correct.
Style/UnneededInterpolation:
Enabled: false
......@@ -342,4 +845,19 @@ Style/UnneededInterpolation:
# Offense count: 11
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Enabled: false
Exclude:
- 'app/models/deploy_key.rb'
- 'app/models/network/commit.rb'
- 'app/models/network/graph.rb'
- 'app/models/project_services/asana_service.rb'
- 'app/services/boards/create_service.rb'
- 'app/services/merge_requests/conflicts/list_service.rb'
- 'lib/declarative_policy/dsl.rb'
- 'lib/extracts_path.rb'
- 'lib/gitlab/git/repository.rb'
# Offense count: 22050
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 1310
......@@ -334,9 +334,11 @@ group :development, :test do
gem 'spring-commands-rspec', '~> 1.0.4'
gem 'spring-commands-spinach', '~> 1.1.0'
gem 'rubocop', '~> 0.49.1', require: false
gem 'rubocop-rspec', '~> 1.15.1', require: false
gem 'rubocop-gitlab-security', '~> 0.1.0', require: false
gem 'gitlab-styles', '~> 2.2.0', require: false
# Pin these dependencies, otherwise a new rule could break the CI pipelines
gem 'rubocop', '~> 0.52.0'
gem 'rubocop-rspec', '~> 1.20.1'
gem 'scss_lint', '~> 0.54.0', require: false
gem 'haml_lint', '~> 0.26.0', require: false
gem 'simplecov', '~> 0.14.0', require: false
......
......@@ -303,6 +303,10 @@ GEM
mime-types (>= 1.16)
posix-spawn (~> 0.3)
gitlab-markup (1.6.3)
gitlab-styles (2.2.0)
rubocop (~> 0.51)
rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.19)
gitlab_omniauth-ldap (2.0.4)
net-ldap (~> 0.16)
omniauth (~> 1.3)
......@@ -777,21 +781,21 @@ GEM
pg
rails
sqlite3
rubocop (0.49.1)
rubocop (0.52.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
parser (>= 2.4.0.2, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-gitlab-security (0.1.0)
rubocop (>= 0.47.1)
rubocop-rspec (1.15.1)
rubocop (>= 0.42.0)
rubocop-gitlab-security (0.1.1)
rubocop (>= 0.51)
rubocop-rspec (1.20.1)
rubocop (>= 0.51.0)
ruby-fogbugz (0.2.1)
crack (~> 0.4)
ruby-prof (0.16.2)
ruby-progressbar (1.8.1)
ruby-progressbar (1.9.0)
ruby-saml (1.4.1)
nokogiri (>= 1.5.10)
ruby_parser (3.9.0)
......@@ -1046,6 +1050,7 @@ DEPENDENCIES
github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2)
gitlab-styles (~> 2.2.0)
gitlab_omniauth-ldap (~> 2.0.4)
gollum-lib (~> 4.2)
gollum-rugged_adapter (~> 0.4.4)
......@@ -1148,9 +1153,8 @@ DEPENDENCIES
rspec-retry (~> 0.4.5)
rspec-set (~> 0.1.3)
rspec_profiling (~> 0.0.5)
rubocop (~> 0.49.1)
rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.15.1)
rubocop (~> 0.52.0)
rubocop-rspec (~> 1.20.1)
ruby-fogbugz (~> 0.2.1)
ruby-prof (~> 0.16.2)
ruby_parser (~> 3.8)
......
......@@ -18,7 +18,7 @@ Peek.into Peek::Views::Rblineprof
Peek.into Peek::Views::GC
Peek.into Peek::Views::Gitaly
# rubocop:disable Style/ClassAndModuleCamelCase
# rubocop:disable Naming/ClassAndModuleCamelCase
class PEEK_DB_CLIENT
class << self
attr_accessor :query_details
......
......@@ -93,9 +93,7 @@ module Gitlab
private
def entries
@entries
end
attr_reader :entries
end
end
end
......
......@@ -56,11 +56,12 @@ module Gitlab
# Do nothing if hooks already exist
unless real_local_hooks_path == File.realpath(global_hooks_path)
if File.exist?(local_hooks_path)
# Move the existing hooks somewhere safe
FileUtils.mv(
local_hooks_path,
"#{local_hooks_path}.old.#{Time.now.to_i}"
) if File.exist?(local_hooks_path)
"#{local_hooks_path}.old.#{Time.now.to_i}")
end
# Create the hooks symlink
FileUtils.ln_sf(global_hooks_path, local_hooks_path)
......
require_relative '../model_helpers'
module RuboCop
module Cop
# Cop that prevents the use of `dependent: ...` in ActiveRecord models.
class ActiveRecordDependent < RuboCop::Cop::Cop
include ModelHelpers
MSG = 'Do not use `dependent: to remove associated data, ' \
'use foreign keys with cascading deletes instead'.freeze
METHOD_NAMES = [:has_many, :has_one, :belongs_to].freeze
def on_send(node)
return unless in_model?(node)
return unless METHOD_NAMES.include?(node.children[1])
node.children.last.each_node(:pair) do |pair|
key_name = pair.children[0].children[0]
add_offense(pair, :expression) if key_name == :dependent
end
end
end
end
end
require_relative '../model_helpers'
module RuboCop
module Cop
# Cop that prevents the use of `serialize` in ActiveRecord models.
class ActiveRecordSerialize < RuboCop::Cop::Cop
include ModelHelpers
MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'.freeze
def on_send(node)
return unless in_model?(node)
add_offense(node, :selector) if node.children[1] == :serialize
end
end
end
end
module RuboCop
module Cop
# This cop makes sure that custom error classes, when empty, are declared
# with Class.new.
#
# @example
# # bad
# class FooError < StandardError
# end
#
# # okish
# class FooError < StandardError; end
#
# # good
# FooError = Class.new(StandardError)
class CustomErrorClass < RuboCop::Cop::Cop
MSG = 'Use `Class.new(SuperClass)` to define an empty custom error class.'.freeze
def on_class(node)
_klass, parent, body = node.children
return if body
parent_klass = class_name_from_node(parent)
return unless parent_klass && parent_klass.to_s.end_with?('Error')
add_offense(node, :expression)
end
def autocorrect(node)
klass, parent, _body = node.children
replacement = "#{class_name_from_node(klass)} = Class.new(#{class_name_from_node(parent)})"
lambda do |corrector|
corrector.replace(node.source_range, replacement)
end
end
private
# The nested constant `Foo::Bar::Baz` looks like:
#
# s(:const,
# s(:const,
# s(:const, nil, :Foo), :Bar), :Baz)
#
# So recurse through that to get the name as written in the source.
#
def class_name_from_node(node, suffix = nil)
return unless node&.type == :const
name = node.children[1].to_s
name = "#{name}::#{suffix}" if suffix
if node.children[0]
class_name_from_node(node.children[0], name)
else
name
end
end
end
end
end
module RuboCop
module Cop
# This cop prevents usage of the `git` and `github` arguments to `gem` in a
# `Gemfile` in order to avoid additional points of failure beyond
# rubygems.org.
class GemFetcher < RuboCop::Cop::Cop
MSG = 'Do not use gems from git repositories, only use gems from RubyGems.'.freeze
GIT_KEYS = [:git, :github].freeze
def on_send(node)
return unless gemfile?(node)
func_name = node.children[1]
return unless func_name == :gem
node.children.last.each_node(:pair) do |pair|
key_name = pair.children[0].children[0].to_sym
if GIT_KEYS.include?(key_name)
add_offense(node, pair.source_range, MSG)
end
end
end
private
def gemfile?(node)
node
.location
.expression
.source_buffer
.name
.end_with?("Gemfile")
end
end
end
end
......@@ -30,12 +30,12 @@ module RuboCop
if only_ivar_or_assignment?(definition)
# We don't allow if any other ivar is used
definition.each_descendant(:ivar) do |offense|
add_offense(offense, :expression)
add_offense(offense, location: :expression)
end
# We allow initialize method and single ivar
elsif !initialize_method?(definition) && !single_ivar?(definition)
definition.each_descendant(:ivar, :ivasgn) do |offense|
add_offense(offense, :expression)
add_offense(offense, location: :expression)
end
end
end
......
require_relative '../model_helpers'
module RuboCop
module Cop
# Cop that prevents the use of `in_batches`
class InBatches < RuboCop::Cop::Cop
MSG = 'Do not use `in_batches`, use `each_batch` from the EachBatch module instead'.freeze
def on_send(node)
return unless node.children[1] == :in_batches
add_offense(node, :selector)
end
end
end
end
......@@ -9,14 +9,14 @@ module RuboCop
MSG = 'Include `ApplicationWorker`, not `Sidekiq::Worker`.'.freeze
def_node_matcher :includes_sidekiq_worker?, <<~PATTERN
(send nil :include (const (const nil :Sidekiq) :Worker))
(send nil? :include (const (const nil? :Sidekiq) :Worker))
PATTERN
def on_send(node)
return if in_spec?(node)
return unless includes_sidekiq_worker?(node)
add_offense(node.arguments.first, :expression)
add_offense(node.arguments.first, location: :expression)
end
def autocorrect(node)
......
# frozen_string_literal: true
module RuboCop
module Cop
# Ensures a line break after guard clauses.
#
# @example
# # bad
# return unless condition
# do_stuff
#
# # good
# return unless condition
#
# do_stuff
#
# # bad
# raise if condition
# do_stuff
#
# # good
# raise if condition
#
# do_stuff
#
# Multiple guard clauses are allowed without
# line break.
#
# # good
# return unless condition_a
# return unless condition_b
#
# do_stuff
#
# Guard clauses in case statement are allowed without
# line break.
#
# # good
# case model
# when condition_a
# return true unless condition_b
# when
# ...
# end
#
# Guard clauses before end are allowed without
# line break.
#
# # good
# if condition_a
# do_something
# else
# do_something_else
# return unless condition
# end
#
# do_something_more
class LineBreakAfterGuardClauses < RuboCop::Cop::Cop
MSG = 'Add a line break after guard clauses'
def_node_matcher :guard_clause_node?, <<-PATTERN
[{(send nil? {:raise :fail :throw} ...) return break next} single_line?]
PATTERN
def on_if(node)
return unless node.single_line?
return unless guard_clause?(node)
return if next_line(node).blank? || clause_last_line?(next_line(node)) || guard_clause?(next_sibling(node))
add_offense(node, :expression, MSG)
end
def autocorrect(node)
lambda do |corrector|
corrector.insert_after(node.loc.expression, "\n")
end
end
private
def guard_clause?(node)
return false unless node.if_type?
guard_clause_node?(node.if_branch)
end
def next_sibling(node)
node.parent.children[node.sibling_index + 1]
end
def next_line(node)
processed_source[node.loc.line]
end
def clause_last_line?(line)
line =~ /^\s*(?:end|elsif|else|when|rescue|ensure)/
end
end
end
end
......@@ -29,7 +29,7 @@ module RuboCop
opts.each_node(:pair) do |pair|
if hash_key_type(pair) == :sym && hash_key_name(pair) == :default
add_offense(node, :selector)
add_offense(node, location: :selector)
end
end
end
......
......@@ -15,7 +15,7 @@ module RuboCop
name = node.children[1]
add_offense(node, :selector) if name == :add_foreign_key
add_offense(node, location: :selector) if name == :add_foreign_key
end
def method_name(node)
......
......@@ -21,7 +21,7 @@ module RuboCop
node.each_ancestor(:def) do |def_node|
next unless method_name(def_node) == :change
add_offense(def_node, :name)
add_offense(def_node, location: :name)
end
end
......
......@@ -27,7 +27,7 @@ module RuboCop
# data in these tables yet.
next if new_tables.include?(first_arg)
add_offense(send_node, :selector)
add_offense(send_node, location: :selector)
end
end
......
......@@ -13,7 +13,7 @@ module RuboCop
def on_send(node)
return unless in_migration?(node)
add_offense(node, :selector) if method_name(node) == :add_timestamps
add_offense(node, location: :selector) if method_name(node) == :add_timestamps
end
def method_name(node)
......
......@@ -17,7 +17,7 @@ module RuboCop
method_name = node.children[1]
if method_name == :datetime || method_name == :timestamp
add_offense(send_node, :selector, format(MSG, method_name))
add_offense(send_node, location: :selector, message: format(MSG, method_name))
end
end
end
......@@ -32,7 +32,7 @@ module RuboCop
last_argument = descendant.children.last
if last_argument == :datetime || last_argument == :timestamp
add_offense(node, :expression, format(MSG, last_argument))
add_offense(node, location: :expression, message: format(MSG, last_argument))
end
end
end
......
......@@ -29,7 +29,7 @@ module RuboCop
hash_key_name(pair) == :using
if hash_key_value(pair).to_s == 'hash'
add_offense(pair, :expression)
add_offense(pair, location: :expression)
end
end
end
......
......@@ -20,7 +20,7 @@ module RuboCop
send_method = send_node.children[1]
if send_method == :remove_column
add_offense(send_node, :selector)
add_offense(send_node, location: :selector)
end
end
end
......
......@@ -16,7 +16,7 @@ module RuboCop
return unless node.children[1] == :remove_concurrent_index
node.each_ancestor(:def) do |def_node|
add_offense(def_node, :name) if method_name(def_node) == :change
add_offense(def_node, location: :name) if method_name(def_node) == :change
end
end
......
......@@ -13,7 +13,7 @@ module RuboCop
return unless in_migration?(node)
node.each_descendant(:send) do |send_node|
add_offense(send_node, :selector) if method_name(send_node) == :remove_index
add_offense(send_node, location: :selector) if method_name(send_node) == :remove_index
end
end
......
......@@ -9,7 +9,7 @@ module RuboCop
include MigrationHelpers
def_node_matcher :add_column_with_default?, <<~PATTERN
(send nil :add_column_with_default $...)
(send nil? :add_column_with_default $...)
PATTERN
def_node_matcher :defines_change?, <<~PATTERN
......@@ -26,7 +26,7 @@ module RuboCop
node.each_ancestor(:def) do |def_node|
next unless defines_change?(def_node)
add_offense(def_node, :name)
add_offense(def_node, location: :name)
end
end
end
......
......@@ -28,7 +28,7 @@ module RuboCop
].freeze
def_node_matcher :add_column?, <<~PATTERN
(send nil :add_column $...)
(send nil? :add_column $...)
PATTERN
def on_send(node)
......@@ -54,7 +54,7 @@ module RuboCop
NULL_OFFENSE
end
add_offense(node, :expression, format(offense, table)) if offense
add_offense(node, location: :expression, message: format(offense, table)) if offense
end
def no_default?(opts)
......
......@@ -14,7 +14,7 @@ module RuboCop
return unless in_migration?(node)
node.each_descendant(:send) do |send_node|
add_offense(send_node, :selector) if method_name(send_node) == :timestamps
add_offense(send_node, location: :selector) if method_name(send_node) == :timestamps
end
end
......
......@@ -18,7 +18,7 @@ module RuboCop
spec_path = spec_filename(node)
unless File.exist?(File.expand_path(spec_path, rails_root))
add_offense(node, :expression, format(MSG, spec_path))
add_offense(node, location: :expression, message: format(MSG, spec_path))
end
end
......
......@@ -35,7 +35,7 @@ module RuboCop
].freeze
def_node_matcher :batch_update?, <<~PATTERN
(send nil ${:add_column_with_default :update_column_in_batches} $(sym ...) ...)
(send nil? ${:add_column_with_default :update_column_in_batches} $(sym ...) ...)
PATTERN
def on_send(node)
......@@ -49,7 +49,7 @@ module RuboCop
return unless LARGE_TABLES.include?(table)
add_offense(node, :expression, format(MSG, update_method, table))
add_offense(node, location: :expression, message: format(MSG, update_method, table))
end
end
end
......
require_relative '../model_helpers'
module RuboCop
module Cop
# Cop that prevents the use of polymorphic associations
class PolymorphicAssociations < RuboCop::Cop::Cop
include ModelHelpers
MSG = 'Do not use polymorphic associations, use separate tables instead'.freeze
def on_send(node)
return unless in_model?(node)
return unless node.children[1] == :belongs_to
node.children.last.each_node(:pair) do |pair|
key_name = pair.children[0].children[0]
add_offense(pair, :expression) if key_name == :polymorphic
end
end
end
end
end
......@@ -17,7 +17,7 @@ module RuboCop
return unless method_name(namespace_expr) == :namespace
return unless receiver(namespace_expr) == project_expr
add_offense(node, :selector)
add_offense(node, location: :selector)
end
def autocorrect(node)
......
module RuboCop
module Cop
# This cop prevents usage of 'redirect_to' in actions 'destroy' without specifying 'status'.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/31840
class RedirectWithStatus < RuboCop::Cop::Cop
MSG = 'Do not use "redirect_to" without "status" in "destroy" action'.freeze
def on_def(node)
return unless in_controller?(node)
return unless destroy?(node) || destroy_all?(node)
node.each_descendant(:send) do |def_node|
next unless redirect_to?(def_node)
methods = []
def_node.children.last.each_node(:pair) do |pair|
methods << pair.children.first.children.first
end
add_offense(def_node, :selector) unless methods.include?(:status)
end
end
private
def in_controller?(node)
node.location.expression.source_buffer.name.end_with?('_controller.rb')
end
def destroy?(node)
node.children.first == :destroy
end
def destroy_all?(node)
node.children.first == :destroy_all
end
def redirect_to?(node)
node.children[1] == :redirect_to
end
end
end
end
require 'rubocop-rspec'
require_relative '../../spec_helpers'
module RuboCop
......@@ -17,7 +16,7 @@ module RuboCop
# before do
# stub_env('FOO', 'bar')
# end
class EnvAssignment < Cop
class EnvAssignment < RuboCop::Cop::Cop
include SpecHelpers
MESSAGE = "Don't assign to ENV, use `stub_env` instead.".freeze
......@@ -32,7 +31,7 @@ module RuboCop
return unless in_spec?(node)
return unless env_assignment?(node)
add_offense(node, :expression, MESSAGE)
add_offense(node, location: :expression, message: MESSAGE)
end
def autocorrect(node)
......
require 'rubocop-rspec'
module RuboCop
module Cop
module RSpec
# This cop checks for single-line hook blocks
#
# @example
#
# # bad
# before { do_something }
# after(:each) { undo_something }
#
# # good
# before do
# do_something
# end
#
# after(:each) do
# undo_something
# end
class SingleLineHook < Cop
MESSAGE = "Don't use single-line hook blocks.".freeze
def_node_search :rspec_hook?, <<~PATTERN
(send nil {:after :around :before} ...)
PATTERN
def on_block(node)
return unless rspec_hook?(node)
return unless node.single_line?
add_offense(node, :expression, MESSAGE)
end
end
end
end
end
# frozen_string_literal: true
require 'rubocop-rspec'
module RuboCop
module Cop
module RSpec
# Checks for verbose include metadata used in the specs.
#
# @example
# # bad
# describe MyClass, js: true do
# end
#
# # good
# describe MyClass, :js do
# end
class VerboseIncludeMetadata < Cop
MSG = 'Use `%s` instead of `%s`.'
SELECTORS = %i[describe context feature example_group it specify example scenario its].freeze
def_node_matcher :include_metadata, <<-PATTERN
(send {(const nil :RSpec) nil} {#{SELECTORS.map(&:inspect).join(' ')}}
!const
...
(hash $...))
PATTERN
def_node_matcher :invalid_metadata?, <<-PATTERN
(pair
(sym $...)
(true))
PATTERN
def on_send(node)
invalid_metadata_matches(node) do |match|
add_offense(node, :expression, format(MSG, good(match), bad(match)))
end
end
def autocorrect(node)
lambda do |corrector|
invalid_metadata_matches(node) do |match|
corrector.replace(match.loc.expression, good(match))
end
end
end
private
def invalid_metadata_matches(node)
include_metadata(node) do |matches|
matches.select(&method(:invalid_metadata?)).each do |match|
yield match
end
end
end
def bad(match)
"#{metadata_key(match)}: true"
end
def good(match)
":#{metadata_key(match)}"
end
def metadata_key(match)
match.children[0].source
end
end
end
end
end
......@@ -9,7 +9,7 @@ module RuboCop
MSG = 'Do not manually set a queue; `ApplicationWorker` sets one automatically.'.freeze
def_node_matcher :sidekiq_options?, <<~PATTERN
(send nil :sidekiq_options $...)
(send nil? :sidekiq_options $...)
PATTERN
def on_send(node)
......@@ -19,7 +19,7 @@ module RuboCop
node.arguments.first.each_node(:pair) do |pair|
key_name = pair.key.children[0]
add_offense(pair, :expression) if key_name == :queue
add_offense(pair, location: :expression) if key_name == :queue
end
end
end
......
module RuboCop
module ModelHelpers
# Returns true if the given node originated from the models directory.
def in_model?(node)
path = node.location.expression.source_buffer.name
models_path = File.join(Dir.pwd, 'app', 'models')
path.start_with?(models_path)
end
end
end
require_relative 'cop/active_record_dependent'
require_relative 'cop/active_record_serialize'
require_relative 'cop/custom_error_class'
require_relative 'cop/gem_fetcher'
require_relative 'cop/in_batches'
require_relative 'cop/include_sidekiq_worker'
require_relative 'cop/line_break_after_guard_clauses'
require_relative 'cop/polymorphic_associations'
require_relative 'cop/project_path_helper'
require_relative 'cop/redirect_with_status'
require_relative 'cop/gitlab/module_with_instance_variables'
require_relative 'cop/sidekiq_options_queue'
require_relative 'cop/include_sidekiq_worker'
require_relative 'cop/migration/add_column'
require_relative 'cop/migration/add_concurrent_foreign_key'
require_relative 'cop/migration/add_concurrent_index'
......@@ -25,6 +16,8 @@ require_relative 'cop/migration/safer_boolean_column'
require_relative 'cop/migration/timestamps'
require_relative 'cop/migration/update_column_in_batches'
require_relative 'cop/migration/update_large_table'
require_relative 'cop/project_path_helper'
require_relative 'cop/rspec/env_assignment'
require_relative 'cop/rspec/single_line_hook'
require_relative 'cop/rspec/verbose_include_metadata'
require_relative 'cop/sidekiq_options_queue'
......@@ -14,6 +14,7 @@ FactoryBot.define do
trait :closed do
state :closed
closed_at { Time.now }
end
factory :closed_issue, traits: [:closed]
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/active_record_dependent'
describe RuboCop::Cop::ActiveRecordDependent do
include CopHelper
subject(:cop) { described_class.new }
context 'inside the app/models directory' do
it 'registers an offense when dependent: is used' do
allow(cop).to receive(:in_model?).and_return(true)
inspect_source(cop, 'belongs_to :foo, dependent: :destroy')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
end
context 'outside the app/models directory' do
it 'does nothing' do
allow(cop).to receive(:in_model?).and_return(false)
inspect_source(cop, 'belongs_to :foo, dependent: :destroy')
expect(cop.offenses).to be_empty
end
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/active_record_serialize'
describe RuboCop::Cop::ActiveRecordSerialize do
include CopHelper
subject(:cop) { described_class.new }
context 'inside the app/models directory' do
it 'registers an offense when serialize is used' do
allow(cop).to receive(:in_model?).and_return(true)
inspect_source(cop, 'serialize :foo')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
end
context 'outside the app/models directory' do
it 'does nothing' do
allow(cop).to receive(:in_model?).and_return(false)
inspect_source(cop, 'serialize :foo')
expect(cop.offenses).to be_empty
end
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/custom_error_class'
describe RuboCop::Cop::CustomErrorClass do
include CopHelper
subject(:cop) { described_class.new }
context 'when a class has a body' do
it 'does nothing' do
inspect_source(cop, 'class CustomError < StandardError; def foo; end; end')
expect(cop.offenses).to be_empty
end
end
context 'when a class has no explicit superclass' do
it 'does nothing' do
inspect_source(cop, 'class CustomError; end')
expect(cop.offenses).to be_empty
end
end
context 'when a class has a superclass that does not end in Error' do
it 'does nothing' do
inspect_source(cop, 'class CustomError < BasicObject; end')
expect(cop.offenses).to be_empty
end
end
context 'when a class is empty and inherits from a class ending in Error' do
context 'when the class is on a single line' do
let(:source) do
<<-SOURCE
module Foo
class CustomError < Bar::Baz::BaseError; end
end
SOURCE
end
let(:expected) do
<<-EXPECTED
module Foo
CustomError = Class.new(Bar::Baz::BaseError)
end
EXPECTED
end
it 'registers an offense' do
expected_highlights = source.split("\n")[1].strip
inspect_source(cop, source)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([2])
expect(cop.highlights).to contain_exactly(expected_highlights)
end
end
it 'autocorrects to the right version' do
autocorrected = autocorrect_source(cop, source, 'foo/custom_error.rb')
expect(autocorrected).to eq(expected)
end
end
context 'when the class is on multiple lines' do
let(:source) do
<<-SOURCE
module Foo
class CustomError < Bar::Baz::BaseError
end
end
SOURCE
end
let(:expected) do
<<-EXPECTED
module Foo
CustomError = Class.new(Bar::Baz::BaseError)
end
EXPECTED
end
it 'registers an offense' do
expected_highlights = source.split("\n")[1..2].join("\n").strip
inspect_source(cop, source)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([2])
expect(cop.highlights).to contain_exactly(expected_highlights)
end
end
it 'autocorrects to the right version' do
autocorrected = autocorrect_source(cop, source, 'foo/custom_error.rb')
expect(autocorrected).to eq(expected)
end
end
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/gem_fetcher'
describe RuboCop::Cop::GemFetcher do
include CopHelper
subject(:cop) { described_class.new }
context 'in Gemfile' do
before do
allow(cop).to receive(:gemfile?).and_return(true)
end
it 'registers an offense when a gem uses `git`' do
inspect_source(cop, 'gem "foo", git: "https://gitlab.com/foo/bar.git"')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq(['git: "https://gitlab.com/foo/bar.git"'])
end
end
it 'registers an offense when a gem uses `github`' do
inspect_source(cop, 'gem "foo", github: "foo/bar.git"')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq(['github: "foo/bar.git"'])
end
end
end
context 'outside of Gemfile' do
it 'registers no offense' do
inspect_source(cop, 'gem "foo", git: "https://gitlab.com/foo/bar.git"')
expect(cop.offenses.size).to eq(0)
end
end
end
......@@ -12,7 +12,7 @@ describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do
let(:offending_lines) { options[:offending_lines] }
it 'registers an offense when instance variable is used in a module' do
inspect_source(cop, source)
inspect_source(source)
aggregate_failures do
expect(cop.offenses.size).to eq(offending_lines.size)
......@@ -23,7 +23,7 @@ describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do
shared_examples('not registering offense') do
it 'does not register offenses' do
inspect_source(cop, source)
inspect_source(source)
expect(cop.offenses).to be_empty
end
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/in_batches'
describe RuboCop::Cop::InBatches do
include CopHelper
subject(:cop) { described_class.new }
it 'registers an offense when in_batches is used' do
inspect_source(cop, 'foo.in_batches do; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/include_sidekiq_worker'
describe RuboCop::Cop::IncludeSidekiqWorker do
......@@ -13,7 +15,7 @@ describe RuboCop::Cop::IncludeSidekiqWorker do
let(:correct_source) { 'include ApplicationWorker' }
it 'registers an offense ' do
inspect_source(cop, source)
inspect_source(source)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -23,7 +25,7 @@ describe RuboCop::Cop::IncludeSidekiqWorker do
end
it 'autocorrects to the right version' do
autocorrected = autocorrect_source(cop, source)
autocorrected = autocorrect_source(source)
expect(autocorrected).to eq(correct_source)
end
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/line_break_after_guard_clauses'
describe RuboCop::Cop::LineBreakAfterGuardClauses do
include CopHelper
subject(:cop) { described_class.new }
shared_examples 'examples with guard clause' do |title|
%w[if unless].each do |conditional|
it "flags violation for #{title} #{conditional} without line breaks" do
source = <<~RUBY
#{title} #{conditional} condition
do_stuff
RUBY
inspect_source(cop, source)
expect(cop.offenses.size).to eq(1)
offense = cop.offenses.first
expect(offense.line).to eq(1)
expect(cop.highlights).to eq(["#{title} #{conditional} condition"])
expect(offense.message).to eq('Add a line break after guard clauses')
end
it "doesn't flag violation for #{title} #{conditional} with line break" do
source = <<~RUBY
#{title} #{conditional} condition
do_stuff
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} on multiple lines without line break" do
source = <<~RUBY
#{conditional} condition
#{title}
end
do_stuff
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by end keyword" do
source = <<~RUBY
def test
#{title} #{conditional} condition
end
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by elsif keyword" do
source = <<~RUBY
if model
#{title} #{conditional} condition
elsif
do_something
end
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by else keyword" do
source = <<~RUBY
if model
#{title} #{conditional} condition
else
do_something
end
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by when keyword" do
source = <<~RUBY
case model
when condition_a
#{title} #{conditional} condition
when condition_b
do_something
end
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by rescue keyword" do
source = <<~RUBY
begin
#{title} #{conditional} condition
rescue StandardError
do_something
end
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by ensure keyword" do
source = <<~RUBY
def foo
#{title} #{conditional} condition
ensure
do_something
end
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by another guard clause" do
source = <<~RUBY
#{title} #{conditional} condition
#{title} #{conditional} condition
do_stuff
RUBY
inspect_source(cop, source)
expect(cop.offenses).to be_empty
end
it "autocorrects #{title} #{conditional} guard clauses without line break" do
source = <<~RUBY
#{title} #{conditional} condition
do_stuff
RUBY
autocorrected = autocorrect_source(cop, source)
expected_source = <<~RUBY
#{title} #{conditional} condition
do_stuff
RUBY
expect(autocorrected).to eql(expected_source)
end
end
end
%w[return fail raise next break throw].each do |example|
it_behaves_like 'examples with guard clause', example
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/migration/add_concurrent_foreign_key'
describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
......@@ -10,7 +12,7 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
context 'outside of a migration' do
it 'does not register any offenses' do
inspect_source(cop, 'def up; add_foreign_key(:projects, :users, column: :user_id); end')
inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
expect(cop.offenses).to be_empty
end
......@@ -22,7 +24,7 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
end
it 'registers an offense when using add_foreign_key' do
inspect_source(cop, 'def up; add_foreign_key(:projects, :users, column: :user_id); end')
inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......
......@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do
end
it 'registers an offense when add_concurrent_index is used inside a change method' do
inspect_source(cop, 'def change; add_concurrent_index :table, :column; end')
inspect_source('def change; add_concurrent_index :table, :column; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do
end
it 'registers no offense when add_concurrent_index is used inside an up method' do
inspect_source(cop, 'def up; add_concurrent_index :table, :column; end')
inspect_source('def up; add_concurrent_index :table, :column; end')
expect(cop.offenses.size).to eq(0)
end
......@@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, 'def change; add_concurrent_index :table, :column; end')
inspect_source('def change; add_concurrent_index :table, :column; end')
expect(cop.offenses.size).to eq(0)
end
......
......@@ -53,7 +53,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
end
it 'registers an offense when the "add_timestamps" method is used' do
inspect_source(cop, migration_with_add_timestamps)
inspect_source(migration_with_add_timestamps)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
end
it 'does not register an offense when the "add_timestamps" method is not used' do
inspect_source(cop, migration_without_add_timestamps)
inspect_source(migration_without_add_timestamps)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
......@@ -70,7 +70,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
end
it 'does not register an offense when the "add_timestamps_with_timezone" method is used' do
inspect_source(cop, migration_with_add_timestamps_with_timezone)
inspect_source(migration_with_add_timestamps_with_timezone)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
......@@ -80,9 +80,9 @@ describe RuboCop::Cop::Migration::AddTimestamps do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, migration_with_add_timestamps)
inspect_source(cop, migration_without_add_timestamps)
inspect_source(cop, migration_with_add_timestamps_with_timezone)
inspect_source(migration_with_add_timestamps)
inspect_source(migration_without_add_timestamps)
inspect_source(migration_with_add_timestamps_with_timezone)
expect(cop.offenses.size).to eq(0)
end
......
......@@ -67,7 +67,7 @@ describe RuboCop::Cop::Migration::Datetime do
end
it 'registers an offense when the ":datetime" data type is used' do
inspect_source(cop, migration_with_datetime)
inspect_source(migration_with_datetime)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -77,7 +77,7 @@ describe RuboCop::Cop::Migration::Datetime do
end
it 'registers an offense when the ":timestamp" data type is used' do
inspect_source(cop, migration_with_timestamp)
inspect_source(migration_with_timestamp)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -87,7 +87,7 @@ describe RuboCop::Cop::Migration::Datetime do
end
it 'does not register an offense when the ":datetime" data type is not used' do
inspect_source(cop, migration_without_datetime)
inspect_source(migration_without_datetime)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
......@@ -95,7 +95,7 @@ describe RuboCop::Cop::Migration::Datetime do
end
it 'does not register an offense when the ":datetime_with_timezone" data type is used' do
inspect_source(cop, migration_with_datetime_with_timezone)
inspect_source(migration_with_datetime_with_timezone)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
......@@ -105,10 +105,10 @@ describe RuboCop::Cop::Migration::Datetime do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, migration_with_datetime)
inspect_source(cop, migration_with_timestamp)
inspect_source(cop, migration_without_datetime)
inspect_source(cop, migration_with_datetime_with_timezone)
inspect_source(migration_with_datetime)
inspect_source(migration_with_timestamp)
inspect_source(migration_without_datetime)
inspect_source(migration_with_datetime_with_timezone)
expect(cop.offenses.size).to eq(0)
end
......
......@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::HashIndex do
end
it 'registers an offense when creating a hash index' do
inspect_source(cop, 'def change; add_index :table, :column, using: :hash; end')
inspect_source('def change; add_index :table, :column, using: :hash; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::HashIndex do
end
it 'registers an offense when creating a concurrent hash index' do
inspect_source(cop, 'def change; add_concurrent_index :table, :column, using: :hash; end')
inspect_source('def change; add_concurrent_index :table, :column, using: :hash; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -34,7 +34,7 @@ describe RuboCop::Cop::Migration::HashIndex do
end
it 'registers an offense when creating a hash index using t.index' do
inspect_source(cop, 'def change; t.index :table, :column, using: :hash; end')
inspect_source('def change; t.index :table, :column, using: :hash; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -45,7 +45,7 @@ describe RuboCop::Cop::Migration::HashIndex do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, 'def change; index :table, :column, using: :hash; end')
inspect_source('def change; index :table, :column, using: :hash; end')
expect(cop.offenses.size).to eq(0)
end
......
......@@ -21,7 +21,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
end
it 'registers an offense when remove_column is used in the change method' do
inspect_source(cop, source('change'))
inspect_source(source('change'))
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -30,7 +30,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
end
it 'registers an offense when remove_column is used in the up method' do
inspect_source(cop, source('up'))
inspect_source(source('up'))
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -39,7 +39,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
end
it 'registers no offense when remove_column is used in the down method' do
inspect_source(cop, source('down'))
inspect_source(source('down'))
expect(cop.offenses.size).to eq(0)
end
......@@ -52,7 +52,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
end
it 'registers no offense' do
inspect_source(cop, source)
inspect_source(source)
expect(cop.offenses.size).to eq(0)
end
......@@ -60,7 +60,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
context 'outside of a migration' do
it 'registers no offense' do
inspect_source(cop, source)
inspect_source(source)
expect(cop.offenses.size).to eq(0)
end
......
......@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
end
it 'registers an offense when remove_concurrent_index is used inside a change method' do
inspect_source(cop, 'def change; remove_concurrent_index :table, :column; end')
inspect_source('def change; remove_concurrent_index :table, :column; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
end
it 'registers no offense when remove_concurrent_index is used inside an up method' do
inspect_source(cop, 'def up; remove_concurrent_index :table, :column; end')
inspect_source('def up; remove_concurrent_index :table, :column; end')
expect(cop.offenses.size).to eq(0)
end
......@@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, 'def change; remove_concurrent_index :table, :column; end')
inspect_source('def change; remove_concurrent_index :table, :column; end')
expect(cop.offenses.size).to eq(0)
end
......
......@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::RemoveIndex do
end
it 'registers an offense when remove_index is used' do
inspect_source(cop, 'def change; remove_index :table, :column; end')
inspect_source('def change; remove_index :table, :column; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -27,7 +27,7 @@ describe RuboCop::Cop::Migration::RemoveIndex do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, 'def change; remove_index :table, :column; end')
inspect_source('def change; remove_index :table, :column; end')
expect(cop.offenses.size).to eq(0)
end
......
......@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do
end
it 'registers an offense when add_column_with_default is used inside a change method' do
inspect_source(cop, 'def change; add_column_with_default :table, :column, default: false; end')
inspect_source('def change; add_column_with_default :table, :column, default: false; end')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do
end
it 'registers no offense when add_column_with_default is used inside an up method' do
inspect_source(cop, 'def up; add_column_with_default :table, :column, default: false; end')
inspect_source('def up; add_column_with_default :table, :column, default: false; end')
expect(cop.offenses.size).to eq(0)
end
......@@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, 'def change; add_column_with_default :table, :column, default: false; end')
inspect_source('def change; add_column_with_default :table, :column, default: false; end')
expect(cop.offenses.size).to eq(0)
end
......
......@@ -32,7 +32,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
sources_and_offense.each do |source, offense|
context "given the source \"#{source}\"" do
it "registers the offense matching \"#{offense}\"" do
inspect_source(cop, source)
inspect_source(source)
aggregate_failures do
expect(cop.offenses.first.message).to match(offense)
......@@ -49,7 +49,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
inoffensive_sources.each do |source|
context "given the source \"#{source}\"" do
it "registers no offense" do
inspect_source(cop, source)
inspect_source(source)
aggregate_failures do
expect(cop.offenses).to be_empty
......@@ -61,14 +61,14 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
end
it 'registers no offense for tables not listed in SMALL_TABLES' do
inspect_source(cop, "add_column :large_table, :column, :boolean")
inspect_source("add_column :large_table, :column, :boolean")
expect(cop.offenses).to be_empty
end
it 'registers no offense for non-boolean columns' do
table = described_class::SMALL_TABLES.sample
inspect_source(cop, "add_column :#{table}, :column, :string")
inspect_source("add_column :#{table}, :column, :string")
expect(cop.offenses).to be_empty
end
......@@ -77,7 +77,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
context 'outside of migration' do
it 'registers no offense' do
table = described_class::SMALL_TABLES.sample
inspect_source(cop, "add_column :#{table}, :column, :boolean")
inspect_source("add_column :#{table}, :column, :boolean")
expect(cop.offenses).to be_empty
end
......
......@@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::Timestamps do
end
it 'registers an offense when the "timestamps" method is used' do
inspect_source(cop, migration_with_timestamps)
inspect_source(migration_with_timestamps)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -71,7 +71,7 @@ describe RuboCop::Cop::Migration::Timestamps do
end
it 'does not register an offense when the "timestamps" method is not used' do
inspect_source(cop, migration_without_timestamps)
inspect_source(migration_without_timestamps)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
......@@ -79,7 +79,7 @@ describe RuboCop::Cop::Migration::Timestamps do
end
it 'does not register an offense when the "timestamps_with_timezone" method is used' do
inspect_source(cop, migration_with_timestamps_with_timezone)
inspect_source(migration_with_timestamps_with_timezone)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
......@@ -89,9 +89,9 @@ describe RuboCop::Cop::Migration::Timestamps do
context 'outside of migration' do
it 'registers no offense' do
inspect_source(cop, migration_with_timestamps)
inspect_source(cop, migration_without_timestamps)
inspect_source(cop, migration_with_timestamps_with_timezone)
inspect_source(migration_with_timestamps)
inspect_source(migration_without_timestamps)
inspect_source(migration_with_timestamps_with_timezone)
expect(cop.offenses.size).to eq(0)
end
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/migration/update_column_in_batches'
describe RuboCop::Cop::Migration::UpdateColumnInBatches do
......@@ -25,7 +27,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do
context 'outside of a migration' do
it 'does not register any offenses' do
inspect_source(cop, migration_code)
inspect_source(migration_code)
expect(cop.offenses).to be_empty
end
......@@ -49,7 +51,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do
let(:relative_spec_filepath) { Pathname.new(spec_filepath).relative_path_from(tmp_rails_root) }
it 'registers an offense when using update_column_in_batches' do
inspect_source(cop, migration_code, @migration_file)
inspect_source(migration_code, @migration_file)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -72,7 +74,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do
end
it 'does not register any offenses' do
inspect_source(cop, migration_code, @migration_file)
inspect_source(migration_code, @migration_file)
expect(cop.offenses).to be_empty
end
......
......@@ -18,7 +18,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
shared_examples 'large tables' do |update_method|
described_class::LARGE_TABLES.each do |table|
it "registers an offense for the #{table} table" do
inspect_source(cop, "#{update_method} :#{table}, :column, default: true")
inspect_source("#{update_method} :#{table}, :column, default: true")
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -37,7 +37,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
end
it 'registers no offense for non-blacklisted tables' do
inspect_source(cop, "add_column_with_default :table, :column, default: true")
inspect_source("add_column_with_default :table, :column, default: true")
expect(cop.offenses).to be_empty
end
......@@ -45,7 +45,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
it 'registers no offense for non-blacklisted methods' do
table = described_class::LARGE_TABLES.sample
inspect_source(cop, "some_other_method :#{table}, :column, default: true")
inspect_source("some_other_method :#{table}, :column, default: true")
expect(cop.offenses).to be_empty
end
......@@ -55,13 +55,13 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
let(:table) { described_class::LARGE_TABLES.sample }
it 'registers no offense for add_column_with_default' do
inspect_source(cop, "add_column_with_default :#{table}, :column, default: true")
inspect_source("add_column_with_default :#{table}, :column, default: true")
expect(cop.offenses).to be_empty
end
it 'registers no offense for update_column_in_batches' do
inspect_source(cop, "add_column_with_default :#{table}, :column, default: true")
inspect_source("add_column_with_default :#{table}, :column, default: true")
expect(cop.offenses).to be_empty
end
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/polymorphic_associations'
describe RuboCop::Cop::PolymorphicAssociations do
include CopHelper
subject(:cop) { described_class.new }
context 'inside the app/models directory' do
it 'registers an offense when polymorphic: true is used' do
allow(cop).to receive(:in_model?).and_return(true)
inspect_source(cop, 'belongs_to :foo, polymorphic: true')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
end
context 'outside the app/models directory' do
it 'does nothing' do
allow(cop).to receive(:in_model?).and_return(false)
inspect_source(cop, 'belongs_to :foo, polymorphic: true')
expect(cop.offenses).to be_empty
end
end
end
......@@ -15,7 +15,7 @@ describe RuboCop::Cop::ProjectPathHelper do
let(:correct_source) { 'edit_project_issue_path(@issue.project, @issue)' }
it 'registers an offense' do
inspect_source(cop, source)
inspect_source(source)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -25,7 +25,7 @@ describe RuboCop::Cop::ProjectPathHelper do
end
it 'autocorrects to the right version' do
autocorrected = autocorrect_source(cop, source)
autocorrected = autocorrect_source(source)
expect(autocorrected).to eq(correct_source)
end
......@@ -33,7 +33,7 @@ describe RuboCop::Cop::ProjectPathHelper do
context 'when using namespace_project with a different namespace' do
it 'registers no offense' do
inspect_source(cop, 'edit_namespace_project_issue_path(namespace, project)')
inspect_source('edit_namespace_project_issue_path(namespace, project)')
expect(cop.offenses.size).to eq(0)
end
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/redirect_with_status'
describe RuboCop::Cop::RedirectWithStatus do
include CopHelper
subject(:cop) { described_class.new }
let(:controller_fixture_without_status) do
%q(
class UserController < ApplicationController
def show
user = User.find(params[:id])
redirect_to user_path if user.name == 'John Wick'
end
def destroy
user = User.find(params[:id])
if user.destroy
redirect_to root_path
else
render :show
end
end
end
)
end
let(:controller_fixture_with_status) do
%q(
class UserController < ApplicationController
def show
user = User.find(params[:id])
redirect_to user_path if user.name == 'John Wick'
end
def destroy
user = User.find(params[:id])
if user.destroy
redirect_to root_path, status: 302
else
render :show
end
end
end
)
end
context 'in controller' do
before do
allow(cop).to receive(:in_controller?).and_return(true)
end
it 'registers an offense when a "destroy" action uses "redirect_to" without "status"' do
inspect_source(cop, controller_fixture_without_status)
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([12]) # 'redirect_to' is located on 12th line in controller_fixture.
expect(cop.highlights).to eq(['redirect_to'])
end
end
it 'does not register an offense when a "destroy" action uses "redirect_to" with "status"' do
inspect_source(cop, controller_fixture_with_status)
aggregate_failures do
expect(cop.offenses.size).to eq(0)
end
end
end
context 'outside of controller' do
it 'registers no offense' do
inspect_source(cop, controller_fixture_without_status)
inspect_source(cop, controller_fixture_with_status)
expect(cop.offenses.size).to eq(0)
end
end
end
......@@ -17,7 +17,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
shared_examples 'an offensive ENV#[]= call' do |content|
it "registers an offense for `#{content}`" do
inspect_source(cop, content, source_file)
inspect_source(content, source_file)
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
......@@ -27,7 +27,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
shared_examples 'an autocorrected ENV#[]= call' do |content, autocorrected_content|
it "registers an offense for `#{content}` and autocorrects it to `#{autocorrected_content}`" do
autocorrected = autocorrect_source(cop, content, source_file)
autocorrected = autocorrect_source(content, source_file)
expect(autocorrected).to eql(autocorrected_content)
end
......@@ -51,7 +51,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
context 'outside of a spec file' do
it "does not register an offense for `#{OFFENSE_CALL_SINGLE_QUOTES_KEY}` in a non-spec file" do
inspect_source(cop, OFFENSE_CALL_SINGLE_QUOTES_KEY)
inspect_source(OFFENSE_CALL_SINGLE_QUOTES_KEY)
expect(cop.offenses.size).to eq(0)
end
......
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/rspec/single_line_hook'
describe RuboCop::Cop::RSpec::SingleLineHook do
include CopHelper
subject(:cop) { described_class.new }
# Override `CopHelper#inspect_source` to always appear to be in a spec file,
# so that our RSpec-only cop actually runs
def inspect_source(*args)
super(*args, 'foo_spec.rb')
end
it 'registers an offense for a single-line `before` block' do
inspect_source(cop, 'before { do_something }')
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq(['before { do_something }'])
end
it 'registers an offense for a single-line `after` block' do
inspect_source(cop, 'after(:each) { undo_something }')
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq(['after(:each) { undo_something }'])
end
it 'registers an offense for a single-line `around` block' do
inspect_source(cop, 'around { |ex| do_something_else }')
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq(['around { |ex| do_something_else }'])
end
it 'ignores a multi-line `before` block' do
inspect_source(cop, ['before do',
' do_something',
'end'])
expect(cop.offenses.size).to eq(0)
end
it 'ignores a multi-line `after` block' do
inspect_source(cop, ['after(:each) do',
' undo_something',
'end'])
expect(cop.offenses.size).to eq(0)
end
it 'ignores a multi-line `around` block' do
inspect_source(cop, ['around do |ex|',
' do_something_else',
'end'])
expect(cop.offenses.size).to eq(0)
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/rspec/verbose_include_metadata'
describe RuboCop::Cop::RSpec::VerboseIncludeMetadata do
include CopHelper
subject(:cop) { described_class.new }
let(:source_file) { 'foo_spec.rb' }
# Override `CopHelper#inspect_source` to always appear to be in a spec file,
# so that our RSpec-only cop actually runs
def inspect_source(*args)
super(*args, source_file)
end
shared_examples 'examples with include syntax' do |title|
it "flags violation for #{title} examples that uses verbose include syntax" do
inspect_source(cop, "#{title} 'Test', js: true do; end")
expect(cop.offenses.size).to eq(1)
offense = cop.offenses.first
expect(offense.line).to eq(1)
expect(cop.highlights).to eq(["#{title} 'Test', js: true"])
expect(offense.message).to eq('Use `:js` instead of `js: true`.')
end
it "doesn't flag violation for #{title} examples that uses compact include syntax", :aggregate_failures do
inspect_source(cop, "#{title} 'Test', :js do; end")
expect(cop.offenses).to be_empty
end
it "doesn't flag violation for #{title} examples that uses flag: symbol" do
inspect_source(cop, "#{title} 'Test', flag: :symbol do; end")
expect(cop.offenses).to be_empty
end
it "autocorrects #{title} examples that uses verbose syntax into compact syntax" do
autocorrected = autocorrect_source(cop, "#{title} 'Test', js: true do; end", source_file)
expect(autocorrected).to eql("#{title} 'Test', :js do; end")
end
end
%w(describe context feature example_group it specify example scenario its).each do |example|
it_behaves_like 'examples with include syntax', example
end
end
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/sidekiq_options_queue'
describe RuboCop::Cop::SidekiqOptionsQueue do
......@@ -9,7 +11,7 @@ describe RuboCop::Cop::SidekiqOptionsQueue do
subject(:cop) { described_class.new }
it 'registers an offense when `sidekiq_options` is used with the `queue` option' do
inspect_source(cop, 'sidekiq_options queue: "some_queue"')
inspect_source('sidekiq_options queue: "some_queue"')
aggregate_failures do
expect(cop.offenses.size).to eq(1)
......@@ -19,7 +21,7 @@ describe RuboCop::Cop::SidekiqOptionsQueue do
end
it 'does not register an offense when `sidekiq_options` is used with another option' do
inspect_source(cop, 'sidekiq_options retry: false')
inspect_source('sidekiq_options retry: false')
expect(cop.offenses).to be_empty
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment