default.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. # Default enabled cops
  2. # https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
  3. require:
  4. - rubocop-capybara
  5. - rubocop-factory_bot
  6. - rubocop-graphql
  7. - rubocop-inflector
  8. - rubocop-rspec_rails
  9. - ../../config/initializers/inflections.rb
  10. - ./rubocop_zammad.rb
  11. plugins:
  12. - rubocop-faker
  13. - rubocop-performance
  14. - rubocop-rails
  15. - rubocop-rspec
  16. inherit_from:
  17. - todo.yml
  18. - todo.rspec.yml
  19. inherit_mode:
  20. merge:
  21. - Include
  22. AllCops:
  23. NewCops: enable
  24. DisplayCopNames: true
  25. Include:
  26. - '.gitlab/**/*.rb'
  27. - '.github/**/*.rb'
  28. - '.dev/rubocop/**/*.rb'
  29. Exclude:
  30. - 'bin/*'
  31. - 'db/schema.rb'
  32. - 'vendor/**/*'
  33. - 'node_modules/**/*'
  34. - 'public/assets/**/*'
  35. - 'public/packs/**/*'
  36. RSpec:
  37. Include:
  38. - "**/*_spec.rb"
  39. - "**/*_examples.rb"
  40. Language:
  41. Expectations:
  42. - expect_no_offenses
  43. - expect_offense
  44. - adds_foreign_key
  45. - sent
  46. - not_sent
  47. Rails:
  48. Enabled: true
  49. # Zammad StyleGuide
  50. Style/FrozenStringLiteralComment:
  51. Enabled: false
  52. Layout/LineLength:
  53. Description: 'Limit lines to 80 characters.'
  54. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
  55. Enabled: false
  56. Style/NegatedIf:
  57. Description: >-
  58. Favor unless over if for negative conditions
  59. (or control flow or).
  60. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives'
  61. Enabled: false
  62. Style/IfUnlessModifier:
  63. Description: >-
  64. Favor modifier if/unless usage when you have a
  65. single-line body.
  66. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
  67. Enabled: false
  68. Style/TrailingCommaInArrayLiteral:
  69. Description: 'Checks for trailing comma in array literals.'
  70. StyleGuide: '#no-trailing-array-commas'
  71. Enabled: false
  72. Style/TrailingCommaInHashLiteral:
  73. Description: 'Checks for trailing comma in hash literals.'
  74. Enabled: false
  75. Style/TrailingCommaInArguments:
  76. Description: 'Checks for trailing comma in argument lists.'
  77. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
  78. Enabled: false
  79. Style/RescueStandardError:
  80. Description: 'Avoid rescuing without specifying an error class.'
  81. Enabled: true
  82. EnforcedStyle: implicit
  83. Style/FormatStringToken:
  84. Description: Use a consistent style for named format string tokens.
  85. EnforcedStyle: template
  86. # Prefer %{...} over %<...>s to make it easier for translators.
  87. Layout/SpaceInsideReferenceBrackets:
  88. Description: 'Checks the spacing inside referential brackets.'
  89. Enabled: false
  90. Layout/SpaceInsideArrayLiteralBrackets:
  91. Description: 'Checks the spacing inside array literal brackets.'
  92. Enabled: false
  93. Style/DefWithParentheses:
  94. Description: 'Use def with parentheses when there are arguments.'
  95. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
  96. Enabled: false
  97. Style/HashSyntax:
  98. EnforcedShorthandSyntax: either
  99. Layout/HashAlignment:
  100. Description: >-
  101. Align the elements of a hash literal if they span more than
  102. one line.
  103. Enabled: true
  104. EnforcedHashRocketStyle: table
  105. EnforcedColonStyle: table
  106. EnforcedLastArgumentHashStyle: always_inspect
  107. Layout/EmptyLinesAroundClassBody:
  108. Description: "Keeps track of empty lines around class bodies."
  109. Enabled: false
  110. Layout/EmptyLinesAroundMethodBody:
  111. Description: "Keeps track of empty lines around method bodies."
  112. Enabled: false
  113. Layout/EmptyLinesAroundBlockBody:
  114. Description: "Keeps track of empty lines around block bodies."
  115. Enabled: false
  116. Layout/EmptyLinesAroundModuleBody:
  117. Description: "Keeps track of empty lines around module bodies."
  118. Enabled: false
  119. Layout/ExtraSpacing:
  120. Description: 'Do not use unnecessary spacing.'
  121. Enabled: true
  122. Exclude:
  123. - 'config/routes/**/*'
  124. - 'db/migrate/20120101000001_create_base.rb'
  125. - 'db/migrate/20120101000010_create_ticket.rb'
  126. Style/MultilineBlockChain:
  127. Description: 'Avoid multi-line chains of blocks.'
  128. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
  129. Enabled: false
  130. Metrics/ClassLength:
  131. Description: 'Avoid classes longer than 100 lines of code.'
  132. Enabled: false
  133. Metrics/MethodLength:
  134. Description: 'Avoid methods longer than 10 lines of code.'
  135. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
  136. Enabled: false
  137. Metrics/ParameterLists:
  138. Description: 'Checks for methods with too many parameters.'
  139. CountKeywordArgs: false
  140. Style/BlockComments:
  141. Description: 'Do not use block comments.'
  142. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments'
  143. Enabled: false
  144. Style/PerlBackrefs:
  145. Description: 'Avoid Perl-style regex back references.'
  146. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
  147. Enabled: false
  148. Rails/ApplicationRecord:
  149. Exclude:
  150. - 'app/models/application_model.rb'
  151. - 'app/models/active_job_lock.rb'
  152. Rails/BulkChangeTable:
  153. Description: 'Check whether alter queries are combinable.'
  154. Enabled: false
  155. Rails/FindEach:
  156. Description: 'Prefer all.find_each over all.find.'
  157. Enabled: false
  158. Rails/HasAndBelongsToMany:
  159. Description: 'Prefer has_many :through to has_and_belongs_to_many.'
  160. # StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through'
  161. Enabled: false
  162. Rails/I18nLocaleTexts:
  163. Description: 'Enforces use of I18n and locale files instead of locale specific strings.'
  164. Enabled: false
  165. Rails/MatchRoute:
  166. Description: >-
  167. Don't use `match` to define any routes unless there is a need to map multiple request types
  168. among [:get, :post, :patch, :put, :delete] to a single action using the `:via` option.
  169. StyleGuide: 'https://rails.rubystyle.guide/#no-match-routes'
  170. Enabled: false
  171. Rails/SkipsModelValidations:
  172. Description: >-
  173. Use methods that skips model validations with caution.
  174. See reference for more information.
  175. Reference: 'http://guides.rubyonrails.org/active_record_validations.html#skipping-validations'
  176. Enabled: true
  177. Exclude:
  178. - test/**/*
  179. - "**/*_spec.rb"
  180. - "**/*_examples.rb"
  181. Rails/ReversibleMigration:
  182. Description: This cop checks whether the change method of the migration file is reversible.
  183. Enabled: false
  184. Rails/EnvironmentVariableAccess:
  185. Description: 'This cop looks for direct access to environment variables through the ENV variable within the application code.'
  186. Enabled: true
  187. AllowReads: true
  188. Rails/Output:
  189. Exclude:
  190. - "lib/tasks/**/*"
  191. Include:
  192. - "**/*_spec.rb"
  193. Rails/Delegate:
  194. Description: Looks for delegations that could have been created automatically with the delegate method.
  195. Enabled: false
  196. Style/ClassAndModuleChildren:
  197. Description: 'Checks style of children classes and modules.'
  198. Enabled: true
  199. EnforcedStyle: compact
  200. # Avoids nesting of classes and modules in sequencer code and improves readability by decreasing whitespace.
  201. # This cop is excluded for the rest of the codebase, due to following problems:
  202. # - undefined constants in path components which are not autoloaded
  203. # - changes to the lexical scope which require reference to the complete namespace of external classes
  204. # - difficult backporting due to extensive whitespace changes on all lines
  205. Include:
  206. - 'lib/sequencer/**/*.rb'
  207. Naming/FileName:
  208. Description: 'Use snake_case for source file names.'
  209. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
  210. Enabled: true
  211. Exclude:
  212. - 'script/websocket-server.rb'
  213. Naming/VariableNumber:
  214. Description: 'Use the configured style when numbering variables.'
  215. Enabled: false
  216. Naming/MethodParameterName:
  217. Description: >-
  218. Checks for method parameter names that contain capital letters,
  219. end in numbers, or do not meet a minimal length.
  220. Enabled: true
  221. AllowedNames: e, id, _, ip, to
  222. Lint/BooleanSymbol:
  223. Description: 'Check for `:true` and `:false` symbols.'
  224. Enabled: true
  225. Exclude:
  226. - "db/seeds/object_manager_attributes.rb"
  227. - "spec/requests/integration/object_manager_attributes_spec.rb"
  228. Lint/InterpolationCheck:
  229. Description: 'Raise warning for interpolation in single q strs'
  230. Enabled: true
  231. Exclude:
  232. - "test/unit/email_process_auto_response_test.rb"
  233. - "test/unit/email_process_bounce_delivery_permanent_failed_test.rb"
  234. - "test/unit/email_process_bounce_follow_test.rb"
  235. - "test/unit/notification_factory_renderer_test.rb"
  236. - "test/unit/notification_factory_template_test.rb"
  237. - "test/unit/ticket_trigger_test.rb"
  238. - "test/unit/ticket_trigger_recursive_disabled_test.rb"
  239. Lint/UselessConstantScoping:
  240. Description: Checks for useless constant scoping.
  241. Enabled: false
  242. Style/StringConcatenation:
  243. Description: 'Checks for places where string concatenation can be replaced with string interpolation.'
  244. StyleGuide: '#string-interpolation'
  245. Enabled: true
  246. Exclude:
  247. - "config/routes/**/*"
  248. Style/RegexpLiteral:
  249. Description: 'This cop enforces using // or %r around regular expressions.'
  250. EnforcedStyle: percent_r
  251. Style/RedundantBegin:
  252. Description: 'This cop checks for redundant `begin` blocks.'
  253. Enabled: false
  254. Style/FetchEnvVar:
  255. Description: 'This cop suggests `ENV.fetch` for the replacement of `ENV[]`.'
  256. Enabled: false
  257. Style/SafeNavigationChainLength:
  258. Description: 'This cops suggests to not use&.optional&.chaining&.too&.much'
  259. Enabled: false
  260. GraphQL/OrderedArguments:
  261. Enabled: false
  262. GraphQL/OrderedFields:
  263. Enabled: false
  264. # Our models can have many fields, and we should not enforce a different GraphQL structure just for the sake of it.
  265. GraphQL/ExtractType:
  266. Enabled: false
  267. GraphQL/ExtractInputType:
  268. MaxArguments: 3
  269. # Run cop only for mutations: https://github.com/DmitryTsepelev/rubocop-graphql/issues/47
  270. Include:
  271. - 'app/graphql/gql/mutations/**/*.rb'
  272. # Enforcing field descriptions for all model fields will be too verbose/redundant.
  273. GraphQL/FieldDescription:
  274. Exclude:
  275. - "app/graphql/gql/types/**/*"
  276. GraphQL/ObjectDescription:
  277. Exclude:
  278. - "app/graphql/gql/fields/**/*" # false positive?
  279. - "app/graphql/gql/types/**/base_*"
  280. # RSpec tests
  281. Style/NumericPredicate:
  282. Description: >-
  283. Checks for the use of predicate- or comparison methods for
  284. numeric comparisons.
  285. StyleGuide: '#predicate-methods'
  286. # This will change to a new method call which isn't guaranteed to be on the
  287. # object. Switching these methods has to be done with knowledge of the types
  288. # of the variables which rubocop doesn't have.
  289. AutoCorrect: false
  290. Enabled: true
  291. Exclude:
  292. - "**/*_spec.rb"
  293. Lint/AmbiguousBlockAssociation:
  294. Description: >-
  295. Checks for ambiguous block association with method when param
  296. passed without parentheses.
  297. StyleGuide: '#syntax'
  298. Enabled: true
  299. Exclude:
  300. - "spec/support/*.rb"
  301. - "**/*_spec.rb"
  302. - "**/*_examples.rb"
  303. Layout/MultilineMethodCallIndentation:
  304. Description: >-
  305. Checks the indentation of the method name part in method calls
  306. that span more than one line.
  307. EnforcedStyle: indented
  308. Include:
  309. - "**/*_spec.rb"
  310. Lint/UnusedMethodArgument:
  311. AllowUnusedKeywordArguments: true
  312. Naming/PredicateName:
  313. Exclude:
  314. - "app/graphql/gql/types/**/*"
  315. RSpec/DescribeMethod:
  316. # We want to be able to split tests into subfolders, where several cases are grouped together.
  317. Description: 'Checks that the second argument to the top level describe is the tested method name.'
  318. Enabled: false
  319. RSpec/NestedGroups:
  320. Max: 6
  321. RSpecRails/AvoidSetupHook:
  322. Exclude:
  323. - "test/**/*"
  324. RSpec/AlignLeftLetBrace:
  325. Description: 'Checks that left braces for adjacent single line lets are aligned.'
  326. Enabled: true
  327. RSpec/AnyInstance:
  328. Description: 'Prefer instance doubles over stubbing any instance of a class.'
  329. Enabled: false
  330. RSpec/SubjectStub:
  331. Enabled: false
  332. RSpecRails/InferredSpecType:
  333. Description: 'Identifies redundant spec type.'
  334. Enabled: false # We use types to add DSL to rspec.
  335. RSpec/IndexedLet:
  336. Description: 'Do not set up test data using indexes (e.g., `item_1`, `item_2`).'
  337. Enabled: false
  338. Capybara/SpecificFinders:
  339. Description: 'Checks if there is a more specific finder offered by Capybara.'
  340. Enabled: false
  341. # False positives, autocorrection makes weird suggestions.
  342. Capybara/SpecificActions:
  343. Description: 'Checks for there is a more specific actions offered by Capybara.'
  344. Enabled: false
  345. Capybara/NegationMatcher:
  346. Description: Enforces use of have_no_* or not_to for negated expectations.
  347. EnforcedStyle: have_no
  348. Capybara/ClickLinkOrButtonStyle:
  349. EnforcedStyle: link_or_button
  350. RSpec/ExampleLength:
  351. inherit_mode:
  352. merge:
  353. - Exclude
  354. CountAsOne:
  355. - 'array'
  356. - 'hash'
  357. - 'heredoc'
  358. Max: 25
  359. Exclude:
  360. - "spec/system/**/*.rb"
  361. FactoryBot/ExcessiveCreateList:
  362. Enabled: false
  363. Zammad/PreferNegatedIfOverUnless:
  364. Exclude:
  365. - 'bin/rspec'
  366. Zammad/ExistsDateTimePrecision:
  367. Include:
  368. - "db/migrate/*.rb"
  369. - "**/db/addon/**/*.rb"
  370. Zammad/ExistsResetColumnInformation:
  371. Include:
  372. - "db/migrate/*.rb"
  373. - "**/db/addon/**/*.rb"
  374. Exclude:
  375. - 'db/migrate/201*_*.rb'
  376. - 'db/migrate/2020*_*.rb'
  377. Zammad/MigrationSchedulerLastRun:
  378. Include:
  379. - "db/migrate/*.rb"
  380. - "**/db/addon/**/*.rb"
  381. Exclude:
  382. - 'db/migrate/201*_*.rb'
  383. - 'db/migrate/2020*_*.rb'
  384. Zammad/DetectTranslatableString:
  385. Enabled: true
  386. Include:
  387. - "app/**/*.rb"
  388. - "db/**/*.rb"
  389. - "lib/**/*.rb"
  390. Exclude:
  391. - "db/migrate/**/*.rb"
  392. - "db/addon/**/*.rb"
  393. - "lib/generators/**/*.rb"
  394. - "lib/sequencer/**/*.rb"
  395. - "lib/import/**/*.rb"
  396. - "lib/tasks/**/*.rb"
  397. - "lib/fill_db.rb"
  398. Zammad/ForbidTranslatableMarker:
  399. Enabled: true
  400. Include:
  401. - "db/migrate/*.rb"
  402. Zammad/ExistsDbStrategy:
  403. Include:
  404. - "spec/**/*.rb"
  405. Exclude:
  406. - "spec/support/capybara/*.rb"