gitlab-styles 6.3.0 → 6.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb +43 -0
- data/lib/gitlab/styles/version.rb +1 -1
- data/rubocop-performance.yml +2 -4
- data/rubocop-style.yml +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7243d64ca027fd058b9183cab0e19417797fa05e9b13de3f31200027b39c0440
|
4
|
+
data.tar.gz: c45d182c5dc811e729bc93c26db12c9127b276ad266fad7be3bc921b7d1def89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64fed474c7b045454a9dad3e9faf742ca4bc371084562033e7062eeb4a6e0130084000e5579e6b1c2f32c47c4b674d5b5f6d7cc4dd07d6b53d93e229e5178453
|
7
|
+
data.tar.gz: 735af04bd27f127aa2bc99cb1ca06a951892bcf42957e82c2a3e029b570ae29ca88d3be4de3aba0f21e6d0a82197c1fbc26b4f6c96289c8d682832c4291c37af
|
@@ -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-performance.yml
CHANGED
@@ -38,11 +38,9 @@ Performance/DoubleStartEndWith:
|
|
38
38
|
Performance/MethodObjectAsBlock: # (new in 1.9)
|
39
39
|
Enabled: true
|
40
40
|
|
41
|
-
#
|
41
|
+
# Superseded by Style/OpenStructUse
|
42
42
|
Performance/OpenStruct:
|
43
|
-
Enabled:
|
44
|
-
Exclude:
|
45
|
-
- 'spec/**/*'
|
43
|
+
Enabled: false
|
46
44
|
|
47
45
|
# Use `Range#cover?` instead of `Range#include?`.
|
48
46
|
Performance/RangeInclude:
|
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.4.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-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
|
176
176
|
- lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb
|
177
177
|
- lib/gitlab/styles/rubocop/cop/style/hash_transformation.rb
|
178
|
+
- lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb
|
178
179
|
- lib/gitlab/styles/rubocop/cop/without_reactive_cache.rb
|
179
180
|
- lib/gitlab/styles/rubocop/migration_helpers.rb
|
180
181
|
- lib/gitlab/styles/rubocop/model_helpers.rb
|