gitlab-styles 10.0.0 → 10.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be58fa1f46b81e0e8a73c3c85843048680518c23e846bcf54a1df301c53cfa18
4
- data.tar.gz: 95f2466fb2ae6f5dcfcfce8b7e9343101588b9627f0c9c061c53beac597126e9
3
+ metadata.gz: 0cd204f5572b14a03cd4f6faec35d9973f07dcab0579cf17ebb5fc10d56ac6b0
4
+ data.tar.gz: 7a126190155bc1b39eea832c88e4636306f0fafb09f4b6c2c12c9fb275032a8c
5
5
  SHA512:
6
- metadata.gz: cb13dbe44128173fc03b4dddf53cfdfb67a6e8d37ffc6f4c32a4e30c33ead6e686b6023c2cff9fe7fbf95600d518b508fb9b9b68ffbb07dc8686765f65f3f638
7
- data.tar.gz: 6a2774df245a7c42725e8989a8683b4953d91f70f059c0ceb41450b1c305b375f4e150ecb9418a56f60833ce166eca335ce94ba3a03fb7cf29575c7b72cbd54f
6
+ metadata.gz: ef80fd1223c28800de324bb2e71bc1c4e381137ddf7e4a4605e7d1e6e301cca3fc5cee69146a80fe23213a77c8c459d7037e305372242702d4cc8c9bb2b08c0b
7
+ data.tar.gz: 4f60365ef4232d584eb8ec18f99f8ac5537bd4bf933777d5125c4fb2f71423e7c487dd61f18e9e4e40738c4d02949d9291d7fda7a66fa88442bcdeb8854621c0
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
+ /_yardoc/
1
2
  /.bundle/
3
+ /.byebug_history
2
4
  /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
5
  /coverage/
6
6
  /pkg/
7
7
  /spec/reports/
@@ -11,4 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  # Ignore IDE specific files
14
- .idea/
14
+ .idea/
@@ -1,13 +1,26 @@
1
- <!-- Replace `<PREVIOUS_VERSION>` with the previous version number here, `<COMMIT_UPDATING_VERSION>` with the latest
1
+ <!-- Replace `<PREVIOUS_VERSION>` with the previous version number, `<COMMIT_UPDATING_VERSION>` with the latest
2
2
  commit from this merge request, and `<NEW_VERSION>` with the upcoming version number. -->
3
3
  ## Diff
4
4
 
5
- https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/compare/v<PREVIOUS_VERSION>...<COMMIT_UPDATING_VERSION>
5
+ https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/compare/v<PREVIOUS_VERSION>...<COMMIT_UPDATING_VERSION>
6
6
 
7
7
  ## Checklist
8
8
 
