-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path.rubocop.yml
262 lines (247 loc) · 9.38 KB
/
.rubocop.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
inherit_from: .rubocop_todo.yml
inherit_mode:
merge:
- Exclude
require:
- rubocop-performance
- rubocop-rails
# ------------------------------------------------------------------------------
# Updating RuboCop
#
# *** Update The Codeclimate Channel When Updating Rubocop
# See docs.codeclimate.com/docs/rubocop#section-using-rubocop-s-newer-versions
# Use the highest available channel that's compatible with the RuboCop version.
# Available channels: https://github.com/codeclimate/codeclimate-rubocop/branches/all?utf8=%E2%9C%93&query=channel%2Frubocop
# .codeclimate.yml specifies the RuboCop version ('channel') used
# by Code Climate, which can be different than the version in Gemfile.lock
#
# *** Re-generate the RuboCop auto-configuration todo list
# at least run rubocop --regenerate-todo and commit changes
# optionally follow other suggestions at
# https://docs.rubocop.org/rubocop/configuration.html#automatically-generated-configuration
#
# ------------------------------------------------------------------------------
# RuboCop configuration
# https://docs.rubocop.org/rubocop/configuration.html
AllCops:
NewCops: enable
########################### Excluded files ###################################
# Completely ignore the following
Exclude:
- .codeclimate.yml
- app/assets/javascripts/bootstrap.js
- app/assets/javascripts/jquery.js
- app/assets/javascripts/jstz.js
- app/assets/javascripts/lightbox.js
- "db/**/*"
- "log/**/*"
- public/design_test/jquery-1.5.2.min.js
# We need not check these scripts, and some of them cause Rubocop errors
- "script/old/**/*"
# not Ruby
- script/perf_monitor
- "tmp/**/*"
# ------------------------------------------------------------------------------
########### Individual cops for which MO uses a non-default configuration
Gemspec:
# Not relevent (MO is not a gem)
Enabled: false
Layout/BeginEndAlignment:
# Rubocop default: start_of_line
# which aligns "end" with **start of the line** that includes "begin"
# MO: align with "begin". This is how we've almost always done it.
# And it's consistent with Layout/EndAlignment for other keywords.
EnforcedStyleAlignWith: begin
Layout/DotPosition:
# Rubocop default: leading
EnforcedStyle: trailing
Layout/HashAlignment:
# Repeat the Rubocop default because Codeclimate ignores it as of 2019-07-09
EnforcedColonStyle: key
Layout/LineEndStringConcatenationIndentation:
# We most consistently align the start of the continued line
# with the start of the string on the previous line.
# This does not correspond to any available EnforcedStyle.
Enabled: false
Layout/LineLength:
# RuboCop default: 120
# Use 80 instead because some developers have smaller screens
Max: 80
Layout/MultilineMethodParameterLineBreaks:
# Makes Each param in a multi-line method definition start on a separate line.
# RuboCop default: true
# Cop seems like overkill; MO has many relevant methods with >1 param per line
Enabled: false
Lint/AmbiguousOperatorPrecedence:
# We do this only in rare cases; Always doing it would add uneeded clutter
Enabled: false
Lint/NonAtomicFileOperation:
# Disable until I understand the cop's implications - jdc 2022-07-14
# https://docs.rubocop.org/rubocop/1.31/cops_lint.html#lintnonatomicfileoperation
Enabled: false
Metrics/AbcSize:
# This Cop makes less sense in tests, we regularly ignore it.
Exclude:
- "test//**/*"
Metrics/BlockLength:
# This Cop makes less sense in tests, we regularly ignore it.
Exclude:
- "test//**/*"
Metrics/ClassLength:
# Rubocop default: 100
# Relaxed metric based on actual practice
Max: 250
Exclude:
# This Cop makes less sense in tests, we regularly ignore it.
- "test//**/*"
Metrics/CyclomaticComplexity:
# This Cop makes less sense in tests, we regularly ignore it.
Exclude:
- "test//**/*"
Metrics/MethodLength:
# Rubocop default: 10
# Relaxed metric based on Codeclimate's default .rubocop.yml
Max: 30
# This Cop makes less sense in tests, we regularly ignore it.
Exclude:
- "test//**/*"
Metrics/ModuleLength:
# Rubocop default: 100
# Relaxed metric based on Codeclimate's default .rubocop.yml
Max: 250
# This Cop makes less sense in tests, we regularly ignore it.
Exclude:
- "test//**/*"
Metrics/PerceivedComplexity:
# This Cop makes less sense in tests, we regularly ignore it.
Exclude:
- "test//**/*"
Naming/BlockForwarding:
# In Ruby 3.1, anonymous block forwarding has been added.
# This cop identifies places where `do_something(&block)`
# can be replaced by `do_something(&)`.
# Default is `anonymous`
# Keeping it `explicit` until we're ready to switch.
EnforcedStyle: explicit
Performance/Casecmp:
# This cop does not work with Unicode in Ruby 2.4
Enabled: false
Performance/RegexpMatch:
# Autocorrect changes "something.match(regexp)" to "something.match?(regexp)".
# The latter throws an error when something is not a Regexp, String or Symbol
# Example: undefined method `match?' for nil:NilClass
# So manually correct to: regexp.match?(something)
AutoCorrect: false
Performance/StringInclude:
# "This cop’s offenses are not safe to auto-correct if a receiver is nil."
Enabled: false
Rails/ActionOrder:
# Allow `edit` after `create`
# See https://github.com/MushroomObserver/mushroom-observer/pull/1241#issuecomment-1364636450
ExpectedOrder:
- index
- show
- new
# - edit
- create
- update
- destroy
Rails/DynamicFindBy:
# Make autocorrect saf(er) by whitelisting our find_by methods
AllowedMethods: find_by_sql, find_by_code_with_wildcards, find_by_name_with_wildcards, find_by_name_or_reverse_name, find_by_scientific_name_with_wildcards, find_by_title_with_wildcards, find_by_title_with_wildcards
AutoCorrect: true
Rails/RedundantPresenceValidationOnBelongsTo: # new in 2.13
# Cop gives false positives
# Perhaps because we don't load Rails defaults in config, and also don't have
# config.active_record.belongs_to_required_by_default
# See also https://github.com/MushroomObserver/mushroom-observer/issues/1072
Enabled: false
Rails/RenderInline:
# https://github.com/MushroomObserver/mushroom-observer/pull/1079#discussion_r917332451
Exclude:
- "app/controllers/ajax_controller/**/*"
Rails/WhereExists:
# Can be unsafe depending on eager_load vs pre_load
# https://docs.rubocop.org/rubocop-rails/cops_rails.html#railswhereexists
Enabled: false
Style/AccessorGrouping:
# https://github.com/MushroomObserver/mushroom-observer/pull/988
Enabled: false
# The following are Exclude in case we re-enable the cop
# Exclude files that individually comment accessors
# else Rubocop concatenates the accessors and comments on a single line.
# Disabling Style/AccessorGrouping around the accessors doesn't
# work in this context because Rubocop v1.30.0 generates a
# Style/EmptyLinesAroundAttributeAccessor offense
# See https://github.com/rubocop/rubocop/issues/10693
Exclude:
- "app/classes/country_counter.rb"
- "app/classes/mo_paginator.rb"
Style/AsciiComments:
# Allow non-ascii characters in comments; we need to use accented chars
Enabled: false
Style/ClassAndModuleChildren:
# Allow nested or compact module declaration
Enabled: false
Style/DateTime:
# Repeat the RuboCop default because CodeClimate silently overrides it
# Is this still true? JDC 2020-08-17
Enabled: false
Style/Documentation:
# We often ignore this and bare-bones comments add nothing useful.
# And see Martin, Clean Code, ch. 4
# (Redundant Comments and Mandated Comments are Bad Comments)
Enabled: false
Style/DoubleNegation:
# Rubocop default: true
# Allow double bang. In the rare places we do this, its use is justified.
Enabled: false
Style/EmptyHeredoc:
# Empty Heredoc is usedful as a placeholder in script/refresh_sitemap
Exclude:
- script/refresh_sitemap
Style/FormatStringToken:
# It doesn't seem like we gain much by doing this.
Enabled: false
# The commented-out lines below are in case we re-enable the cop
# # This doesn't work for redirect in config/routes.rb.
# AllowedMethods:
# - "redirect"
Style/HashSyntax:
# Ruby 3.1 supports a new JS-like shorthand hash key/val assignment
# as long as key names and value variable names are the same.
# e.g. { foo: } is evaluated like { foo: foo }
# https://dev.to/baweaver/ruby-3-1-shorthand-hash-syntax-first-impressions-19op
# This setting allows for a transition while we get used to the new style.
# AN 2022-10-09
EnforcedShorthandSyntax: either
Style/MethodCallWithArgsParentheses:
# MO uses parentheses (except for some macro-style methods)
Enabled: true
Style/PercentLiteralDelimiters:
# Repeat the RuboCop defaults because Codeclimate silently overrides them
# Is that still true? JDC 2020-08-17?
PreferredDelimiters:
default: "()"
"%i": "[]"
"%I": "[]"
"%r": "{}"
"%w": "[]"
"%W": "[]"
Style/RaiseArgs:
# Rubocop defaiult: exploded
# I can't figure out how to get exploded to work with API.
EnforcedStyle: compact
Style/StringLiterals:
# Rubocop default: single_quotes
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
# Rubocop default: single_quotes
EnforcedStyle: double_quotes
Style/SymbolArray:
# Rubocop default: percent. Ex: %i[foo bar baz]
# MO uses plain brackets. Ex: [:foo, :bar, :baz]
EnforcedStyle: brackets
Rails/SkipsModelValidations:
# We skip validations all the time. I'm tired of disabling this cop.
Enabled: false