gitlab-styles 4.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +18 -0
  3. data/.gitlab-ci.yml +4 -15
  4. data/.gitlab/merge_request_templates/New Static Analysis Check.md +21 -0
  5. data/.gitlab/merge_request_templates/Release.md +4 -4
  6. data/.rubocop.yml +3 -1
  7. data/Gemfile +2 -2
  8. data/gitlab-styles.gemspec +5 -4
  9. data/lib/gitlab/styles/rubocop.rb +5 -0
  10. data/lib/gitlab/styles/rubocop/cop/active_record_dependent.rb +1 -1
  11. data/lib/gitlab/styles/rubocop/cop/code_reuse/active_record.rb +131 -0
  12. data/lib/gitlab/styles/rubocop/cop/custom_error_class.rb +6 -3
  13. data/lib/gitlab/styles/rubocop/cop/gem_fetcher.rb +1 -1
  14. data/lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb +1 -1
  15. data/lib/gitlab/styles/rubocop/cop/line_break_around_conditional_block.rb +132 -0
  16. data/lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb +1 -1
  17. data/lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb +1 -1
  18. data/lib/gitlab/styles/rubocop/cop/rspec/base.rb +18 -0
  19. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb +65 -0
  20. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb +65 -0
  21. data/lib/gitlab/styles/rubocop/cop/rspec/example_starting_character.rb +124 -0
  22. data/lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb +10 -5
  23. data/lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb +3 -2
  24. data/lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb +10 -13
  25. data/lib/gitlab/styles/rubocop/model_helpers.rb +1 -1
  26. data/lib/gitlab/styles/rubocop/rspec/helpers.rb +17 -0
  27. data/lib/gitlab/styles/version.rb +1 -1
  28. data/rubocop-all.yml +1 -0
  29. data/rubocop-bundler.yml +1 -0
  30. data/rubocop-code_reuse.yml +24 -0
  31. data/rubocop-default.yml +1 -0
  32. data/rubocop-gemspec.yml +1 -0
  33. data/rubocop-layout.yml +6 -0
  34. data/rubocop-lint.yml +63 -5
  35. data/rubocop-metrics.yml +1 -0
  36. data/rubocop-migrations.yml +1 -0
  37. data/rubocop-naming.yml +1 -0
  38. data/rubocop-performance.yml +48 -0
  39. data/rubocop-rails.yml +79 -0
  40. data/rubocop-rspec.yml +14 -0
  41. data/rubocop-security.yml +1 -0
  42. data/rubocop-style.yml +90 -1
  43. metadata +22 -13
  44. data/.rubocop_todo.yml +0 -7
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Gems in consecutive lines should be alphabetically sorted
2
3
  Bundler/OrderedGems:
3
4
  Enabled: false
@@ -0,0 +1,24 @@
1
+ # Denies the use of ActiveRecord methods outside of configured
2
+ # excluded directories
3
+ # Directories that allow the use of the denied methods.
4
+ # To start we provide a default configuration that matches
5
+ # a standard Rails app and enable.
6
+ # The default configuration can be overridden by
7
+ # providing your own Exclusion list as follows:
8
+ # CodeReuse/ActiveRecord:
9
+ # Enabled: true
10
+ # Exclude:
11
+ # - app/models/**/*.rb
12
+ # - config/**/*.rb
13
+ # - db/**/*.rb
14
+ # - lib/tasks/**/*.rb
15
+ # - spec/**/*.rb
16
+ # - lib/gitlab/**/*.rb
17
+ CodeReuse/ActiveRecord:
18
+ Enabled: true
19
+ Exclude:
20
+ - app/models/**/*.rb
21
+ - config/**/*.rb
22
+ - db/**/*.rb
23
+ - lib/tasks/**/*.rb
24
+ - spec/**/*.rb
@@ -1,3 +1,4 @@
1
+ ---
1
2
  require:
2
3
  - rubocop-gitlab-security
3
4
  - rubocop-performance
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Dependencies in the gemspec should be alphabetically sorted
2
3
  # Configuration parameters: Include, TreatCommentsAsGroupSeparators.