9
- - [ ] Diff link is up-to-date.
10
- - [ ] Check the release notes: https://gitlab.com/api/v4/projects/4176070/repository/changelog?version=<NEW_VERSION>
11
- - [ ] Based on the diff and the release notes, `version.rb` is updated, according to [SemVer](https://semver.org).
9
+ - [ ] Change the `VERSION` constant to a minor version in `lib/gitlab/styles/version.rb` (you might have to change the version number in the next steps according to [SemVer](https://semver.org)).
10
+ - [ ] Ensure the diff link above is up-to-date.
11
+ - [ ] Add release notes to the [Changelog](#changelog) section below.
12
+ - [ ] Based on the diff and the release notes, update the `version.rb` according to [SemVer](https://semver.org).
13
+ - [ ] Create an MR on `gitlab-org/gitlab` project [with the `New Version of gitlab-styles.md` template](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/merge_request_templates/New%20Version%20of%20gitlab-styles.md) to test the new version of `gitlab-styles`, and follow the MR instructions.
14
+
15
+ ## Changelog
16
+
17
+ <!--
18
+ Paste output of:
19
+
20
+ curl https://gitlab.com/api/v4/projects/4176070/repository/changelog?version=<NEW_VERSION> | jq -r ".notes"
21
+
22
+ NOTE: Skip `v` in `<NEW_VERSION>`. For example, Use `version=10.0.0` instead of `version=v10.0.0`.
23
+
24
+ -->
12
25
 
13
26
  /label ~"type::maintenance" ~"static code analysis"
data/.gitlab-ci.yml CHANGED
@@ -10,6 +10,9 @@ default:
10
10
  - bundle --version
11
11
  - bundle install
12
12
 
13
+ variables:
14
+ BUNDLE_FROZEN: 'true'
15
+
13
16
  workflow:
14
17
  rules:
15
18
  # For merge requests, create a pipeline.
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  inherit_from:
2
- - .rubocop_todo.yml
3
2
  - rubocop-default.yml
3
+ - .rubocop_todo.yml
4
4
 
5
5
  require:
6
6
  - rubocop/cop/internal_affairs
@@ -9,6 +9,10 @@ require:
9
9
  AllCops:
10
10
  NewCops: disable # https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/issues/40
11
11
 
12
+ Gemspec/DevelopmentDependencies:
13
+ EnforcedStyle: gemspec
14
+ Enabled: true
15
+
12
16
  InternalAffairs/DeprecateCopHelper:
13
17
  Enabled: true
14
18
  Include:
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-01-11 12:59:00 UTC using RuboCop version 1.43.0.
3
+ # on 2023-06-05 10:15:47 UTC using RuboCop version 1.50.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -10,3 +10,27 @@
10
10
  InternalAffairs/InheritDeprecatedCopClass:
11
11
  Exclude:
12
12
  - 'lib/rubocop/cop/gitlab_security/json_serialization.rb'
13
+
14
+ # Offense count: 11
15
+ InternalAffairs/MissingCopDepartment:
16
+ Exclude:
17
+ - 'lib/rubocop/cop/active_record_dependent.rb'
18
+ - 'lib/rubocop/cop/active_record_serialize.rb'
19
+ - 'lib/rubocop/cop/avoid_return_from_blocks.rb'
20
+ - 'lib/rubocop/cop/custom_error_class.rb'
21
+ - 'lib/rubocop/cop/gem_fetcher.rb'
22
+ - 'lib/rubocop/cop/in_batches.rb'
23
+ - 'lib/rubocop/cop/line_break_after_guard_clauses.rb'
24
+ - 'lib/rubocop/cop/line_break_around_conditional_block.rb'
25
+ - 'lib/rubocop/cop/polymorphic_associations.rb'
26
+ - 'lib/rubocop/cop/redirect_with_status.rb'
27
+ - 'lib/rubocop/cop/without_reactive_cache.rb'
28
+
29
+ # Offense count: 5
30
+ InternalAffairs/UseRestrictOnSend:
31
+ Exclude:
32
+ - 'lib/rubocop/cop/active_record_dependent.rb'
33
+ - 'lib/rubocop/cop/active_record_serialize.rb'
34
+ - 'lib/rubocop/cop/in_batches.rb'
35
+ - 'lib/rubocop/cop/polymorphic_associations.rb'
36
+ - 'lib/rubocop/cop/without_reactive_cache.rb'
data/Gemfile CHANGED
@@ -4,19 +4,3 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in gitlab-rubocop.gemspec
6
6
  gemspec
7
-
8
- group :development do
9
- gem 'lefthook', require: false
10
- gem 'test_file_finder', '~> 0.1.4'
11
- end
12
-
13
- group :test do
14
- # Pin these dependencies, otherwise a new rule could break the CI pipelines
15
- gem 'rubocop', '1.43.0'
16
- gem 'rubocop-rspec', '2.18.1'
17
- gem 'rspec-parameterized-table_syntax', '1.0.0', require: false
18
-
19
- gem 'simplecov', '~> 0.22.0', require: false
20
- gem 'simplecov-html', '~> 0.12.3', require: false
21
- gem 'simplecov-cobertura', '~> 2.1.0', require: false
22
- end
data/Gemfile.lock ADDED
@@ -0,0 +1,227 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gitlab-styles (10.1.0)
5
+ rubocop (~> 1.50.2)
6
+ rubocop-graphql (~> 0.18)
7
+ rubocop-performance (~> 1.15)
8
+ rubocop-rails (~> 2.17)
9
+ rubocop-rspec (~> 2.22)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (7.0.4.3)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ addressable (2.8.4)
20
+ public_suffix (>= 2.0.2, < 6.0)
21
+ ast (2.4.2)
22
+ binding_of_caller (1.0.0)
23
+ debug_inspector (>= 0.0.1)
24
+ byebug (11.1.3)
25
+ claide (1.1.0)
26
+ claide-plugins (0.9.2)
27
+ cork
28
+ nap
29
+ open4 (~> 1.3)
30
+ coderay (1.1.3)
31
+ colored2 (3.1.2)
32
+ concurrent-ruby (1.2.2)
33
+ cork (0.3.0)
34
+ colored2 (~> 3.1)
35
+ danger (9.3.0)
36
+ claide (~> 1.0)
37
+ claide-plugins (>= 0.9.2)
38
+ colored2 (~> 3.1)
39
+ cork (~> 0.1)
40
+ faraday (>= 0.9.0, < 3.0)
41
+ faraday-http-cache (~> 2.0)
42
+ git (~> 1.13.0)
43
+ kramdown (~> 2.3)
44
+ kramdown-parser-gfm (~> 1.0)
45
+ no_proxy_fix
46
+ octokit (~> 5.0)
47
+ terminal-table (>= 1, < 4)
48
+ danger-gitlab (8.0.0)
49
+ danger
50
+ gitlab (~> 4.2, >= 4.2.0)
51
+ debug_inspector (1.1.0)
52
+ diff-lcs (1.5.0)
53
+ docile (1.4.0)
54
+ faraday (1.10.3)
55
+ faraday-em_http (~> 1.0)
56
+ faraday-em_synchrony (~> 1.0)
57
+ faraday-excon (~> 1.1)
58
+ faraday-httpclient (~> 1.0)
59
+ faraday-multipart (~> 1.0)
60
+ faraday-net_http (~> 1.0)
61
+ faraday-net_http_persistent (~> 1.0)
62
+ faraday-patron (~> 1.0)
63
+ faraday-rack (~> 1.0)
64
+ faraday-retry (~> 1.0)
65
+ ruby2_keywords (>= 0.0.4)
66
+ faraday-em_http (1.0.0)
67
+ faraday-em_synchrony (1.0.0)
68
+ faraday-excon (1.1.0)
69
+ faraday-http-cache (2.5.0)
70
+ faraday (>= 0.8)
71
+ faraday-httpclient (1.0.1)
72
+ faraday-multipart (1.0.4)
73
+ multipart-post (~> 2)
74
+ faraday-net_http (1.0.1)
75
+ faraday-net_http_persistent (1.2.0)
76
+ faraday-patron (1.0.0)
77
+ faraday-rack (1.0.0)
78
+ faraday-retry (1.0.3)
79
+ git (1.13.2)
80
+ addressable (~> 2.8)
81
+ rchardet (~> 1.8)
82
+ gitlab (4.19.0)
83
+ httparty (~> 0.20)
84
+ terminal-table (>= 1.5.1)
85
+ gitlab-dangerfiles (3.6.7)
86
+ danger (>= 8.4.5)
87
+ danger-gitlab (>= 8.0.0)
88
+ rake
89
+ httparty (0.21.0)
90
+ mini_mime (>= 1.0.0)
91
+ multi_xml (>= 0.5.2)
92
+ i18n (1.13.0)
93
+ concurrent-ruby (~> 1.0)
94
+ json (2.6.3)
95
+ kramdown (2.4.0)
96
+ rexml
97
+ kramdown-parser-gfm (1.1.0)
98
+ kramdown (~> 2.0)
99
+ lefthook (1.3.13)
100
+ method_source (1.0.0)
101
+ mini_mime (1.1.2)
102
+ minitest (5.18.0)
103
+ multi_xml (0.6.0)
104
+ multipart-post (2.3.0)
105
+ nap (1.1.0)
106
+ no_proxy_fix (0.1.2)
107
+ octokit (5.6.1)
108
+ faraday (>= 1, < 3)
109
+ sawyer (~> 0.9)
110
+ open4 (1.3.4)
111
+ parallel (1.23.0)
112
+ parser (3.2.2.1)
113
+ ast (~> 2.4.1)
114
+ proc_to_ast (0.1.0)
115
+ coderay
116
+ parser
117
+ unparser
118
+ pry (0.14.2)
119
+ coderay (~> 1.1)
120
+ method_source (~> 1.0)
121
+ pry-byebug (3.10.1)
122
+ byebug (~> 11.0)
123
+ pry (>= 0.13, < 0.15)
124
+ public_suffix (5.0.1)
125
+ rack (3.0.7)
126
+ rainbow (3.1.1)
127
+ rake (13.0.6)
128
+ rchardet (1.8.0)
129
+ regexp_parser (2.8.0)
130
+ rexml (3.2.5)
131
+ rspec (3.12.0)
132
+ rspec-core (~> 3.12.0)
133
+ rspec-expectations (~> 3.12.0)
134
+ rspec-mocks (~> 3.12.0)
135
+ rspec-core (3.12.2)
136
+ rspec-support (~> 3.12.0)
137
+ rspec-expectations (3.12.3)
138
+ diff-lcs (>= 1.2.0, < 2.0)
139
+ rspec-support (~> 3.12.0)
140
+ rspec-mocks (3.12.5)
141
+ diff-lcs (>= 1.2.0, < 2.0)
142
+ rspec-support (~> 3.12.0)
143
+ rspec-parameterized-core (1.0.0)
144
+ parser
145
+ proc_to_ast
146
+ rspec (>= 2.13, < 4)
147
+ unparser
148
+ rspec-parameterized-table_syntax (1.0.0)
149
+ binding_of_caller
150
+ rspec-parameterized-core (< 2)
151
+ rspec-support (3.12.0)
152
+ rubocop (1.50.2)
153
+ json (~> 2.3)
154
+ parallel (~> 1.10)
155
+ parser (>= 3.2.0.0)
156
+ rainbow (>= 2.2.2, < 4.0)
157
+ regexp_parser (>= 1.8, < 3.0)
158
+ rexml (>= 3.2.5, < 4.0)
159
+ rubocop-ast (>= 1.28.0, < 2.0)
160
+ ruby-progressbar (~> 1.7)
161
+ unicode-display_width (>= 2.4.0, < 3.0)
162
+ rubocop-ast (1.28.1)
163
+ parser (>= 3.2.1.0)
164
+ rubocop-capybara (2.18.0)
165
+ rubocop (~> 1.41)
166
+ rubocop-factory_bot (2.23.0)
167
+ rubocop (~> 1.33)
168
+ rubocop-graphql (0.19.0)
169
+ rubocop (>= 0.87, < 2)
170
+ rubocop-performance (1.17.1)
171
+ rubocop (>= 1.7.0, < 2.0)
172
+ rubocop-ast (>= 0.4.0)
173
+ rubocop-rails (2.19.1)
174
+ activesupport (>= 4.2.0)
175
+ rack (>= 1.1)
176
+ rubocop (>= 1.33.0, < 2.0)
177
+ rubocop-rake (0.6.0)
178
+ rubocop (~> 1.0)
179
+ rubocop-rspec (2.22.0)
180
+ rubocop (~> 1.33)
181
+ rubocop-capybara (~> 2.17)
182
+ rubocop-factory_bot (~> 2.22)
183
+ ruby-progressbar (1.13.0)
184
+ ruby2_keywords (0.0.5)
185
+ sawyer (0.9.2)
186
+ addressable (>= 2.3.5)
187
+ faraday (>= 0.17.3, < 3)
188
+ simplecov (0.22.0)
189
+ docile (~> 1.1)
190
+ simplecov-html (~> 0.11)
191
+ simplecov_json_formatter (~> 0.1)
192
+ simplecov-cobertura (2.1.0)
193
+ rexml
194
+ simplecov (~> 0.19)
195
+ simplecov-html (0.12.3)
196
+ simplecov_json_formatter (0.1.4)
197
+ terminal-table (3.0.2)
198
+ unicode-display_width (>= 1.1.1, < 3)
199
+ test_file_finder (0.1.4)
200
+ faraday (~> 1.0)
201
+ tzinfo (2.0.6)
202
+ concurrent-ruby (~> 1.0)
203
+ unicode-display_width (2.4.2)
204
+ unparser (0.6.7)
205
+ diff-lcs (~> 1.3)
206
+ parser (>= 3.2.0)
207
+
208
+ PLATFORMS
209
+ ruby
210
+
211
+ DEPENDENCIES
212
+ bundler (~> 2.1)
213
+ gitlab-dangerfiles (~> 3.6.7)
214
+ gitlab-styles!
215
+ lefthook (~> 1.3.13)
216
+ pry-byebug (~> 3.10)
217
+ rake (~> 13.0)
218
+ rspec (~> 3.0)
219
+ rspec-parameterized-table_syntax (~> 1.0.0)
220
+ rubocop-rake (~> 0.6)
221
+ simplecov (~> 0.22.0)
222
+ simplecov-cobertura (~> 2.1.0)
223
+ simplecov-html (~> 0.12.3)
224
+ test_file_finder (~> 0.1.4)
225
+
226
+ BUNDLED WITH
227
+ 2.4.13
data/README.md CHANGED
@@ -91,7 +91,6 @@ To release a new version:
91
91
  1. Create a Merge Request.
92
92
  1. Use Merge Request template [Release.md](https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/blob/master/.gitlab/merge_request_templates/Release.md).
93
93
  1. Follow the instructions.
94
- 1. (Optional, but appreciated) Create an MR on `gitlab-org/gitlab` project [with the `New Version of gitlab-styles.md` template](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/merge_request_templates/New%20Version%20of%20gitlab-styles.md) to test the new version of `gitlab-styles`, and follow the MR instructions.
95
94
  1. After the Merge Request has been merged, a new gem version is [published automatically](https://gitlab.com/gitlab-org/quality/pipeline-common/-/blob/master/ci/gem-release.yml)
96
95
 
97
96
  See [!123](https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/merge_requests/123) as an example.
@@ -22,15 +22,22 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'rubocop', '~> 1.43.0'
25
+ spec.add_dependency 'rubocop', '~> 1.50.2'
26
26
  spec.add_dependency 'rubocop-graphql', '~> 0.18'
27
27
  spec.add_dependency 'rubocop-performance', '~> 1.15'
28
28
  spec.add_dependency 'rubocop-rails', '~> 2.17'
29
- spec.add_dependency 'rubocop-rspec', '~> 2.18'
29
+ spec.add_dependency 'rubocop-rspec', '~> 2.22'
30
30
 
31
31
  spec.add_development_dependency 'bundler', '~> 2.1'
32
- spec.add_development_dependency 'gitlab-dangerfiles', '~> 2.11.0'
32
+ spec.add_development_dependency 'gitlab-dangerfiles', '~> 3.6.7'
33
+ spec.add_development_dependency 'lefthook', '~> 1.3.13'
34
+ spec.add_development_dependency 'pry-byebug', '~> 3.10'
33
35
  spec.add_development_dependency 'rake', '~> 13.0'
34
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rspec-parameterized-table_syntax', '~> 1.0.0'
35
38
  spec.add_development_dependency 'rubocop-rake', '~> 0.6'
39
+ spec.add_development_dependency 'simplecov', '~> 0.22.0'
40
+ spec.add_development_dependency 'simplecov-cobertura', '~> 2.1.0'
41
+ spec.add_development_dependency 'simplecov-html', '~> 0.12.3'
42
+ spec.add_development_dependency 'test_file_finder', '~> 0.1.4'
36
43
  end
@@ -7,7 +7,7 @@ module Gitlab
7
7
  module MigrationHelpers
8
8
  # Returns true if the given node originated from the db/migrate directory.
9
9
  def in_migration?(node)
10
- dirname = File.dirname(node.location.expression.source_buffer.name)
10
+ dirname = File.dirname(node.source_range.source_buffer.name)
11
11
 
12
12
  dirname.end_with?(
13
13
  'db/migrate',
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '10.0.0'
5
+ VERSION = '10.1.0'
6
6
  end
7
7
  end
@@ -36,7 +36,7 @@ module Rubocop
36
36
 
37
37
  replacement = "#{class_name_from_node(klass)} = Class.new(#{class_name_from_node(parent)})"
38
38
 
39
- corrector.replace(node.source_range, replacement)
39
+ corrector.replace(node, replacement)
40
40
  end
41
41
  end
42
42
 
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ # Enforces the use of explicit department names for cop rules.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # module RuboCop
11
+ # module Cop
12
+ # class Implicit
13
+ # end
14
+ # end
15
+ # end
16
+ #
17
+ # module RuboCop
18
+ # module Cop
19
+ # module Cop
20
+ # class Explicit
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # # good
27
+ # module RuboCop
28
+ # module Cop
29
+ # module Foo
30
+ # class Implicit
31
+ # end
32
+ # end
33
+ # end
34
+ # end
35
+ #
36
+ # module RuboCop
37
+ # module Cop
38
+ # module Foo
39
+ # class Explicit
40
+ # end
41
+ # end
42
+ # end
43
+ # end
44
+ class MissingCopDepartment < Base
45
+ MSG = 'Define a proper department. Using `Cop/` as department is discourged.'
46
+
47
+ COP_DEPARTMENT = 'Cop'
48
+
49
+ def on_class(node)
50
+ namespace = full_namespace(node)
51
+
52
+ # Skip top-level RuboCop::Cop
53
+ names = namespace.drop(2)
54
+
55
+ add_offense(node.loc.name) if names.size < 2 || names.first == COP_DEPARTMENT
56
+ end
57
+
58
+ private
59
+
60
+ def full_namespace(node)
61
+ (node_namespace(node) + parents_namespace(node)).reverse
62
+ end
63
+
64
+ def node_namespace(node)
65
+ name_parts(node).reverse
66
+ end
67
+
68
+ def parents_namespace(node)
69
+ node
70
+ .each_ancestor(:module, :class)
71
+ .flat_map { |node| name_parts(node) }
72
+ end
73
+
74
+ def name_parts(node)
75
+ node.identifier.source.split('::')
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ # Flags if `RESTRICT_ON_SEND` constant not defined and method name is
7
+ # checked programmatically in `on_send` methods.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # def on_send(node)
12
+ # return unless method_name(node) == :foo
13
+ # return unless node.children[1] == :foo
14
+ # return unless METHOD_NAMES.include?(method_name(node))
15
+ #
16
+ # name = node.children[1]
17
+ # return unless name == :foo
18
+ # name2 = method_name(node)
19
+ # return unless name == :foo
20
+ #
21
+ # # more code
22
+ # end
23
+ #
24
+ # # good
25
+ # RESTRICT_ON_SEND = %i[foo].freeze
26
+ #
27
+ # def on_send(node)
28
+ # # more code
29
+ # end
30
+ #
31
+ # # ignored - not `on_send`
32
+ # def on_def(node)
33
+ # return unless method_name(node) == :foo
34
+ # end
35
+ #
36
+ # # ignored - `else` branch
37
+ # def on_send(node)
38
+ # if method_name(node) == :foo
39
+ # add_offense(node)
40
+ # else
41
+ # something_else
42
+ # end
43
+ # end
44
+ class UseRestrictOnSend < Base
45
+ MSG = 'Define constant `RESTRICT_ON_SEND` to speed up calls to `on_send`. ' \
46
+ 'The following line is then no longer necessary:'
47
+
48
+ # @!method method_name_plain(node)
49
+ def_node_matcher :method_name_plain, <<~PATTERN
50
+ {
51
+ (send _ :method_name _ ...) # method_name(node)
52
+ (send
53
+ (send _ :children) :[] (int 1) # node.children[1]
54
+ )
55
+ }
56
+ PATTERN
57
+
58
+ # @!method method_name_call(node)
59
+ def_node_matcher :method_name_call, <<~PATTERN
60
+ {
61
+ #method_name_plain
62
+ (lvar %1)
63
+ }
64
+ PATTERN
65
+
66
+ # @!method method_name_assignment(node)
67
+ def_node_search :method_name_assignment, <<~PATTERN
68
+ (lvasgn $_name #method_name_plain)
69
+ PATTERN
70
+
71
+ # @!method method_name_check(node)
72
+ def_node_search :method_name_check, <<~PATTERN
73
+ (if
74
+ ${
75
+ (send #method_name_call(%1) {:== :!=} _) # method_name(node) == foo
76
+ (send _ :include? #method_name_call(%1)) # a.include?(method_name(node))
77
+ }
78
+ {!nil? nil? | nil? !nil?} # has either `if` or `else` branch - not both
79
+ )
80
+ PATTERN
81
+
82
+ def on_def(node)
83
+ return unless node.method?(:on_send)
84
+ return if @restrict_on_send_set
85
+
86
+ local_assignments = method_name_assignment(node).to_set
87
+
88
+ method_name_check(node, local_assignments) do |call_node|
89
+ add_offense(call_node)
90
+ end
91
+ end
92
+
93
+ def on_casgn(node)
94
+ @restrict_on_send_set = true if node.name == :RESTRICT_ON_SEND
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -71,7 +71,7 @@ module Rubocop
71
71
  return if next_line(node).blank? || clause_last_line?(next_line(node)) || guard_clause?(next_sibling(node))
72
72
 
73
73
  add_offense(node) do |corrector|
74
- corrector.insert_after(node.loc.expression, "\n")
74
+ corrector.insert_after(node, "\n")
75
75
  end
76
76
  end
77
77
 
@@ -125,7 +125,7 @@ module Rubocop
125
125
  end
126
126
 
127
127
  def in_haml?(node)
128
- node.location.expression.source_buffer.name.end_with?('.haml.rb')
128
+ node.source_range.source_buffer.name.end_with?('.haml.rb')
129
129
  end
130
130
  end
131
131
  end
@@ -44,8 +44,15 @@ module Rubocop
44
44
  MSG = 'Add an empty line after `%<example>s` block.'
45
45
 
46
46
  # @!method shared_examples(node)
47
- def_node_matcher :shared_examples,
48
- block_pattern('{#SharedGroups.all #Includes.all}')
47
+ def_node_matcher :shared_examples, <<~PATTERN
48
+ {
49
+ (block (send #rspec? #SharedGroups.all ...) ...)
50
+ {
51
+ (block (send nil? #Includes.all ...) ...)
52
+ (send nil? #Includes.all ...)
53
+ }
54
+ }
55
+ PATTERN
49
56
 
50
57
  def on_block(node)
51
58
  shared_examples(node) do
@@ -77,7 +77,7 @@ module Rubocop
77
77
  end
78
78
 
79
79
  def docstring(node)
80
- expr = node.loc.expression
80
+ expr = node.source_range
81
81
 
82
82
  Parser::Source::Range.new(
83
83
  expr.source_buffer,
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop-rspec'
4
+ require_relative '../base'
5
+
6
+ module Rubocop
7
+ module Cop
8
+ module RSpec
9
+ module FactoryBot
10
+ # Check for create_list FactoryBot declarations higher than configured MaxAmount.
11
+ #
12
+ # @example MaxAmount: 20
13
+ # We do not allow more than 20 items to be created.
14
+ #
15
+ # # bad
16
+ # create_list(:merge_request, 1000, state: :opened)
17
+ #
18
+ # # good
19
+ # create_list(:merge_request, 15, state: :opened)
20
+ #
21
+ # @example
22
+ # We do not allow more than 10 items to be created (default)
23
+ # # bad
24
+ # create_list(:merge_request, 1000, state: :opened)
25
+ #
26
+ # # good
27
+ # create_list(:merge_request, 10, state: :opened)
28
+ #
29
+ class ExcessiveCreateList < Base
30
+ MESSAGE = 'Avoid using `create_list` with more than %{max_amount} items.'
31
+
32
+ # @!method create_list?(node)
33
+ def_node_matcher :create_list?, <<~PATTERN
34
+ (send nil? :create_list (sym ...) $(int _) ...)
35
+ PATTERN
36
+
37
+ RESTRICT_ON_SEND = %i[create_list].freeze
38
+
39
+ def on_send(node)
40
+ number_node = create_list?(node)
41
+ return unless number_node
42
+
43
+ max_amount = cop_config['MaxAmount']
44
+ return if number_node.value <= max_amount
45
+
46
+ add_offense(number_node, message: format(MESSAGE, max_amount: max_amount))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module RSpec
8
+ # Flags useless dynamic hook/let definitions via `.each`, `.each_key`, or
9
+ # `.each_value` without defining a wrapping `context` explicitly inside
10
+ # the loop block. Without it, the let definition will always/only be set
11
+ # to the final value.
12
+ #
13
+ # @example
14
+ #
15
+ # # bad
16
+ # context 'foo' do
17
+ # [true, false].each do |bool|
18
+ # before do
19
+ # stub_something(bool: bool)
20
+ # end
21
+ #
22
+ # let(:foo) { build(:model, bool: bool) }
23
+ #
24
+ # it 'works' do
25
+ # # `bool` is always `false`
26
+ # end
27
+ # end
28
+ # end
29
+ #
30
+ # # good
31
+ # context 'foo' do
32
+ # [true, false].each do |bool|
33
+ # context "with bool #{bool}" do # <--
34
+ # before do
35
+ # stub_something(bool: bool)
36
+ # end
37
+ #
38
+ # let(:foo) { build(:model, bool: bool) }
39
+ #
40
+ # it 'works' do
41
+ # # `bool` is `true` and then `false`
42
+ # end
43
+ # end
44
+ # end
45
+ # end
46
+ class UselessDynamicDefinition < Base
47
+ MSG = 'Avoid useless dynamic definitions without `context`.'
48
+
49
+ RESTRICT_ON_SEND = %i[each each_key each_value].freeze
50
+
51
+ def on_send(node)
52
+ return unless dynamic_definition?(node.parent)
53
+
54
+ add_offense(node.loc.selector)
55
+ end
56
+
57
+ private
58
+
59
+ def dynamic_definition?(node)
60
+ group = RuboCop::RSpec::ExampleGroup.new(node)
61
+
62
+ group.lets.any? || group.hooks.any?
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -42,7 +42,7 @@ module Rubocop
42
42
  invalid_metadata_matches(node) do |match|
43
43
  add_offense(node, message: format(MSG, good(match), bad(match))) do |corrector|
44
44
  invalid_metadata_matches(node) do |match|
45
- corrector.replace(match.loc.expression, good(match))
45
+ corrector.replace(match, good(match))
46
46
  end
47
47
  end
48
48
  end
data/rubocop-default.yml CHANGED
@@ -13,6 +13,7 @@ inherit_from:
13
13
  - rubocop-fips.yml
14
14
  - rubocop-gemspec.yml
15
15
  - rubocop-graphql.yml
16
+ - rubocop-internal-affairs.yml
16
17
  - rubocop-layout.yml
17
18
  - rubocop-lint.yml
18
19
  - rubocop-metrics.yml
@@ -23,6 +24,3 @@ inherit_from:
23
24
  - rubocop-rspec.yml
24
25
  - rubocop-security.yml
25
26
  - rubocop-style.yml
26
-
27
- InternalAffairs/DeprecateCopHelper:
28
- Enabled: false
data/rubocop-gemspec.yml CHANGED
@@ -4,3 +4,9 @@
4
4
  Gemspec/OrderedDependencies:
5
5
  Include:
6
6
  - '**/*.gemspec'
7
+
8
+ # Enforce that development dependencies for a gem are specified in Gemfile,
9
+ # rather than in the gemspec using add_development_dependency
10
+ # Reason: Each project may decide to use a different strategy.
11
+ Gemspec/DevelopmentDependencies:
12
+ Enabled: false
@@ -0,0 +1,11 @@
1
+ ---
2
+ require:
3
+ - ./lib/gitlab/styles/rubocop
4
+
5
+ InternalAffairs/DeprecateCopHelper:
6
+ Include:
7
+ - 'spec/rubocop/**/*.rb'
8
+
9
+ InternalAffairs/MissingCopDepartment:
10
+ Include:
11
+ - 'lib/rubocop/cop/**/*.rb'
data/rubocop-lint.yml CHANGED
@@ -27,10 +27,11 @@ Lint/AmbiguousRange:
27
27
  Lint/AmbiguousRegexpLiteral:
28
28
  Enabled: true
29
29
 
30
- # This cop checks for assignments in the conditions of
31
- # if/while/until.
30
+ # This cop checks for assignments in the conditions of if/while/until.
31
+ # Forbid assignments within conditions.
32
32
  Lint/AssignmentInCondition:
33
- Enabled: false
33
+ Enabled: true
34
+ AllowSafeAssignment: false
34
35
 
35
36
  # Checks for places where binary operator has identical operands
36
37
  Lint/BinaryOperatorWithIdenticalOperands:
data/rubocop-rails.yml CHANGED
@@ -140,7 +140,7 @@ Rails/Output:
140
140
  # This cop checks for the use of output safety calls like html_safe and
141
141
  # raw.
142
142
  Rails/OutputSafety:
143
- Enabled: false
143
+ Enabled: true
144
144
 
145
145
  # Enforces the use of pluck over map.
146
146
  # https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railspluck
@@ -196,6 +196,13 @@ Rails/SquishedSQLHeredocs:
196
196
  Rails/TimeZone:
197
197
  Enabled: false
198
198
 
199
+ # Checks for the use of exit statements (namely return, break and throw) in
200
+ # transactions. This is due to the eventual unexpected behavior when using
201
+ # ActiveRecord >= 7, where transactions exited using these statements are being
202
+ # rollbacked rather than committed (pre ActiveRecord 7 behavior).
203
+ Rails/TransactionExitStatement:
204
+ Enabled: true
205
+
199
206
  # This cop checks for the use of old-style attribute validation macros.
200
207
  Rails/Validation:
201
208
  Enabled: true
data/rubocop-rspec.yml CHANGED
@@ -2,6 +2,11 @@
2
2
  require:
3
3
  - ./lib/gitlab/styles/rubocop
4
4
 
5
+ # Check for create_list FactoryBot declarations higher than MaxAmount
6
+ RSpec/FactoryBot/ExcessiveCreateList:
7
+ Enabled: true
8
+ MaxAmount: 10
9
+
5
10
  # Check that instances are not being stubbed globally.
6
11
  RSpec/AnyInstance:
7
12
  Enabled: false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-styles
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-10 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.43.0
19
+ version: 1.50.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.43.0
26
+ version: 1.50.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-graphql
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.18'
75
+ version: '2.22'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.18'
82
+ version: '2.22'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,42 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 2.11.0
103
+ version: 3.6.7
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 2.11.0
110
+ version: 3.6.7
111
+ - !ruby/object:Gem::Dependency
112
+ name: lefthook
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.13
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.3.13
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.10'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.10'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: rake
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +164,20 @@ dependencies:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
166
  version: '3.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec-parameterized-table_syntax
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 1.0.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 1.0.0
139
181
  - !ruby/object:Gem::Dependency
140
182
  name: rubocop-rake
141
183
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +192,62 @@ dependencies:
150
192
  - - "~>"
151
193
  - !ruby/object:Gem::Version
152
194
  version: '0.6'
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.22.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.22.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: simplecov-cobertura
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 2.1.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 2.1.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: simplecov-html
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 0.12.3
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.12.3
237
+ - !ruby/object:Gem::Dependency
238
+ name: test_file_finder
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 0.1.4
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 0.1.4
153
251
  description:
154
252
  email:
155
253
  - gitlab_rubygems@gitlab.com
@@ -171,6 +269,7 @@ files:
171
269
  - CONTRIBUTING.md
172
270
  - Dangerfile
173
271
  - Gemfile
272
+ - Gemfile.lock
174
273
  - LICENSE.md
175
274
  - README.md
176
275
  - Rakefile
@@ -201,6 +300,8 @@ files:
201
300
  - lib/rubocop/cop/gitlab_security/system_command_injection.rb
202
301
  - lib/rubocop/cop/in_batches.rb
203
302
  - lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb
303
+ - lib/rubocop/cop/internal_affairs/missing_cop_department.rb
304
+ - lib/rubocop/cop/internal_affairs/use_restrict_on_send.rb
204
305
  - lib/rubocop/cop/line_break_after_guard_clauses.rb
205
306
  - lib/rubocop/cop/line_break_around_conditional_block.rb
206
307
  - lib/rubocop/cop/migration/update_large_table.rb
@@ -212,8 +313,10 @@ files:
212
313
  - lib/rubocop/cop/rspec/empty_line_after_let_block.rb
213
314
  - lib/rubocop/cop/rspec/empty_line_after_shared_example.rb
214
315
  - lib/rubocop/cop/rspec/example_starting_character.rb
316
+ - lib/rubocop/cop/rspec/factory_bot/excessive_create_list.rb
215
317
  - lib/rubocop/cop/rspec/have_link_parameters.rb
216
318
  - lib/rubocop/cop/rspec/single_line_hook.rb
319
+ - lib/rubocop/cop/rspec/useless_dynamic_definition.rb
217
320
  - lib/rubocop/cop/rspec/verbose_include_metadata.rb
218
321
  - lib/rubocop/cop/style/hash_transformation.rb
219
322
  - lib/rubocop/cop/style/open_struct_use.rb
@@ -226,6 +329,7 @@ files:
226
329
  - rubocop-fips.yml
227
330
  - rubocop-gemspec.yml
228
331
  - rubocop-graphql.yml
332
+ - rubocop-internal-affairs.yml
229
333
  - rubocop-layout.yml
230
334
  - rubocop-lint.yml
231
335
  - rubocop-metrics.yml