Files
grecia/.rubocop.yml
Senén Rodero Rodríguez c263a6fc2f Configure Rails/I18nLocaleAssignment cop to scan all Ruby files
This cop scans only the tests files by default, but we prefer to scan all
application Ruby files, so when a developer uses the class method
`I18n.locale=`, the cop will embrace using the method
`I18n.with_locale` instead. By doing this way, the cop will help
developers to avoid unexpected translation errors.

Quoting the Rails 6 guides:
> I18n.locale can leak into subsequent requests served by the same
thread/process if it is not consistently set in every controller. For
example executing I18n.locale = :es in one POST requests will have
effects for all later requests to controllers that don't set the locale,
but only in that particular thread/process. For that reason, instead of
I18n.locale = you can use I18n.with_locale which does not have this
leak issue.

Now we enabled the cop for all application Ruby files; we have to
remove the assignments at the controller level to set the request
locale. As Rails 6 guides suggest [1], we can use the `around_action`
controller callback to set each request locale without breaking the
rule.

This cop will warn CONSUL developers when using `I18n.locale`
assignment embracing them to use the `I18n.with_locale`instead.

[1] https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
2022-06-13 15:45:32 +02:00

568 lines
8.3 KiB
YAML

require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
Exclude:
- "db/schema.rb"
- "lib/ckeditor/backend/active_storage.rb"
DisabledByDefault: true
Bundler/DuplicatedGem:
Enabled: true
Bundler/OrderedGems:
Enabled: true
ConsiderPunctuation: true
Layout/AssignmentIndentation:
Enabled: true
Layout/EmptyLineAfterGuardClause:
Enabled: true
Layout/EmptyLineBetweenDefs:
Enabled: true
Layout/EmptyLines:
Enabled: true
Layout/EmptyLinesAroundAccessModifier:
Enabled: true
Layout/EmptyLinesAroundBlockBody:
Enabled: true
Layout/EmptyLinesAroundClassBody:
Enabled: true
Layout/EmptyLinesAroundMethodBody:
Enabled: true
Layout/EmptyLinesAroundModuleBody:
Enabled: true
Layout/EndOfLine:
EnforcedStyle: lf
Layout/ExtraSpacing:
Enabled: true
Layout/HeredocIndentation:
Enabled: true
Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methods
Layout/IndentationStyle:
Enabled: true
Layout/IndentationWidth:
Enabled: true
Layout/LeadingEmptyLines:
Enabled: true
Layout/LineLength:
Max: 110
Severity: refactor
Layout/MultilineBlockLayout:
Enabled: true
Layout/SpaceAfterColon:
Enabled: true
Layout/SpaceAfterComma:
Enabled: true
Layout/SpaceAfterMethodName:
Enabled: true
Layout/SpaceAfterNot:
Enabled: true
Layout/SpaceAfterSemicolon:
Enabled: true
Layout/SpaceAroundBlockParameters:
Enabled: true
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
Layout/SpaceAroundMethodCallOperator:
Enabled: true
Layout/SpaceAroundOperators:
Enabled: true
Layout/SpaceBeforeBlockBraces:
Enabled: true
Layout/SpaceBeforeComma:
Enabled: true
Layout/SpaceBeforeComment:
Enabled: true
Layout/SpaceBeforeFirstArg:
Enabled: true
Layout/SpaceBeforeSemicolon:
Enabled: true
Layout/SpaceInLambdaLiteral:
Enabled: true
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: true
Layout/SpaceInsideArrayPercentLiteral:
Enabled: true
Layout/SpaceInsideBlockBraces:
Enabled: true
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
EnforcedStyle: compact
Layout/SpaceInsideParens:
Enabled: true
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: true
Layout/SpaceInsideRangeLiteral:
Enabled: true
Layout/SpaceInsideReferenceBrackets:
Enabled: true
Layout/SpaceInsideStringInterpolation:
Enabled: true
Layout/TrailingEmptyLines:
Enabled: true
Layout/TrailingWhitespace:
Enabled: true
Lint/AmbiguousRegexpLiteral:
Enabled: true
Lint/BooleanSymbol:
Enabled: true
Lint/ConstantDefinitionInBlock:
Enabled: true
Lint/DuplicateBranch:
Enabled: true
Lint/DuplicateMethods:
Enabled: true
Lint/EmptyBlock:
Enabled: true
Lint/EmptyFile:
Enabled: true
Lint/LiteralAsCondition:
Enabled: true
Lint/ParenthesesAsGroupedExpression:
Enabled: true
Lint/RedundantStringCoercion:
Enabled: true
Lint/SafeNavigationChain:
Enabled: true
Lint/ShadowingOuterLocalVariable:
Enabled: true
Lint/SymbolConversion:
Enabled: true
Exclude:
- "app/models/setting.rb"
- "db/dev_seeds/settings.rb"
Lint/UselessAssignment:
Enabled: true
Lint/Void:
Enabled: true
Naming/VariableName:
Enabled: true
Performance/BlockGivenWithExplicitBlock:
Enabled: true
Performance/CompareWithBlock:
Enabled: true
Performance/DoubleStartEndWith:
Enabled: true
Performance/EndWith:
Enabled: true
Performance/StartWith:
Enabled: true
Performance/Sum:
Enabled: true
Rails/ActiveRecordCallbacksOrder:
Enabled: true
Rails/AddColumnIndex:
Enabled: true
Rails/CreateTableWithTimestamps:
Enabled: true
Exclude:
- "db/migrate/201[5-8]*"
- "db/migrate/*install_audited.rb"
Rails/Date:
Enabled: true
Rails/DynamicFindBy:
Enabled: true
Whitelist:
- find_by_slug_or_id
- find_by_slug_or_id!
- find_by_manager_login
Rails/EnumUniqueness:
Enabled: true
Rails/EnvironmentComparison:
Enabled: true
Rails/FindBy:
Enabled: true
Include:
- "**/*.rb"
Rails/FindEach:
Enabled: true
Rails/HasAndBelongsToMany:
Enabled: true
Rails/HasManyOrHasOneDependent:
Enabled: true
Severity: refactor
Rails/HttpStatus:
Enabled: true
Rails/I18nLocaleAssignment:
Enabled: true
Include:
- "**/*.rb"
Rails/InverseOf:
Enabled: true
Exclude:
- "app/models/related_content.rb"
Rails/NotNullColumn:
Enabled: true
Exclude:
- "db/migrate/201[5-7]*"
Rails/OutputSafety:
Enabled: true
Severity: warning
Exclude:
- app/helpers/text_with_links_helper.rb
Rails/PluckId:
Enabled: true
Rails/PluralizationGrammar:
Enabled: true
Rails/Presence:
Enabled: true
Rails/RelativeDateConstant:
Enabled: true
Rails/RequestReferer:
Enabled: true
Rails/ReversibleMigration:
Enabled: true
Rails/SafeNavigation:
Enabled: true
ConvertTry: true
Rails/SaveBang:
Enabled: true
Severity: refactor
Rails/SkipsModelValidations:
Enabled: true
ForbiddenMethods:
- update_attribute
Exclude:
- lib/acts_as_paranoid_aliases.rb
Rails/TimeZone:
Enabled: true
Rails/UniqBeforePluck:
Enabled: true
Rails/UniqueValidationWithoutIndex:
Enabled: true
Severity: refactor
Rails/UnknownEnv:
Enabled: true
Environments:
- development
- test
- production
- preproduction
- staging
Rails/Validation:
Enabled: true
Rails/WhereEquals:
Enabled: true
Rails/WhereNot:
Enabled: true
RSpec/AroundBlock:
Enabled: true
RSpec/BeforeAfterAll:
Enabled: true
RSpec/Capybara/CurrentPathExpectation:
Enabled: true
RSpec/Capybara/FeatureMethods:
Enabled: true
EnabledMethods:
- scenario
- xscenario
RSpec/Capybara/VisibilityMatcher:
Enabled: true
RSpec/ContextMethod:
Enabled: true
RSpec/DescribedClass:
Enabled: true
EnforcedStyle: explicit
RSpec/EmptyExampleGroup:
Enabled: true
Exclude:
- spec/factories/**/*
RSpec/EmptyHook:
Enabled: true
RSpec/EmptyLineAfterExample:
Enabled: true
RSpec/EmptyLineAfterExampleGroup:
Enabled: true
Exclude:
- spec/factories/**/*
RSpec/ExampleWording:
Enabled: true
RSpec/FactoryBot/FactoryClassName:
Enabled: true
RSpec/FilePath:
Enabled: true
RSpec/Focus:
Enabled: true
RSpec/HookArgument:
Enabled: true
RSpec/InstanceVariable:
Enabled: true
Exclude:
- spec/controllers/concerns/has_orders_spec.rb
RSpec/LetBeforeExamples:
Enabled: true
RSpec/LetSetup:
Enabled: true
RSpec/NotToNot:
Enabled: true
RSpec/OverwritingSetup:
Enabled: true
RSpec/RepeatedExample:
Enabled: true
RSpec/RepeatedExampleGroupBody:
Enabled: true
RSpec/RepeatedExampleGroupDescription:
Enabled: true
RSpec/ScatteredLet:
Enabled: true
RSpec/ScatteredSetup:
Enabled: true
RSpec/VoidExpect:
Enabled: true
Security/Eval:
Enabled: true
Security/JSONLoad:
Enabled: true
Security/Open:
Enabled: true
Security/YAMLLoad:
Enabled: true
Style/AccessorGrouping:
Enabled: true
Style/AndOr:
Enabled: true
Style/ArrayCoercion:
Enabled: true
Style/BlockDelimiters:
Enabled: true
Style/ClassCheck:
Enabled: true
Style/ClassVars:
Enabled: true
Style/CollectionMethods:
Enabled: true
Style/HashConversion:
Enabled: true
Style/HashSyntax:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
Style/IdenticalConditionalBranches:
Enabled: true
Style/IfWithBooleanLiteralBranches:
Enabled: true
Style/MethodDefParentheses:
Enabled: true
Style/MutableConstant:
Enabled: true
Style/NegatedIfElseCondition:
Enabled: true
Style/Not:
Enabled: true
Style/OrAssignment:
Enabled: true
Style/PercentLiteralDelimiters:
Enabled: true
Style/Proc:
Enabled: true
Style/RaiseArgs:
Enabled: true
Style/RedundantArgument:
Enabled: true
Style/RedundantCondition:
Enabled: true
Style/RedundantFileExtensionInRequire:
Enabled: true
Style/RedundantFreeze:
Enabled: true
Style/RedundantInterpolation:
Enabled: true
Style/RedundantParentheses:
Enabled: true
Style/RedundantReturn:
Enabled: true
Style/RedundantSelf:
Enabled: true
Style/SafeNavigation:
Enabled: true
Style/SingleLineMethods:
Enabled: true
Style/SoleNestedConditional:
Enabled: true
Style/StringChars:
Enabled: true
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/SymbolProc:
Enabled: true
Style/TrailingCommaInArrayLiteral:
Enabled: true
Style/TrailingCommaInHashLiteral:
Enabled: true