3
4
  Gemspec/OrderedDependencies:
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Check indentation of private/protected visibility modifiers.
2
3
  Layout/AccessModifierIndentation:
3
4
  Enabled: true
@@ -60,6 +61,11 @@ Layout/EmptyLines:
60
61
  Layout/EmptyLinesAroundAccessModifier:
61
62
  Enabled: true
62
63
 
64
+ # Checks for a newline after an attribute accessor or a group of them
65
+ # https://docs.rubocop.org/rubocop/0.89/cops_layout.html#layoutemptylinesaroundattributeaccessor
66
+ Layout/EmptyLinesAroundAttributeAccessor:
67
+ Enabled: true
68
+
63
69
  # Keeps track of empty lines around block bodies.
64
70
  Layout/EmptyLinesAroundBlockBody:
65
71
  Enabled: true
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Checks for ambiguous block association with method when param passed without
2
3
  # parentheses.
3
4
  Lint/AmbiguousBlockAssociation:
@@ -18,6 +19,10 @@ Lint/AmbiguousRegexpLiteral:
18
19
  Lint/AssignmentInCondition:
19
20
  Enabled: false
20
21
 
22
+ # Checks for places where binary operator has identical operands
23
+ Lint/BinaryOperatorWithIdenticalOperands:
24
+ Enabled: true
25
+
21
26
  # Default values in optional keyword arguments and optional ordinal arguments
22
27
  # should not refer back to the name of the argument.
23
28
  Lint/CircularArgumentReference:
@@ -31,6 +36,22 @@ Lint/Debugger:
31
36
  Lint/DeprecatedClassMethods:
32
37
  Enabled: true
33
38
 
39
+ # Algorithmic constants for OpenSSL::Cipher and OpenSSL::Digest deprecated since OpenSSL version 2.2.0.
40
+ # Prefer passing a string instead.
41
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintdeprecatedopensslconstant
42
+ Lint/DeprecatedOpenSSLConstant:
43
+ Enabled: true
44
+
45
+ # Checks that there are no repeated conditions used in if 'elsif'.
46
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintduplicateelsifcondition
47
+ Lint/DuplicateElsifCondition:
48
+ Enabled: true
49
+
50
+ # Checks that there are no repeated exceptions used in 'rescue' expressions.
51
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintduplicaterescueexception
52
+ Lint/DuplicateRescueException:
53
+ Enabled: true
54
+
34
55
  # Check for immutable argument given to each_with_object.
35
56
  Lint/EachWithObjectArgument:
36
57
  Enabled: true
@@ -39,6 +60,11 @@ Lint/EachWithObjectArgument:
39
60
  Lint/ElseLayout:
40
61
  Enabled: true
41
62
 
63
+ # Checks for the presence of if, elsif and unless branches without a body.
64
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintemptyconditionalbody
65
+ Lint/EmptyConditionalBody:
66
+ Enabled: true
67
+
42
68
  # Checks for empty ensure block.
43
69
  Lint/EmptyEnsure:
44
70
  Enabled: true
@@ -55,6 +81,11 @@ Lint/EnsureReturn:
55
81
  Lint/FlipFlop:
56
82
  Enabled: true
57
83
 
84
+ # Checks for the presence of precise comparison of floating point numbers.
85
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintfloatcomparison
86
+ Lint/FloatComparison:
87
+ Enabled: true
88
+
58
89
  # Catches floating-point literals too large or small for Ruby to represent.
59
90
  Lint/FloatOutOfRange:
60
91
  Enabled: true
@@ -81,10 +112,21 @@ Lint/LiteralAsCondition:
81
112
  Lint/LiteralInInterpolation:
82
113
  Enabled: true
83
114
 
84
- # This cop checks for uses of *begin...end while/until something*.
115
+ # Checks for uses of *begin...end while/until something*.
85
116
  Lint/Loop:
86
117
  Enabled: false
87
118
 
119
+ # Checks for the presence of constructors and lifecycle callbacks without calls to super.
120
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintmissingsuper
121
+ Lint/MissingSuper:
122
+ Enabled: false
123
+
124
+ # Do not mix named captures and numbered captures in a Regexp literal
125
+ # because numbered capture is ignored if they’re mixed.
126
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintmixedregexpcapturetypes
127
+ Lint/MixedRegexpCaptureTypes:
128
+ Enabled: true
129
+
88
130
  # Do not use nested method definitions.
