gitlab-styles 11.0.0 → 12.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +41 -24
- data/.rubocop_todo.yml +1 -10
- data/Gemfile.lock +29 -29
- data/README.md +1 -1
- data/gitlab-styles.gemspec +7 -6
- data/lib/gitlab/styles/rubocop.rb +1 -1
- data/lib/gitlab/styles/version.rb +1 -1
- data/lib/rubocop/cop/active_record_dependent.rb +10 -12
- data/lib/rubocop/cop/active_record_serialize.rb +5 -1
- data/lib/rubocop/cop/code_reuse/active_record.rb +1 -1
- data/lib/rubocop/cop/gem_fetcher.rb +1 -1
- data/lib/rubocop/cop/gitlab_security/redirect_to_params_update.rb +1 -1
- data/lib/rubocop/cop/gitlab_security/send_file_params.rb +1 -1
- data/lib/rubocop/cop/gitlab_security/system_command_injection.rb +1 -1
- data/lib/rubocop/cop/in_batches.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/use_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/layout/line_break_after_final_mixin.rb +75 -0
- data/lib/rubocop/cop/migration/update_large_table.rb +2 -2
- data/lib/rubocop/cop/performance/rubyzip.rb +4 -4
- data/lib/rubocop/cop/polymorphic_associations.rb +8 -5
- data/lib/rubocop/cop/style/open_struct_use.rb +2 -2
- data/lib/rubocop/cop/without_reactive_cache.rb +2 -2
- data/rubocop-all.yml +2 -1
- data/rubocop-default.yml +1 -15
- data/rubocop-factory_bot.yml +8 -0
- data/rubocop-graphql.yml +27 -1
- data/rubocop-layout.yml +16 -4
- data/rubocop-minimal.yml +17 -0
- data/rubocop-rspec.yml +1 -5
- metadata +35 -19
- data/lib/rubocop/cop/rspec/factory_bot/excessive_create_list.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5301968fa7603c90e9ed917011c49e4a3124a7c442963e778fcc1f4862c7cf03
|
4
|
+
data.tar.gz: 4b7676b2fcdb2bed6f3be9c8b0505ba04afa5ec008e95b6c980da5ef3a795032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcb7c63e4e3cacd1638d87b2406483d763ecad6dbdb218a3da292f8be56112ca64d0d1596ac108143981d502834f6672e4c9128981edc8b6bd05566c924289f7
|
7
|
+
data.tar.gz: e08bb7c660e85a30ffc64d669363e6b420219745231a5ea7e5524e657ae72c4f6b1fcb00c9d01d31c9bb846c5d8be57db22d8640dff67ae554f76db2092375ae
|
data/.gitlab-ci.yml
CHANGED
@@ -1,44 +1,43 @@
|
|
1
|
+
workflow:
|
2
|
+
rules:
|
3
|
+
# For merge requests, create a pipeline.
|
4
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
5
|
+
# For the default branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
|
6
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
7
|
+
# For tags, create a pipeline.
|
8
|
+
- if: '$CI_COMMIT_TAG'
|
9
|
+
|
1
10
|
stages:
|
2
11
|
- test
|
3
12
|
- deploy
|
4
13
|
|
5
14
|
default:
|
6
|
-
image: "ruby:${RUBY_VERSION}"
|
7
15
|
tags:
|
8
16
|
- gitlab-org
|
17
|
+
|
18
|
+
.base-ruby-job:
|
19
|
+
image: "ruby:${RUBY_VERSION}"
|
9
20
|
before_script:
|
10
21
|
- bundle --version
|
11
|
-
- bundle
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
workflow:
|
17
|
-
rules:
|
18
|
-
# For merge requests, create a pipeline.
|
19
|
-
- if: '$CI_MERGE_REQUEST_IID'
|
20
|
-
# For the default branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
|
21
|
-
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
22
|
-
# For tags, create a pipeline.
|
23
|
-
- if: '$CI_COMMIT_TAG'
|
22
|
+
- bundle config set --local deployment 'true'
|
23
|
+
- bundle install -j $(nproc)
|
24
|
+
parallel:
|
25
|
+
matrix:
|
26
|
+
- RUBY_VERSION: ['3.0', '3.1', '3.2']
|
24
27
|
|
25
28
|
styles:
|
29
|
+
extends: .base-ruby-job
|
26
30
|
stage: test
|
27
31
|
script:
|
28
32
|
- bundle exec rubocop --debug --parallel
|
29
|
-
parallel:
|
30
|
-
matrix:
|
31
|
-
- RUBY_VERSION: ['2.7', '3.0', '3.1', '3.2']
|
32
33
|
|
33
34
|
specs:
|
35
|
+
extends: .base-ruby-job
|
34
36
|
stage: test
|
35
37
|
script:
|
36
38
|
# Disable simplecov for all Ruby version other than 3.0
|
37
39
|
- if [[ "$RUBY_VERSION" != "3.0" ]]; then export SIMPLECOV=0; fi
|
38
40
|
- bundle exec rspec
|
39
|
-
parallel:
|
40
|
-
matrix:
|
41
|
-
- RUBY_VERSION: ['2.7', '3.0', '3.1', '3.2']
|
42
41
|
artifacts:
|
43
42
|
name: coverage
|
44
43
|
expire_in: 31d
|
@@ -51,7 +50,25 @@ specs:
|
|
51
50
|
path: coverage/coverage.xml
|
52
51
|
|
53
52
|
include:
|
54
|
-
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
- component: gitlab.com/components/sast/sast@~latest
|
54
|
+
- component: gitlab.com/components/secret-detection/secret-detection@~latest
|
55
|
+
- component: gitlab.com/gitlab-org/components/gem-release/gem-release@~latest
|
56
|
+
inputs:
|
57
|
+
smoke_test_script: "ruby -r 'gitlab/styles' -e \"puts Gitlab::Styles::VERSION\""
|
58
|
+
- template: Security/Dependency-Scanning.gitlab-ci.yml
|
59
|
+
- component: gitlab.com/gitlab-org/components/danger-review/danger-review@~latest
|
60
|
+
|
61
|
+
semgrep-sast:
|
62
|
+
rules:
|
63
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
64
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
65
|
+
|
66
|
+
gemnasium-dependency_scanning:
|
67
|
+
rules:
|
68
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
69
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
70
|
+
|
71
|
+
secret_detection:
|
72
|
+
rules:
|
73
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
74
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2024-01-24 13:27:15 UTC using RuboCop version 1.57.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
|
@@ -25,12 +25,3 @@ InternalAffairs/MissingCopDepartment:
|
|
25
25
|
- 'lib/rubocop/cop/polymorphic_associations.rb'
|
26
26
|
- 'lib/rubocop/cop/redirect_with_status.rb'
|
27
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.lock
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gitlab-styles (
|
5
|
-
rubocop (~> 1.
|
6
|
-
rubocop-
|
7
|
-
rubocop-
|
8
|
-
rubocop-
|
9
|
-
rubocop-
|
4
|
+
gitlab-styles (12.0.1)
|
5
|
+
rubocop (~> 1.62.1)
|
6
|
+
rubocop-factory_bot (~> 2.25.1)
|
7
|
+
rubocop-graphql (~> 1.5.0)
|
8
|
+
rubocop-performance (~> 1.20.2)
|
9
|
+
rubocop-rails (~> 2.24.0)
|
10
|
+
rubocop-rspec (~> 2.27.1)
|
10
11
|
|
11
12
|
GEM
|
12
13
|
remote: https://rubygems.org/
|
@@ -19,7 +20,6 @@ GEM
|
|
19
20
|
addressable (2.8.5)
|
20
21
|
public_suffix (>= 2.0.2, < 6.0)
|
21
22
|
ast (2.4.2)
|
22
|
-
base64 (0.1.1)
|
23
23
|
binding_of_caller (1.0.0)
|
24
24
|
debug_inspector (>= 0.0.1)
|
25
25
|
byebug (11.1.3)
|
@@ -92,7 +92,7 @@ GEM
|
|
92
92
|
multi_xml (>= 0.5.2)
|
93
93
|
i18n (1.13.0)
|
94
94
|
concurrent-ruby (~> 1.0)
|
95
|
-
json (2.
|
95
|
+
json (2.7.1)
|
96
96
|
kramdown (2.4.0)
|
97
97
|
rexml
|
98
98
|
kramdown-parser-gfm (1.1.0)
|
@@ -110,8 +110,8 @@ GEM
|
|
110
110
|
faraday (>= 1, < 3)
|
111
111
|
sawyer (~> 0.9)
|
112
112
|
open4 (1.3.4)
|
113
|
-
parallel (1.
|
114
|
-
parser (3.
|
113
|
+
parallel (1.24.0)
|
114
|
+
parser (3.3.0.5)
|
115
115
|
ast (~> 2.4.1)
|
116
116
|
racc
|
117
117
|
proc_to_ast (0.1.0)
|
@@ -125,12 +125,12 @@ GEM
|
|
125
125
|
byebug (~> 11.0)
|
126
126
|
pry (>= 0.13, < 0.15)
|
127
127
|
public_suffix (5.0.3)
|
128
|
-
racc (1.7.
|
128
|
+
racc (1.7.3)
|
129
129
|
rack (3.0.7)
|
130
130
|
rainbow (3.1.1)
|
131
131
|
rake (13.0.6)
|
132
132
|
rchardet (1.8.0)
|
133
|
-
regexp_parser (2.8.
|
133
|
+
regexp_parser (2.8.3)
|
134
134
|
rexml (3.2.6)
|
135
135
|
rspec (3.12.0)
|
136
136
|
rspec-core (~> 3.12.0)
|
@@ -153,37 +153,37 @@ GEM
|
|
153
153
|
binding_of_caller
|
154
154
|
rspec-parameterized-core (< 2)
|
155
155
|
rspec-support (3.12.0)
|
156
|
-
rubocop (1.
|
157
|
-
base64 (~> 0.1.1)
|
156
|
+
rubocop (1.62.1)
|
158
157
|
json (~> 2.3)
|
159
158
|
language_server-protocol (>= 3.17.0)
|
160
159
|
parallel (~> 1.10)
|
161
|
-
parser (>= 3.
|
160
|
+
parser (>= 3.3.0.2)
|
162
161
|
rainbow (>= 2.2.2, < 4.0)
|
163
162
|
regexp_parser (>= 1.8, < 3.0)
|
164
163
|
rexml (>= 3.2.5, < 4.0)
|
165
|
-
rubocop-ast (>= 1.
|
164
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
166
165
|
ruby-progressbar (~> 1.7)
|
167
166
|
unicode-display_width (>= 2.4.0, < 3.0)
|
168
|
-
rubocop-ast (1.
|
169
|
-
parser (>= 3.
|
170
|
-
rubocop-capybara (2.
|
167
|
+
rubocop-ast (1.31.2)
|
168
|
+
parser (>= 3.3.0.4)
|
169
|
+
rubocop-capybara (2.20.0)
|
171
170
|
rubocop (~> 1.41)
|
172
|
-
rubocop-factory_bot (2.
|
173
|
-
rubocop (~> 1.
|
174
|
-
rubocop-graphql (
|
175
|
-
rubocop (>= 0.
|
176
|
-
rubocop-performance (1.
|
177
|
-
rubocop (>= 1.
|
178
|
-
rubocop-ast (>=
|
179
|
-
rubocop-rails (2.
|
171
|
+
rubocop-factory_bot (2.25.1)
|
172
|
+
rubocop (~> 1.41)
|
173
|
+
rubocop-graphql (1.5.0)
|
174
|
+
rubocop (>= 0.90, < 2)
|
175
|
+
rubocop-performance (1.20.2)
|
176
|
+
rubocop (>= 1.48.1, < 2.0)
|
177
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
178
|
+
rubocop-rails (2.24.0)
|
180
179
|
activesupport (>= 4.2.0)
|
181
180
|
rack (>= 1.1)
|
182
181
|
rubocop (>= 1.33.0, < 2.0)
|
182
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
183
183
|
rubocop-rake (0.6.0)
|
184
184
|
rubocop (~> 1.0)
|
185
|
-
rubocop-rspec (2.
|
186
|
-
rubocop (~> 1.
|
185
|
+
rubocop-rspec (2.27.1)
|
186
|
+
rubocop (~> 1.40)
|
187
187
|
rubocop-capybara (~> 2.17)
|
188
188
|
rubocop-factory_bot (~> 2.22)
|
189
189
|
ruby-progressbar (1.13.0)
|
data/README.md
CHANGED
@@ -91,7 +91,7 @@ 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. After the Merge Request has been merged, a new gem version is [published automatically](https://gitlab.com/gitlab-org/
|
94
|
+
1. After the Merge Request has been merged, a new gem version is [published automatically](https://gitlab.com/gitlab-org/components/gem-release).
|
95
95
|
1. Once the new gem version is visible on [RubyGems.org](https://rubygems.org/gems/gitlab-styles), it is recommended to update [GitLab's `Gemfile`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/Gemfile) to bump the `gitlab-styles` Ruby gem to the new version also.
|
96
96
|
|
97
97
|
See [!123](https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/merge_requests/123) as an example.
|
data/gitlab-styles.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'gitlab/styles/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.required_ruby_version = '>=
|
8
|
+
spec.required_ruby_version = '>= 3.0'
|
9
9
|
spec.name = 'gitlab-styles'
|
10
10
|
spec.version = Gitlab::Styles::VERSION
|
11
11
|
spec.authors = ['GitLab']
|
@@ -22,11 +22,12 @@ 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.
|
26
|
-
spec.add_dependency 'rubocop-
|
27
|
-
spec.add_dependency 'rubocop-
|
28
|
-
spec.add_dependency 'rubocop-
|
29
|
-
spec.add_dependency 'rubocop-
|
25
|
+
spec.add_dependency 'rubocop', '~> 1.62.1'
|
26
|
+
spec.add_dependency 'rubocop-factory_bot', '~> 2.25.1'
|
27
|
+
spec.add_dependency 'rubocop-graphql', '~> 1.5.0'
|
28
|
+
spec.add_dependency 'rubocop-performance', '~> 1.20.2'
|
29
|
+
spec.add_dependency 'rubocop-rails', '~> 2.24.0'
|
30
|
+
spec.add_dependency 'rubocop-rspec', '~> 2.27.1'
|
30
31
|
|
31
32
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
32
33
|
spec.add_development_dependency 'gitlab-dangerfiles', '~> 4.6.0'
|
@@ -5,21 +5,19 @@ module Rubocop
|
|
5
5
|
# Cop that prevents the use of `dependent: ...` in ActiveRecord models.
|
6
6
|
class ActiveRecordDependent < RuboCop::Cop::Base
|
7
7
|
MSG = 'Do not use `dependent:` to remove associated data, ' \
|
8
|
-
|
8
|
+
'use foreign keys with cascading deletes instead.'
|
9
9
|
|
10
|
-
|
11
|
-
ALLOWED_OPTIONS = [
|
10
|
+
RESTRICT_ON_SEND = %i[has_many has_one belongs_to].to_set.freeze
|
11
|
+
ALLOWED_OPTIONS = %i[restrict_with_error].freeze
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
key_name = pair.children[0].children[0]
|
18
|
-
option_name = pair.children[1].children[0]
|
13
|
+
# @!method dependent_use(node)
|
14
|
+
def_node_matcher :dependent_use, <<~PATTERN
|
15
|
+
(send _ %RESTRICT_ON_SEND ... (hash <$(pair (sym :dependent) (sym $_)) ...>))
|
16
|
+
PATTERN
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
add_offense(pair)
|
18
|
+
def on_send(node)
|
19
|
+
dependent_use(node) do |pair, value|
|
20
|
+
add_offense(pair) unless ALLOWED_OPTIONS.include?(value)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
@@ -6,8 +6,12 @@ module Rubocop
|
|
6
6
|
class ActiveRecordSerialize < RuboCop::Cop::Base
|
7
7
|
MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'
|
8
8
|
|
9
|
+
RESTRICT_ON_SEND = %i[serialize].freeze
|
10
|
+
|
9
11
|
def on_send(node)
|
10
|
-
|
12
|
+
return if node.receiver
|
13
|
+
|
14
|
+
add_offense(node.loc.selector)
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -6,7 +6,7 @@ module Rubocop
|
|
6
6
|
# Cop that denies the use of ActiveRecord methods outside of models.
|
7
7
|
class ActiveRecord < RuboCop::Cop::Base
|
8
8
|
MSG = 'This method can only be used inside an ActiveRecord model: ' \
|
9
|
-
|
9
|
+
'https://gitlab.com/gitlab-org/gitlab-foss/issues/49653'
|
10
10
|
|
11
11
|
# Various methods from ActiveRecord::Querying that are denied. We
|
12
12
|
# exclude some generic ones such as `any?` and `first`, as these may
|
@@ -7,7 +7,7 @@ module Rubocop
|
|
7
7
|
# rubygems.org.
|
8
8
|
class GemFetcher < RuboCop::Cop::Base
|
9
9
|
MSG = 'Do not use gems from git repositories, only use gems from RubyGems or vendored gems. ' \
|
10
|
-
|
10
|
+
'See https://docs.gitlab.com/ee/development/gemfile.html#no-gems-fetched-from-git-repositories'
|
11
11
|
|
12
12
|
# See https://bundler.io/guides/git.html#custom-git-sources
|
13
13
|
GIT_SOURCES = %i[git github gist bitbucket].freeze
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
17
17
|
#
|
18
18
|
class RedirectToParamsUpdate < RuboCop::Cop::Base
|
19
19
|
MSG = 'Avoid using `redirect_to(params.%<name>s(...))`. ' \
|
20
|
-
|
20
|
+
'Only pass allowed arguments into redirect_to() (e.g. not including `host`)'
|
21
21
|
|
22
22
|
# @!method redirect_to_params_update_node(node)
|
23
23
|
def_node_matcher :redirect_to_params_update_node, <<-PATTERN
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
#
|
22
22
|
class SendFileParams < RuboCop::Cop::Base
|
23
23
|
MSG = 'Do not pass user provided params directly to send_file(), ' \
|
24
|
-
|
24
|
+
'verify the path with file.expand_path() first.'
|
25
25
|
|
26
26
|
# @!method params_node?(node)
|
27
27
|
def_node_search :params_node?, <<-PATTERN
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
#
|
20
20
|
class SystemCommandInjection < RuboCop::Cop::Base
|
21
21
|
MSG = 'Do not include variables in the command name for system(). ' \
|
22
|
-
|
22
|
+
'Use parameters "system(cmd, params)" or exec() instead.'
|
23
23
|
|
24
24
|
# @!method system_var?(node)
|
25
25
|
def_node_matcher :system_var?, <<-PATTERN
|
@@ -6,9 +6,9 @@ module Rubocop
|
|
6
6
|
class InBatches < RuboCop::Cop::Base
|
7
7
|
MSG = 'Do not use `in_batches`, use `each_batch` from the EachBatch module instead'
|
8
8
|
|
9
|
-
|
10
|
-
return unless node.children[1] == :in_batches
|
9
|
+
RESTRICT_ON_SEND = %i[in_batches].freeze
|
11
10
|
|
11
|
+
def on_send(node)
|
12
12
|
add_offense(node.loc.selector)
|
13
13
|
end
|
14
14
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
# end
|
44
44
|
class UseRestrictOnSend < Base
|
45
45
|
MSG = 'Define constant `RESTRICT_ON_SEND` to speed up calls to `on_send`. ' \
|
46
|
-
|
46
|
+
'The following line is then no longer necessary:'
|
47
47
|
|
48
48
|
# @!method method_name_plain(node)
|
49
49
|
def_node_matcher :method_name_plain, <<~PATTERN
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# Checks if there is an empty line after the last include/extend/prepend.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# class Hello
|
11
|
+
# include Something1
|
12
|
+
# include Something2
|
13
|
+
# def world
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
|
17
|
+
# # good
|
18
|
+
# class Hello
|
19
|
+
# include Something1
|
20
|
+
# include Something2
|
21
|
+
#
|
22
|
+
# def world
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
class LineBreakAfterFinalMixin < RuboCop::Cop::Base
|
26
|
+
extend RuboCop::Cop::AutoCorrector
|
27
|
+
|
28
|
+
MSG = 'Add an empty line after the last `%<mixin>s`.'
|
29
|
+
|
30
|
+
MIXIN_METHODS = %i[include extend prepend].to_set.freeze
|
31
|
+
|
32
|
+
# @!method mixin?(node)
|
33
|
+
def_node_matcher :mixin?, <<~PATTERN
|
34
|
+
(send {nil? | self} MIXIN_METHODS ...)
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
def on_class(node)
|
38
|
+
return unless node.body
|
39
|
+
|
40
|
+
mixins = node.body.child_nodes.select { |child| mixin?(child) }
|
41
|
+
|
42
|
+
return if mixins.empty?
|
43
|
+
|
44
|
+
last_mixin = mixins.last
|
45
|
+
|
46
|
+
return if next_line_valid?(last_mixin)
|
47
|
+
|
48
|
+
add_offense(last_mixin, message: format(MSG, mixin: last_mixin.method_name)) do |corrector|
|
49
|
+
corrector.insert_after(last_mixin, "\n")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def next_line_valid?(node)
|
56
|
+
next_line = next_line(node)
|
57
|
+
|
58
|
+
empty_line?(next_line) || end_line?(next_line)
|
59
|
+
end
|
60
|
+
|
61
|
+
def next_line(node)
|
62
|
+
processed_source[node.loc.line]
|
63
|
+
end
|
64
|
+
|
65
|
+
def empty_line?(line)
|
66
|
+
line.empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
def end_line?(line)
|
70
|
+
/^\s*end\b/.match?(line)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -18,8 +18,8 @@ module Rubocop
|
|
18
18
|
include Gitlab::Styles::Rubocop::MigrationHelpers
|
19
19
|
|
20
20
|
MSG = 'Using `%s` on the `%s` table will take a long time to ' \
|
21
|
-
|
22
|
-
|
21
|
+
'complete, and should be avoided unless absolutely ' \
|
22
|
+
'necessary'
|
23
23
|
|
24
24
|
# @!method batch_update?(node)
|
25
25
|
def_node_matcher :batch_update?, <<~PATTERN
|
@@ -13,10 +13,10 @@ module Rubocop
|
|
13
13
|
# - https://github.com/rubyzip/rubyzip#notes-on-zipinputstream
|
14
14
|
class Rubyzip < RuboCop::Cop::Base
|
15
15
|
MSG = 'Be careful when opening or iterating zip files via Zip::File. ' \
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
'Zip archives may contain many entries, and their file index is ' \
|
17
|
+
'read into memory upon construction, which can lead to ' \
|
18
|
+
'high memory use and poor performance. ' \
|
19
|
+
'Consider iterating archive entries via Zip::InputStream instead.'
|
20
20
|
|
21
21
|
# @!method reads_central_directory?(node)
|
22
22
|
def_node_matcher :reads_central_directory?, <<-PATTERN
|
@@ -6,13 +6,16 @@ module Rubocop
|
|
6
6
|
class PolymorphicAssociations < RuboCop::Cop::Base
|
7
7
|
MSG = 'Do not use polymorphic associations, use separate tables instead'
|
8
8
|
|
9
|
-
|
10
|
-
return unless node.children[1] == :belongs_to
|
9
|
+
RESTRICT_ON_SEND = %i[belongs_to].to_set.freeze
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
# @!method polymorphic_pair(node)
|
12
|
+
def_node_matcher :polymorphic_pair, <<~PATTERN
|
13
|
+
(send _ %RESTRICT_ON_SEND ... (hash <$(pair (sym :polymorphic) _) ...>))
|
14
|
+
PATTERN
|
14
15
|
|
15
|
-
|
16
|
+
def on_send(node)
|
17
|
+
polymorphic_pair(node) do |pair|
|
18
|
+
add_offense(pair)
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
@@ -12,8 +12,8 @@ module Rubocop
|
|
12
12
|
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67855
|
13
13
|
class OpenStructUse < RuboCop::Cop::Base
|
14
14
|
MSG = 'Avoid using `OpenStruct`. It is officially discouraged. ' \
|
15
|
-
|
16
|
-
|
15
|
+
'Replace it with `Struct`, `Hash`, or RSpec doubles. ' \
|
16
|
+
'See https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats'
|
17
17
|
|
18
18
|
# @!method uses_open_struct?(node)
|
19
19
|
def_node_matcher :uses_open_struct?, <<-PATTERN
|
@@ -6,9 +6,9 @@ module Rubocop
|
|
6
6
|
class WithoutReactiveCache < RuboCop::Cop::Base
|
7
7
|
MSG = 'without_reactive_cache is for debugging purposes only. Please use with_reactive_cache.'
|
8
8
|
|
9
|
-
|
10
|
-
return unless node.children[1] == :without_reactive_cache
|
9
|
+
RESTRICT_ON_SEND = %i[without_reactive_cache].freeze
|
11
10
|
|
11
|
+
def on_send(node)
|
12
12
|
add_offense(node.loc.selector)
|
13
13
|
end
|
14
14
|
end
|
data/rubocop-all.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
---
|
2
2
|
AllCops:
|
3
|
-
|
3
|
+
# The oldest supported Ruby version.
|
4
|
+
TargetRubyVersion: 3.0
|
4
5
|
# Cop names are not displayed in offense messages by default. Change behavior
|
5
6
|
# by overriding DisplayCopNames, or by giving the -D/--display-cop-names
|
6
7
|
# option.
|
data/rubocop-default.yml
CHANGED
@@ -1,26 +1,12 @@
|
|
1
1
|
---
|
2
2
|
require:
|
3
|
-
- rubocop-performance
|
4
|
-
- rubocop-rspec
|
5
|
-
- rubocop-rails
|
6
|
-
- rubocop-graphql
|
7
3
|
- ./lib/gitlab/styles/rubocop
|
8
4
|
|
9
5
|
inherit_from:
|
10
6
|
- rubocop-all.yml
|
11
|
-
- rubocop-
|
7
|
+
- rubocop-minimal.yml
|
12
8
|
- rubocop-capybara.yml
|
13
|
-
- rubocop-fips.yml
|
14
|
-
- rubocop-gemspec.yml
|
15
9
|
- rubocop-graphql.yml
|
16
10
|
- rubocop-internal-affairs.yml
|
17
|
-
- rubocop-layout.yml
|
18
|
-
- rubocop-lint.yml
|
19
|
-
- rubocop-metrics.yml
|
20
11
|
- rubocop-migrations.yml
|
21
|
-
- rubocop-naming.yml
|
22
|
-
- rubocop-performance.yml
|
23
12
|
- rubocop-rails.yml
|
24
|
-
- rubocop-rspec.yml
|
25
|
-
- rubocop-security.yml
|
26
|
-
- rubocop-style.yml
|
data/rubocop-graphql.yml
CHANGED
@@ -18,12 +18,38 @@ GraphQL/ExtractInputType:
|
|
18
18
|
|
19
19
|
# Suggests extracting fields with common prefixes to the separate type
|
20
20
|
GraphQL/ExtractType:
|
21
|
-
Enabled:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
# Enforce use of `graphql_name` in GrahQL types.
|
24
|
+
GraphQL/GraphqlName:
|
25
|
+
EnforcedStyle: required
|
22
26
|
|
23
27
|
# Checks that types are defined with class-based API
|
24
28
|
GraphQL/LegacyDsl:
|
25
29
|
Enabled: false
|
26
30
|
|
31
|
+
# Detects missing max_complexity configuration in schema files.
|
32
|
+
# Max complexity is defined in a different way.
|
33
|
+
# See https://gitlab.com/gitlab-org/gitlab/-/blob/9c0dfedd80ede7dbdcc92cf3f5b14bf36998e85c/app/graphql/gitlab_schema.rb#L41-44
|
34
|
+
GraphQL/MaxComplexitySchema:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
# Detects missing max_depth configuration in schema files.
|
38
|
+
# Max depth is defined in a different way.
|
39
|
+
# See https://gitlab.com/gitlab-org/gitlab/-/blob/9c0dfedd80ede7dbdcc92cf3f5b14bf36998e85c/app/graphql/gitlab_schema.rb#L41-45
|
40
|
+
GraphQL/MaxDepthSchema:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# Detects types that implement Node interface and not have `.authorized?` check.
|
44
|
+
# `authorize` is used instead.
|
45
|
+
GraphQL/NotAuthorizedNodeType:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
# Checks that GraphQL Argument definitions prepare arguments to allow better Sorbet typing.
|
49
|
+
# Sorbet is not (yet) used.
|
50
|
+
GraphQL/PrepareMethod:
|
51
|
+
Enabled: false
|
52
|
+
|
27
53
|
# Ensures all types have a description
|
28
54
|
# Disabled because our bespoke Graphql/Descriptions cop covers this.
|
29
55
|
GraphQL/ObjectDescription:
|
data/rubocop-layout.yml
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
---
|
2
|
+
require:
|
3
|
+
- ./lib/gitlab/styles/rubocop
|
4
|
+
|
2
5
|
# Check indentation of private/protected visibility modifiers.
|
3
6
|
Layout/AccessModifierIndentation:
|
4
7
|
Enabled: true
|
@@ -154,11 +157,9 @@ Layout/IndentationWidth:
|
|
154
157
|
Layout/LeadingCommentSpace:
|
155
158
|
Enabled: true
|
156
159
|
|
157
|
-
#
|
158
|
-
Layout/
|
160
|
+
# Checks if there is an empty line after the last include/extend/prepend.
|
161
|
+
Layout/LineBreakAfterFinalMixin:
|
159
162
|
Enabled: true
|
160
|
-
Max: 120
|
161
|
-
AllowedPatterns: ['\s#\srubocop']
|
162
163
|
|
163
164
|
# Checks that strings broken over multiple lines (by a backslash) contain
|
164
165
|
# trailing spaces instead of leading spaces (default) or leading spaces instead
|
@@ -171,6 +172,12 @@ Layout/LineContinuationLeadingSpace:
|
|
171
172
|
Layout/LineContinuationSpacing:
|
172
173
|
Enabled: true
|
173
174
|
|
175
|
+
# Limit lines to 120 characters.
|
176
|
+
Layout/LineLength:
|
177
|
+
Enabled: true
|
178
|
+
Max: 120
|
179
|
+
AllowedPatterns: ['\s#\srubocop']
|
180
|
+
|
174
181
|
# Checks that the closing brace in an array literal is either on the same line
|
175
182
|
# as the last array element, or a new line.
|
176
183
|
Layout/MultilineArrayBraceLayout:
|
@@ -185,6 +192,7 @@ Layout/MultilineBlockLayout:
|
|
185
192
|
# literal and a backslash.
|
186
193
|
Layout/LineEndStringConcatenationIndentation:
|
187
194
|
Enabled: true
|
195
|
+
EnforcedStyle: indented
|
188
196
|
|
189
197
|
# Checks that the closing brace in a hash literal is either on the same line as
|
190
198
|
# the last hash element, or a new line.
|
@@ -309,3 +317,7 @@ Layout/TrailingEmptyLines:
|
|
309
317
|
# Avoid trailing whitespace.
|
310
318
|
Layout/TrailingWhitespace:
|
311
319
|
Enabled: true
|
320
|
+
|
321
|
+
# checks if the code style follows the ExpectedOrder
|
322
|
+
Layout/ClassStructure:
|
323
|
+
Enabled: true
|
data/rubocop-minimal.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
# This are the cops that has no external dependency on Rails specific code
|
3
|
+
# or GitLab specific code
|
4
|
+
#
|
5
|
+
# It is intended to be used by any of our Ruby Gems that are plain ruby code only
|
6
|
+
inherit_from:
|
7
|
+
- rubocop-bundler.yml
|
8
|
+
- rubocop-fips.yml
|
9
|
+
- rubocop-gemspec.yml
|
10
|
+
- rubocop-layout.yml
|
11
|
+
- rubocop-lint.yml
|
12
|
+
- rubocop-metrics.yml
|
13
|
+
- rubocop-naming.yml
|
14
|
+
- rubocop-performance.yml
|
15
|
+
- rubocop-rspec.yml
|
16
|
+
- rubocop-security.yml
|
17
|
+
- rubocop-style.yml
|
data/rubocop-rspec.yml
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
---
|
2
2
|
require:
|
3
|
+
- rubocop-rspec
|
3
4
|
- ./lib/gitlab/styles/rubocop
|
4
5
|
|
5
|
-
# Check for create_list FactoryBot declarations higher than MaxAmount
|
6
|
-
RSpec/FactoryBot/ExcessiveCreateList:
|
7
|
-
Enabled: true
|
8
|
-
MaxAmount: 10
|
9
|
-
|
10
6
|
# Check that instances are not being stubbed globally.
|
11
7
|
RSpec/AnyInstance:
|
12
8
|
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:
|
4
|
+
version: 12.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -16,70 +16,84 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.62.1
|
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.
|
26
|
+
version: 1.62.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-factory_bot
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.25.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.25.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubocop-graphql
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 1.5.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 1.5.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop-performance
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 1.20.2
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 1.20.2
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rubocop-rails
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 2.24.0
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 2.24.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop-rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 2.27.1
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 2.27.1
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,7 +262,7 @@ dependencies:
|
|
248
262
|
- - "~>"
|
249
263
|
- !ruby/object:Gem::Version
|
250
264
|
version: 0.1.4
|
251
|
-
description:
|
265
|
+
description:
|
252
266
|
email:
|
253
267
|
- gitlab_rubygems@gitlab.com
|
254
268
|
executables: []
|
@@ -302,6 +316,7 @@ files:
|
|
302
316
|
- lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb
|
303
317
|
- lib/rubocop/cop/internal_affairs/missing_cop_department.rb
|
304
318
|
- lib/rubocop/cop/internal_affairs/use_restrict_on_send.rb
|
319
|
+
- lib/rubocop/cop/layout/line_break_after_final_mixin.rb
|
305
320
|
- lib/rubocop/cop/line_break_after_guard_clauses.rb
|
306
321
|
- lib/rubocop/cop/line_break_around_conditional_block.rb
|
307
322
|
- lib/rubocop/cop/migration/update_large_table.rb
|
@@ -313,7 +328,6 @@ files:
|
|
313
328
|
- lib/rubocop/cop/rspec/empty_line_after_let_block.rb
|
314
329
|
- lib/rubocop/cop/rspec/empty_line_after_shared_example.rb
|
315
330
|
- lib/rubocop/cop/rspec/example_starting_character.rb
|
316
|
-
- lib/rubocop/cop/rspec/factory_bot/excessive_create_list.rb
|
317
331
|
- lib/rubocop/cop/rspec/have_link_parameters.rb
|
318
332
|
- lib/rubocop/cop/rspec/single_line_hook.rb
|
319
333
|
- lib/rubocop/cop/rspec/specify_expected.rb
|
@@ -327,6 +341,7 @@ files:
|
|
327
341
|
- rubocop-capybara.yml
|
328
342
|
- rubocop-code_reuse.yml
|
329
343
|
- rubocop-default.yml
|
344
|
+
- rubocop-factory_bot.yml
|
330
345
|
- rubocop-fips.yml
|
331
346
|
- rubocop-gemspec.yml
|
332
347
|
- rubocop-graphql.yml
|
@@ -335,6 +350,7 @@ files:
|
|
335
350
|
- rubocop-lint.yml
|
336
351
|
- rubocop-metrics.yml
|
337
352
|
- rubocop-migrations.yml
|
353
|
+
- rubocop-minimal.yml
|
338
354
|
- rubocop-naming.yml
|
339
355
|
- rubocop-performance.yml
|
340
356
|
- rubocop-rails.yml
|
@@ -345,7 +361,7 @@ homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles
|
|
345
361
|
licenses:
|
346
362
|
- MIT
|
347
363
|
metadata: {}
|
348
|
-
post_install_message:
|
364
|
+
post_install_message:
|
349
365
|
rdoc_options: []
|
350
366
|
require_paths:
|
351
367
|
- lib
|
@@ -353,15 +369,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
353
369
|
requirements:
|
354
370
|
- - ">="
|
355
371
|
- !ruby/object:Gem::Version
|
356
|
-
version: '
|
372
|
+
version: '3.0'
|
357
373
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
358
374
|
requirements:
|
359
375
|
- - ">="
|
360
376
|
- !ruby/object:Gem::Version
|
361
377
|
version: '0'
|
362
378
|
requirements: []
|
363
|
-
rubygems_version: 3.
|
364
|
-
signing_key:
|
379
|
+
rubygems_version: 3.3.27
|
380
|
+
signing_key:
|
365
381
|
specification_version: 4
|
366
382
|
summary: GitLab style guides and shared style configs.
|
367
383
|
test_files: []
|
@@ -1,52 +0,0 @@
|
|
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
|