gitlab-styles 6.2.1 → 6.6.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.
- checksums.yaml +4 -4
- data/gitlab-styles.gemspec +2 -1
- data/lib/gitlab/styles/rubocop/cop/performance/rubyzip.rb +39 -0
- data/lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb +31 -0
- data/lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb +43 -0
- data/lib/gitlab/styles/version.rb +1 -1
- data/rubocop-default.yml +2 -0
- data/rubocop-graphql.yml +30 -0
- data/rubocop-performance.yml +9 -4
- data/rubocop-rails.yml +5 -0
- data/rubocop-style.yml +4 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f43bff11daad05b1bb5f442c18f3fa7b8ef871e60f7675dd165f55b1515953f7
|
4
|
+
data.tar.gz: 57317b8cb40639df642e1d058f342eba63979b237f18cc5d5290065aef5a3a5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb319a3ada8ae43e77ba1de5aeb4234e9c6d8c97848f3ae3870222a4b0a4f4ae2f8f2d6356f8cd9b9747101482758834ceacb5cd2cef09519fd17e736a272c05
|
7
|
+
data.tar.gz: bb37685d5084df12a4820c47ce43ec0106aa50e05f9a7ddbde97c9956a7ec50e62fac388a968ba909c356c66324511fa5f407455b538ea1d183d2fa2f20367d1
|
data/gitlab-styles.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.email = ['gitlab_rubygems@gitlab.com']
|
13
13
|
|
14
14
|
spec.summary = 'GitLab style guides and shared style configs.'
|
15
|
-
spec.homepage = 'https://gitlab.com/gitlab-org/gitlab-styles'
|
15
|
+
spec.homepage = 'https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_dependency 'rubocop', '~> 0.91', '>= 0.91.1'
|
26
26
|
spec.add_dependency 'rubocop-gitlab-security', '~> 0.1.1'
|
27
|
+
spec.add_dependency 'rubocop-graphql', '~> 0.10'
|
27
28
|
spec.add_dependency 'rubocop-performance', '~> 1.9.2'
|
28
29
|
spec.add_dependency 'rubocop-rails', '~> 2.9'
|
29
30
|
spec.add_dependency 'rubocop-rspec', '~> 1.44'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module Styles
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
module Performance
|
8
|
+
# This cop flags inefficient uses of rubyzip's Zip::File, since when instantiated
|
9
|
+
# it reads the file's Central Directory into memory entirely. For zips with many
|
10
|
+
# files and directories, this can be very expensive even when the archive's size
|
11
|
+
# in bytes is small.
|
12
|
+
#
|
13
|
+
# See also:
|
14
|
+
# - https://github.com/rubyzip/rubyzip/issues/506
|
15
|
+
# - https://github.com/rubyzip/rubyzip#notes-on-zipinputstream
|
16
|
+
class Rubyzip < RuboCop::Cop::Cop
|
17
|
+
MSG = 'Be careful when opening or iterating zip files via Zip::File. ' \
|
18
|
+
'Zip archives may contain many entries, and their file index is ' \
|
19
|
+
'read into memory upon construction, which can lead to ' \
|
20
|
+
'high memory use and poor performance. ' \
|
21
|
+
'Consider iterating archive entries via Zip::InputStream instead.'
|
22
|
+
|
23
|
+
def_node_matcher :reads_central_directory?, <<-PATTERN
|
24
|
+
(send
|
25
|
+
(const
|
26
|
+
(const {nil? (cbase)} :Zip) :File) {:new :open :foreach} ...)
|
27
|
+
PATTERN
|
28
|
+
|
29
|
+
def on_send(node)
|
30
|
+
return unless reads_central_directory?(node)
|
31
|
+
|
32
|
+
add_offense(node)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../model_helpers'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module Styles
|
7
|
+
module Rubocop
|
8
|
+
module Cop
|
9
|
+
module Rails
|
10
|
+
class IncludeUrlHelper < RuboCop::Cop::Cop
|
11
|
+
MSG = <<~MSG
|
12
|
+
Avoid including `ActionView::Helpers::UrlHelper`.
|
13
|
+
It adds/overrides ~40 methods while usually only one is needed.
|
14
|
+
Instead, use the `Gitlab::Routing.url_helpers`/`Application.routes.url_helpers`(outside of gitlab)
|
15
|
+
and `ActionController::Base.helpers.link_to`.
|
16
|
+
See https://gitlab.com/gitlab-org/gitlab/-/issues/340567.
|
17
|
+
MSG
|
18
|
+
|
19
|
+
def_node_matcher :include_url_helpers_node?, <<~PATTERN
|
20
|
+
(send nil? :include (const (const (const {nil? cbase} :ActionView) :Helpers) :UrlHelper))
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
add_offense(node) if include_url_helpers_node?(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module Styles
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
module Style
|
8
|
+
# This cop flags uses of OpenStruct, as it is now officially discouraged
|
9
|
+
# to be used for performance, version compatibility, and potential security issues.
|
10
|
+
#
|
11
|
+
# See also:
|
12
|
+
# - https://rubyreferences.github.io/rubychanges/3.0.html#standard-library
|
13
|
+
# - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
|
14
|
+
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67855
|
15
|
+
class OpenStructUse < RuboCop::Cop::Cop
|
16
|
+
MSG = 'Avoid using `OpenStruct`. It is officially discouraged. ' \
|
17
|
+
'Replace it with `Struct`, `Hash`, or RSpec doubles. ' \
|
18
|
+
'See https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats'
|
19
|
+
|
20
|
+
def_node_matcher :uses_open_struct?, <<-PATTERN
|
21
|
+
(const {nil? (cbase)} :OpenStruct)
|
22
|
+
PATTERN
|
23
|
+
|
24
|
+
def on_const(node)
|
25
|
+
return unless uses_open_struct?(node)
|
26
|
+
return if custom_class_or_module_definition?(node)
|
27
|
+
|
28
|
+
add_offense(node)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def custom_class_or_module_definition?(node)
|
34
|
+
parent = node.parent
|
35
|
+
|
36
|
+
(parent.class_type? || parent.module_type?) && node.left_siblings.empty?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/rubocop-default.yml
CHANGED
@@ -4,12 +4,14 @@ require:
|
|
4
4
|
- rubocop-performance
|
5
5
|
- rubocop-rspec
|
6
6
|
- rubocop-rails
|
7
|
+
- rubocop-graphql
|
7
8
|
- ./lib/gitlab/styles/rubocop
|
8
9
|
|
9
10
|
inherit_from:
|
10
11
|
- rubocop-all.yml
|
11
12
|
- rubocop-bundler.yml
|
12
13
|
- rubocop-gemspec.yml
|
14
|
+
- rubocop-graphql.yml
|
13
15
|
- rubocop-layout.yml
|
14
16
|
- rubocop-lint.yml
|
15
17
|
- rubocop-metrics.yml
|
data/rubocop-graphql.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
require:
|
3
|
+
- rubocop-graphql
|
4
|
+
|
5
|
+
# Ensures all arguments have a description
|
6
|
+
# Disabled because our bespoke Graphql/Descriptions cop covers this.
|
7
|
+
GraphQL/ArgumentDescription:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# Ensures all fields have a description
|
11
|
+
# Disabled because our bespoke Graphql/Descriptions cop covers this.
|
12
|
+
GraphQL/FieldDescription:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
# Suggests using input type instead of many arguments
|
16
|
+
GraphQL/ExtractInputType:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# Suggests extracting fields with common prefixes to the separate type
|
20
|
+
GraphQL/ExtractType:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
# Checks that types are defined with class-based API
|
24
|
+
GraphQL/LegacyDsl:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
# Ensures all types have a description
|
28
|
+
# Disabled because our bespoke Graphql/Descriptions cop covers this.
|
29
|
+
GraphQL/ObjectDescription:
|
30
|
+
Enabled: false
|
data/rubocop-performance.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
---
|
2
2
|
require:
|
3
3
|
- rubocop-performance
|
4
|
+
- ./lib/gitlab/styles/rubocop
|
4
5
|
|
5
6
|
# Used to identify usages of ancestors.include? and change them to use ⇐ instead.
|
6
7
|
# https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performanceancestorsinclude
|
@@ -38,11 +39,9 @@ Performance/DoubleStartEndWith:
|
|
38
39
|
Performance/MethodObjectAsBlock: # (new in 1.9)
|
39
40
|
Enabled: true
|
40
41
|
|
41
|
-
#
|
42
|
+
# Superseded by Style/OpenStructUse
|
42
43
|
Performance/OpenStruct:
|
43
|
-
Enabled:
|
44
|
-
Exclude:
|
45
|
-
- 'spec/**/*'
|
44
|
+
Enabled: false
|
46
45
|
|
47
46
|
# Use `Range#cover?` instead of `Range#include?`.
|
48
47
|
Performance/RangeInclude:
|
@@ -114,3 +113,9 @@ Performance/Sum:
|
|
114
113
|
# Checks for `.times.map` calls.
|
115
114
|
Performance/TimesMap:
|
116
115
|
Enabled: true
|
116
|
+
|
117
|
+
# Flags potentially expensive operations on ZIP archives.
|
118
|
+
Performance/Rubyzip:
|
119
|
+
Enabled: true
|
120
|
+
Exclude:
|
121
|
+
- 'spec/**/*'
|
data/rubocop-rails.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
---
|
2
2
|
require:
|
3
3
|
- rubocop-rails
|
4
|
+
- ./lib/gitlab/styles/rubocop
|
4
5
|
|
5
6
|
# Enables Rails cops.
|
6
7
|
Rails:
|
@@ -186,3 +187,7 @@ Rails/WhereExists:
|
|
186
187
|
# https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railswherenot
|
187
188
|
Rails/WhereNot:
|
188
189
|
Enabled: true
|
190
|
+
|
191
|
+
# Bans the use of `include ActionView::Helpers::UrlHelper`.
|
192
|
+
Rails/IncludeUrlHelper:
|
193
|
+
Enabled: true
|
data/rubocop-style.yml
CHANGED
@@ -297,6 +297,10 @@ Style/NumericLiterals:
|
|
297
297
|
Style/OneLineConditional:
|
298
298
|
Enabled: true
|
299
299
|
|
300
|
+
# Do not use OpenStruct.
|
301
|
+
Style/OpenStructUse:
|
302
|
+
Enabled: true
|
303
|
+
|
300
304
|
# Don't use parentheses around the condition of an if/unless/while.
|
301
305
|
Style/ParenthesesAroundCondition:
|
302
306
|
Enabled: true
|
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: 6.
|
4
|
+
version: 6.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.1.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubocop-graphql
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.10'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.10'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: rubocop-performance
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +177,9 @@ files:
|
|
163
177
|
- lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb
|
164
178
|
- lib/gitlab/styles/rubocop/cop/line_break_around_conditional_block.rb
|
165
179
|
- lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb
|
180
|
+
- lib/gitlab/styles/rubocop/cop/performance/rubyzip.rb
|
166
181
|
- lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
|
182
|
+
- lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb
|
167
183
|
- lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
|
168
184
|
- lib/gitlab/styles/rubocop/cop/rspec/base.rb
|
169
185
|
- lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_final_let_it_be.rb
|
@@ -174,6 +190,7 @@ files:
|
|
174
190
|
- lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
|
175
191
|
- lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb
|
176
192
|
- lib/gitlab/styles/rubocop/cop/style/hash_transformation.rb
|
193
|
+
- lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb
|
177
194
|
- lib/gitlab/styles/rubocop/cop/without_reactive_cache.rb
|
178
195
|
- lib/gitlab/styles/rubocop/migration_helpers.rb
|
179
196
|
- lib/gitlab/styles/rubocop/model_helpers.rb
|
@@ -184,6 +201,7 @@ files:
|
|
184
201
|
- rubocop-code_reuse.yml
|
185
202
|
- rubocop-default.yml
|
186
203
|
- rubocop-gemspec.yml
|
204
|
+
- rubocop-graphql.yml
|
187
205
|
- rubocop-layout.yml
|
188
206
|
- rubocop-lint.yml
|
189
207
|
- rubocop-metrics.yml
|
@@ -194,7 +212,7 @@ files:
|
|
194
212
|
- rubocop-rspec.yml
|
195
213
|
- rubocop-security.yml
|
196
214
|
- rubocop-style.yml
|
197
|
-
homepage: https://gitlab.com/gitlab-org/gitlab-styles
|
215
|
+
homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles
|
198
216
|
licenses:
|
199
217
|
- MIT
|
200
218
|
metadata: {}
|