89
131
  Lint/NestedMethodDefinition:
90
132
  Enabled: true
@@ -93,6 +135,11 @@ Lint/NestedMethodDefinition:
93
135
  Lint/NextWithoutAccumulator:
94
136
  Enabled: true
95
137
 
138
+ # Looks for references of Regexp captures that are out of range and thus always returns nil.
139
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintoutofrangeregexpref
140
+ Lint/OutOfRangeRegexpRef:
141
+ Enabled: true
142
+
96
143
  # Checks for method calls with a space before the opening parenthesis.
97
144
  Lint/ParenthesesAsGroupedExpression:
98
145
  Enabled: true
@@ -126,6 +173,11 @@ Lint/RescueException:
126
173
  Lint/SafeNavigationWithEmpty:
127
174
  Enabled: true
128
175
 
176
+ # Checks for self-assignments.
177
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintselfassignment
178
+ Lint/SelfAssignment:
179
+ Enabled: true
180
+
129
181
  # Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception.
130
182
  Lint/ShadowedException:
131
183
  Enabled: false
@@ -143,6 +195,11 @@ Lint/StructNewOverride:
143
195
  Lint/SuppressedException:
144
196
  Enabled: false
145
197
 
198
+ # Checks for top level return with arguments.
199
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#linttoplevelreturnwithargument
200
+ Lint/TopLevelReturnWithArgument:
201
+ Enabled: true
202
+
146
203
  # Do not use prefix `_` for a variable that is used.
147
204
  Lint/UnderscorePrefixedVariableName:
148
205
  Enabled: true
@@ -155,6 +212,11 @@ Lint/UnifiedInteger:
155
212
  Lint/UnreachableCode:
156
213
  Enabled: true
157
214
 
215
+ # Checks for loops that will have at most one iteration.
216
+ # https://docs.rubocop.org/rubocop/0.89/cops_lint.html#lintunreachableloop
217
+ Lint/UnreachableLoop:
218
+ Enabled: true
219
+
158
220
  # This cop checks for unused block arguments.
159
221
  Lint/UnusedBlockArgument:
160
222
  Enabled: false
@@ -172,10 +234,6 @@ Lint/UselessAccessModifier:
172
234
  Lint/UselessAssignment:
173
235
  Enabled: true
174
236
 
175
- # Checks for comparison of something with itself.
176
- Lint/UselessComparison:
177
- Enabled: true
178
-
179
237
  # Checks for useless `else` in `begin..end` without `rescue`.
180
238
  Lint/UselessElseWithoutRescue:
181
239
  Enabled: true
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # A calculated magnitude based on number of assignments,
2
3
  # branches, and conditions.
3
4
  Metrics/AbcSize:
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Checks for methods that may lead to batch type issues on a table that's been
2
3
  # explicitly denied because of its size.
3
4
  #
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Check the naming of accessor methods for get_/set_.
2
3
  Naming/AccessorMethodName:
3
4
  Enabled: false
@@ -1,3 +1,15 @@
1
+ ---
2
+ # Used to identify usages of ancestors.include? and change them to use ⇐ instead.
3
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performanceancestorsinclude
4
+ Performance/AncestorsInclude:
5
+ Enabled: true
6
+
7
+ # Identifies places where numeric argument to BigDecimal should be converted to string.
8
+ # Initializing from String is faster than from Numeric for BigDecimal.
9
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancebigdecimalwithnumericargument
10
+ Performance/BigDecimalWithNumericArgument:
11
+ Enabled: true
12
+
1
13
  # Use `caller(n..n)` instead of `caller`.
2
14
  Performance/Caller:
3
15
  Enabled: false
@@ -31,17 +43,53 @@ Performance/RedundantMerge:
31
43
  Enabled: true
32
44
  MaxKeyValuePairs: 1
33
45
 
