canvas-lms/.rubocop.common.yml

344 lines
9.7 KiB
YAML

require:
- rubocop-rails
- rubocop-rake
- rubocop-rspec
- rubocop-performance
# this odd relative path is so that rubocop works when run without "bundle
# exec", such as from most editors/IDEs.
- ./gems/rubocop-canvas/lib/rubocop_canvas
- outrigger/cops/migration/tagged
AllCops:
TargetRubyVersion: 2.7
NewCops: enable
Bundler:
Severity: error
Bundler/OrderedGems:
Enabled: false # this isn't good for us because of how we pin dependencies
Gemspec:
Severity: error
Gemspec/RequiredRubyVersion:
# all the gemspecs in this repo are non-published gems
# the root Gemfile enforces the Ruby version, and we purposely
# don't specify required_ruby_version in the rest to reduce
# maintenance pain when updating ruby versions
Enabled: false
Layout:
Severity: error
Layout/LineLength:
Enabled: false # TODO. Maybe.
Lint:
Severity: error
Lint/AmbiguousBlockAssociation:
IgnoredMethods:
- change
- not_change
- raise_error
Lint/NoFileUtilsRmRf:
Severity: warning # intended for specs; not enforced
Lint/NoSleep:
Severity: warning # intended for specs; not enforced
Lint/NonLocalExitFromIterator:
Enabled: false # SnR is too low because of how often this construct is used
Lint/SafeNavigationConsistency:
Enabled: false # https://github.com/rubocop/rubocop/issues/9816
Lint/UnusedMethodArgument:
AllowUnusedKeywordArguments: true # there's no way to mark a kwarg as unused
Metrics:
Enabled: false # SnR is just too low to have this enabled
Migration/Tagged:
Severity: error
AllowedTags:
- predeploy
- postdeploy
- cassandra
- dynamodb
Naming/HeredocDelimiterCase:
Severity: error
Naming/HeredocDelimiterNaming:
Severity: error
ForbiddenDelimiters:
# negative regex - these are the _allowed_ delimiters
# any you add should describe the format of the data, not describe
# what the data is for. this allows editors to syntax highlight
- ^(?!AST|BASE64|CSV|GQL|HTML|JS|MD|PEM|REGEX|RUBY|SQL|SRT|TEXT|XML|YAML).+$
Naming/FileName:
Exclude:
- "**/Gemfile.d/~after.rb"
Performance/Casecmp:
Severity: error
AutoCorrect: false # prefer using casecmp?(other) instead of casecmp(other).zero?; it handles unicode better
Performance/Count:
Severity: error
Performance/Detect:
Severity: error
Performance/InefficientHashSearch:
Severity: error
Performance/MapCompact:
Severity: error
Performance/RedundantMerge:
Severity: error
Performance/RedundantSplitRegexpArgument:
Severity: error
Performance/RegexpMatch:
Severity: error
Performance/StartWith:
Severity: error
Performance/StringInclude:
Severity: error
Performance/StringReplacement:
Severity: error
Performance/TimesMap:
Severity: error
Rails/ApplicationRecord:
Enabled: false # we never bothered creating an ApplicationRecord
Rails/ContentTag:
Severity: error
Exclude:
- "**/db/migrate/*" # this cop is for views, not migrations, where it gets confused with outrigger
- "doc/**/*"
Rails/HasManyOrHasOneDependent:
Enabled: false # legacy code + most things we soft delete anyway
Rails/HelperInstanceVariable:
Enabled: false # legacy code
Rails/SkipsModelValidations:
Enabled: false # Canvas skips validations in many places for optimization reasons
Rails/SquishedSQLHeredocs:
Severity: error
RSpec/AnyInstance:
Enabled: false # while using an instance double would be preferable, it's a pain
RSpec/DescribedClass:
Enabled: false # we haven't used it, and it seems antithetical to RSpec/NamedSubject
RSpec/EmptyExampleGroup:
Severity: error
RSpec/EmptyLineAfterExample:
Severity: error
RSpec/EmptyLineAfterHook:
Severity: error
RSpec/EmptyLineAfterFinalLet:
Severity: error
RSpec/ExampleLength:
Enabled: false # this is a Metrics-style cop
RSpec/ExampleWording:
Severity: error
RSpec/ExpectInHook:
Enabled: false # follows RSpec/MultipleExpectations
RSpec/HookArgument:
Severity: error
RSpec/InstanceVariable:
Enabled: false # legacy code
RSpec/MessageSpies:
Enabled: false # we don't use spies
RSpec/MultipleExpectations:
Enabled: false # we don't write specs in this style
RSpec/MultipleMemoizedHelpers:
Enabled: false # complicated setup is sometimes necessary
RSpec/NestedGroups:
Enabled: false # legacy code
RSpec/ReceiveNever:
Severity: error
RSpec/RepeatedDescription:
Severity: error
RSpec/SubjectStub:
Enabled: false # yes, canvas is big and complicated sometimes
RSpec/StubbedMock:
Enabled: false # this style goes along with spies
Specs/EnsureSpecExtension:
Exclude:
- spec/shared_examples/**/*
Style/Alias:
EnforcedStyle: prefer_alias_method # https://github.com/rubocop/ruby-style-guide/issues/821
Severity: error
Style/CaseLikeIf:
Severity: error
Style/ColonMethodCall:
Severity: error
Style/ConditionalAssignment:
Severity: error
Style/Documentation:
Enabled: false # most things don't need to be documented
Style/EmptyCaseCondition:
Severity: error
Style/Encoding:
Severity: error
Style/FrozenStringLiteralComment:
Severity: error
Style/IfUnlessModifier:
# see also https://github.com/rubocop/rubocop/discussions/10048
Enabled: false # can obscure important decisions or put too much code in a line
Style/IfWithBooleanLiteralBranches:
Severity: error
Style/MutableConstant:
Severity: error
Style/NegatedIf:
Severity: error
Style/NumericPredicate:
Enabled: false # `> 0` can be easier to read than `.positive?`
Style/OrAssignment:
Severity: error
Style/ParenthesesAroundCondition:
Severity: error
Style/PerlBackrefs:
Enabled: false # Regexp.last_match(1) is far worse than $1
Style/PreferredHashMethods:
Severity: error
Style/RedundantAssignment:
Severity: error
Style/RedundantBegin:
Severity: error
Style/RedundantCondition:
Severity: error
Style/RedundantInterpolation:
Severity: error
Style/RedundantFreeze:
Severity: error
Style/RedundantParentheses:
Severity: error
Style/RedundantRegexpEscape:
Severity: error
Style/RedundantReturn:
Severity: error
Style/SafeNavigation:
Severity: error
Style/Semicolon:
Severity: error
Style/SingleLineMethods:
Severity: error
Style/SlicingWithRange:
Severity: error
Style/SpecialGlobalVars:
Enabled: false # $! and $? are fine
Style/SymbolProc:
Severity: error
Style/UnpackFirst:
Severity: error
Style/WhileUntilModifier:
Enabled: false # nontrivial loops should look like loops
# the following cops are currently silenced, but we may want to enable them IF
# we correct all instances in the codebase first
Lint/UriEscapeUnescape: # TODO
Severity: warning
Naming/VariableNumber: # TODO
Enabled: false
Rails/DynamicFindBy: # TODO; autocorrect (unsafe)
AllowedMethods:
- find_by_name # PluginSetting.find_by_name
- find_by_asset_string # ApplicationRecord.find_by_asset_string
AutoCorrect: false
Rails/ReadWriteAttribute: # TODO: autocorrect (unsafe)
Enabled: false # accessors are often defined in terms of read_attribute
Rails/TimeZone: # TODO: autocorrect (unsafe)
Enabled: false
Rails/WhereExists: # TODO: autocorrect(unsafe)
EnforcedStyle: where
AutoCorrect: false
RSpec/BeEql: # TODO: autocorrect
Enabled: false
RSpec/ContextWording: # TODO
Enabled: false
RSpec/DescribeClass: # TODO
Enabled: false
RSpec/ExpectChange: # TODO: autocorrect (unsafe)
Enabled: false
RSpec/NamedSubject: # TODO
Enabled: false
RSpec/NotToNot: # TODO: autocorrect
Enabled: false
RSpec/PredicateMatcher: # TODO: autocorrect (unsafe)
Enabled: false
RSpec/ScatteredSetup: # TODO: investigate if these are required
Enabled: false
RSpec/VerifiedDoubles: # TODO
Enabled: false
Style/BlockDelimiters: # TODO: autocorrect
Enabled: true
Exclude:
- spec/**/*_spec.rb
- spec/shared_examples/**/*.rb
AutoCorrect: false
Style/ClassAndModuleChildren: # TODO: autocorrect (unsafe)
Enabled: false
Style/DoubleNegation: # TODO: autocorrect (unsafe)
Enabled: false
Style/Dir: # TODO: autocorrect
Enabled: false
Style/EmptyElse: # TODO: autocorrect
Enabled: false
EnforcedStyle: empty # explicit nil indicates programmer intent
Style/FormatStringToken: # TODO: investigate if this complains about our i18n library
Enabled: false
Style/GuardClause: # TODO
Enabled: false
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
Enabled: false # TODO: autocorrect
Style/Lambda: # TODO: autocorrect
Enabled: false
Style/MethodCallWithArgsParentheses: # TODO: autocorrect
Enabled: false
Style/MethodCallWithoutArgsParentheses: # TODO: autocorrect
Enabled: false
Style/NumericLiterals: # TODO: autocorrect
Enabled: false
Style/ParallelAssignment: # TODO: autocorrect (with probable exceptions)
Enabled: false
Style/PercentLiteralDelimiters: # TODO: autocorrect
Enabled: false
Style/PercentQLiterals: # TODO: autocorrect
Enabled: false
Style/RedundantSelf: # TODO: autocorrect
Enabled: false
Style/RegexpLiteral: # TODO: autocorrect
Enabled: false
Style/RescueModifier: # TODO
Severity: warning
AutoCorrect: false
Style/RescueStandardError: # TODO: autocorrect
EnforcedStyle: implicit
Enabled: false
Style/ReturnNil: # TODO: autocorrect (investigate violations)
Enabled: false
Style/SignalException: # TODO: autocorrect
Enabled: false
Style/StderrPuts: # TODO: autocorrect
Enabled: false
Style/StringConcatenation: # TODO: autocorrect (maybe)
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
Enabled: false # TODO: autocorrect
Style/SymbolArray: # TODO: autocorrect
Enabled: false
Style/QuotedSymbols:
# once Style/StringLiterals is enabled, we can remove this since it will inherit
EnforcedStyle: double_quotes
AutoCorrect: false
Style/TrailingCommaInArguments: # TODO: autocorrect
Enabled: false
Style/TrailingCommaInArrayLiteral: # TODO: autocorrect
Enabled: false
Style/TrailingCommaInHashLiteral: # TODO: autocorrect
Enabled: false
Style/WordArray: # TODO: autocorrect
Enabled: false
Style/ZeroLengthPredicate: # TODO: autocorrect (unsafe)
Enabled: false