gitlab-styles 6.3.0 → 6.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdb4b922d729575676263e2cb9cf6f63b50be1d8b4205d96af7ecb6aaa2c4c84
4
- data.tar.gz: 46a11af0a19079547b1d25e988e80d8271a5fe15fda707096662aee73a4cc9c3
3
+ metadata.gz: 7243d64ca027fd058b9183cab0e19417797fa05e9b13de3f31200027b39c0440
4
+ data.tar.gz: c45d182c5dc811e729bc93c26db12c9127b276ad266fad7be3bc921b7d1def89
5
5
  SHA512:
6
- metadata.gz: df88cc8b9ea74b138c8768130b310d50d2204bed62e4648b292a8b0f058dad46335e23432564a546e0acc0ae9ef3c8a2487f4690f8e4ee2a73e6209665441746
7
- data.tar.gz: 2d744fd1097268298c1073404bf84ddd4d65b28dbfa4b5bfad95857ea310734d24f93b81870e0c03454c26a2aa8de19470c7f75374e73db25ac0067a2665bebf
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '6.3.0'
5
+ VERSION = '6.4.0'
6
6
  end
7
7
  end
@@ -38,11 +38,9 @@ Performance/DoubleStartEndWith:
38
38
  Performance/MethodObjectAsBlock: # (new in 1.9)
39
39
  Enabled: true
40
40
 
41
- # Use `Struct.new(..., keyword_init: true)` instead of `OpenStruct.new(...)`.
41
+ # Superseded by Style/OpenStructUse
42
42
  Performance/OpenStruct:
43
- Enabled: true
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.3.0
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-09-17 00:00:00.000000000 Z
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