46
+ # Identifies places where sort { |a, b| a <=> b } can be replaced with sort.
47
+ # https://docs.rubocop.org/rubocop-performance/1.7/cops_performance.html#performanceredundantsortblock
48
+ Performance/RedundantSortBlock:
49
+ Enabled: true
50
+
51
+ # Checks for redundant String#chars.
52
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performanceredundantstringchars
53
+ Performance/RedundantStringChars:
54
+ Enabled: true
55
+
56
+ # Identifies places where reverse.first(n) and reverse.first can be replaced by last(n).reverse and last.
57
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancereversefirst
58
+ Performance/ReverseFirst:
59
+ Enabled: true
60
+
61
+ # Identifies places where sort { |a, b| b <=> a } can be replaced by a faster sort.reverse.
62
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancesortreverse
63
+ Performance/SortReverse:
64
+ Enabled: true
65
+
66
+ # Identifies places where gsub(/a+/, 'a') and gsub!(/a+/, 'a') can be replaced by squeeze('a') and squeeze!('a').
67
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancesqueeze
68
+ Performance/Squeeze:
69
+ Enabled: true
70
+
34
71
  # Use `start_with?` instead of a regex match anchored to the beginning of a
35
72
  # string.
36
73
  Performance/StartWith:
37
74
  Enabled: true
38
75
 
76
+ # Identifies unnecessary use of a regex where String#include? would suffice.
77
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancestringinclude
78
+ Performance/StringInclude:
79
+ Enabled: true
80
+
39
81
  # Use `tr` instead of `gsub` when you are replacing the same number of
40
82
  # characters. Use `delete` instead of `gsub` when you are deleting
41
83
  # characters.
42
84
  Performance/StringReplacement:
43
85
  Enabled: true
44
86
 
87
+ # Identifies places where custom code finding the sum of elements in some
88
+ # Enumerable object can be replaced by Enumerable#sum method.
89
+ # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancesum
90
+ Performance/Sum:
91
+ Enabled: true
92
+
45
93
  # Checks for `.times.map` calls.
46
94
  Performance/TimesMap:
47
95
  Enabled: true
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Enables Rails cops.
2
3
  Rails:
3
4
  Enabled: true
@@ -7,6 +8,18 @@ Rails/ActionFilter:
7
8
  Enabled: true
8
9
  EnforcedStyle: action
9
10
 
11
+ # Checks that Active Record callbacks are declared in the order in which they will be executed.
12
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsactiverecordcallbacksorder
13
+ Rails/ActiveRecordCallbacksOrder:
14
+ Enabled: true
15
+
16
+ # Enforces that there is only one call to after_commit
17
+ # (and its aliases - after_create_commit, after_update_commit, and after_destroy_commit)
18
+ # with the same callback name per model.
19
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsaftercommitoverride
20
+ Rails/AfterCommitOverride:
21
+ Enabled: true
22
+
10
23
  # Check that models subclass ApplicationRecord.
11
24
  Rails/ApplicationRecord:
12
25
  Enabled: false
@@ -43,6 +56,12 @@ Rails/FindBy:
43
56
  - 'app/**/*.rb'
44
57
  - 'lib/**/*.rb'
45
58
 
59
+ # Enforces that ActiveRecord#find is used instead of where.take!, find_by!, and find_by_id!
60
+ # to retrieve a single record by primary key when you expect it to be found.
61
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsfindbyid
62
+ Rails/FindById:
63
+ Enabled: true
64
+
46
65
  # Prefer `all.find_each` over `all.find`.
47
66
  Rails/FindEach:
48
67
  Enabled: true
@@ -57,6 +76,26 @@ Rails/HasAndBelongsToMany:
57
76
  Rails/HttpPositionalArguments:
58
77
  Enabled: true
59
78
 
79
+ # Checks that Active Support’s inquiry method is not used.
80
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsinquiry
81
+ Rails/Inquiry:
82
+ Enabled: true
83
+
84
+ # Enforces that mailer names end with Mailer suffix.
85
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsmailername
86
+ Rails/MailerName:
87
+ Enabled: true
88
+
89
+ # Identifies places where defining routes with match can be replaced with a specific HTTP method.
90
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsmatchroute
91
+ Rails/MatchRoute:
92
+ Enabled: true
93
+
94
+ # Enforces the use of collection.exclude?(obj) over !collection.include?(obj).
95
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsnegateinclude
96
+ Rails/NegateInclude:
97
+ Enabled: true
98
+
60
99
  # Checks for calls to puts, print, etc.
61
100
  Rails/Output:
62
101
  Enabled: true
@@ -71,6 +110,16 @@ Rails/Output:
71
110
  Rails/OutputSafety:
72
111
  Enabled: false
73
112
 
113
+ # Enforces the use of pluck over map.
114
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railspluck
115
+ Rails/Pluck:
116
+ Enabled: true
117
+
118
+ # Identifies places where pluck is used in where query methods and can be replaced with select.
119
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railspluckinwhere
120
+ Rails/PluckInWhere:
121
+ Enabled: true
122
+
74
123
  # Checks for incorrect grammar when using methods like `3.day.ago`.
75
124
  Rails/PluralizationGrammar:
76
125
  Enabled: true
@@ -87,10 +136,30 @@ Rails/ReadWriteAttribute:
87
136
  Rails/RelativeDateConstant:
88
137
  Enabled: false
89
138
 
139
+ # Looks for inline rendering within controller actions.
140
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsrenderinline
141
+ Rails/RenderInline:
142
+ Enabled: true
143
+
144
+ # Identifies places where render text: can be replaced with render plain:.
145
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsrenderplaintext
146
+ Rails/RenderPlainText:
147
+ Enabled: true
148
+
90
149
  # Checks the arguments of ActiveRecord scopes.
91
150
  Rails/ScopeArgs:
92
151
  Enabled: true
93
152
 
153
+ # Enforces that short forms of I18n methods are used: t instead of translate and l instead of localize.
154
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railsshorti18n
155
+ Rails/ShortI18n:
156
+ Enabled: true
157
+
158
+ # Checks SQL heredocs to use .squish.
159
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railssquishedsqlheredocs
160
+ Rails/SquishedSQLHeredocs:
161
+ Enabled: true
162
+
94
163
  # This cop checks for the use of Time methods without zone.
95
164
  Rails/TimeZone:
96
165
  Enabled: false
@@ -98,3 +167,13 @@ Rails/TimeZone:
98
167
  # This cop checks for the use of old-style attribute validation macros.
99
168
  Rails/Validation:
100
169
  Enabled: true
170
+
171
+ # Enforces consistent style when using exists?.
172
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railswhereexists
173
+ Rails/WhereExists:
174
+ Enabled: true
175
+
176
+ # Identifies places where manually constructed SQL in where can be replaced with where.not(...).
177
+ # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railswherenot
178
+ Rails/WhereNot:
179
+ Enabled: true
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # Check that instances are not being stubbed globally.
2
3
  RSpec/AnyInstance:
3
4
  Enabled: false
@@ -36,6 +37,14 @@ RSpec/EmptyExampleGroup:
36
37
  - it_should_email!
37
38
  - it_should_not_email!
38
39
 
40
+ # Checks if there is an empty line after let blocks.
41
+ RSpec/EmptyLineAfterLetBlock:
42
+ Enabled: true
43
+
44
+ # Checks if there is an empty line after shared example blocks.
45
+ RSpec/EmptyLineAfterSharedExample:
46
+ Enabled: true
47
+
39
48
  # Checks for long example.
40
49
  RSpec/ExampleLength:
41
50
  Enabled: false
@@ -134,6 +143,11 @@ RSpec/SingleLineHook:
134
143
  - 'spec/factories/*'
135
144
  - 'spec/requests/api/v3/*'
136
145
 
146
+ # Checks that message expectations do not have a configured response.
147
+ # https://docs.rubocop.org/rubocop-rspec/1.44/cops_rspec.html#rspecstubbedmock
148
+ RSpec/StubbedMock:
149
+ Enabled: false
150
+
137
151
  # Checks for stubbed test subjects.
138
152
  RSpec/SubjectStub:
139
153
  Enabled: false
@@ -1,3 +1,4 @@
1
+ ---
1
2
  # This cop checks for the use of JSON class methods which have potential
2
3
  # security issues.
3
4
  Security/JSONLoad: