gitlab-styles 6.4.0 → 7.0.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: 7243d64ca027fd058b9183cab0e19417797fa05e9b13de3f31200027b39c0440
4
- data.tar.gz: c45d182c5dc811e729bc93c26db12c9127b276ad266fad7be3bc921b7d1def89
3
+ metadata.gz: 9fcbcb3937df65b5a6ef170918f4abd96786642c5ba2e379b4f0c3273cd21411
4
+ data.tar.gz: dde017a2f0091139175945e0bafd2f0d9c43f2ad280ca9f60c350093fe441dd2
5
5
  SHA512:
6
- metadata.gz: 64fed474c7b045454a9dad3e9faf742ca4bc371084562033e7062eeb4a6e0130084000e5579e6b1c2f32c47c4b674d5b5f6d7cc4dd07d6b53d93e229e5178453
7
- data.tar.gz: 735af04bd27f127aa2bc99cb1ca06a951892bcf42957e82c2a3e029b570ae29ca88d3be4de3aba0f21e6d0a82197c1fbc26b4f6c96289c8d682832c4291c37af
6
+ metadata.gz: ccd9e7b074e48b11b2c9d13f929b2f20d7fcd71e6ad89ae6eaf558d690f1122cbfa78ea145494ada2944ca5f37113ee1ac77fa88679b3194126e24b1c563063c
7
+ data.tar.gz: c38476316f30eed488850324802911e538369ba88a2110357d5b8c5dbb2be08fdf99119f640b05e2a11d90d703e7f2646425e2083a8d96fa96996bf1f7c2e966
@@ -0,0 +1,13 @@
1
+ ---
2
+ # Settings for generating changelogs using the GitLab API. See
3
+ # https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data for
4
+ # more information.
5
+ categories:
6
+ added: Added
7
+ fixed: Fixed
8
+ changed: Changed
9
+ deprecated: Deprecated
10
+ removed: Removed
11
+ security: Security
12
+ performance: Performance
13
+ other: Other
@@ -1,35 +1,13 @@
1
- <!-- Replace `v4.5.0` with the previous release here, and `e18d76b309e42888759c1effe96767f13e34ae55`
2
- with the latest commit from https://gitlab.com/gitlab-org/gitlab-styles/commits/master that will be included in the release. -->
3
- - Diff: https://gitlab.com/gitlab-org/gitlab-styles/compare/v4.5.0...e18d76b309e42888759c1effe96767f13e34ae55
1
+ <!-- Replace `<PREVIOUS_VERSION>` with the previous version number here, `<COMMIT_UPDATING_VERSION>` with the latest
2
+ commit from this merge request, and `<NEW_VERSION>` with the upcoming version number. -->
3
+ ## Diff
4
4
 
5
- - Release notes:
5
+ https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/compare/v<PREVIOUS_VERSION>...<COMMIT_UPDATING_VERSION>
6
6
 
7
- <!-- Keep the sections order but remove the empty sections -->
7
+ ## Checklist
8
8
 
9
- ```markdown
10
- ### New features and features updates
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).
11
12
 
12
- - !aaa <Title of the aaa MR>.
13
-
14
- ### Fixes
15
-
16
- - !bbb <Title of the bbb MR>.
17
-
18
- ### Doc changes
19
-
20
- - !ccc <Title of the ccc MR>.
21
-
22
- ### Other changes (tooling, technical debt)
23
-
24
- - !ddd <Title of the ddd MR>.
25
- ```
26
-
27
- - Checklist before merging:
28
- - [ ] Diff link is up-to-date.
29
- - [ ] Based on the diff, `lib/gitlab/styles/version.rb` is updated, according to [SemVer](https://semver.org).
30
- - [ ] Release notes are accurate.
31
-
32
- - Checklist after merging:
33
- - [ ] [Update the release notes for the newly created tag](docs/release_process.md#how-to).
34
-
35
- /label ~"Engineering Productivity" ~"feature" ~"feature::maintenance" ~"static code analysis"
13
+ /label ~"type::maintenance" ~"static code analysis"
data/.gitlab-ci.yml CHANGED
@@ -31,4 +31,6 @@ specs:
31
31
 
32
32
  include:
33
33
  - project: 'gitlab-org/quality/pipeline-common'
34
- file: '/ci/gem-release.yml'
34
+ file:
35
+ - '/ci/gem-release.yml'
36
+ - '/ci/danger-review.yml'
data/Dangerfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gitlab-dangerfiles'
4
+
5
+ Gitlab::Dangerfiles.for_project(self, &:import_defaults)
@@ -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,11 +24,13 @@ 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'
30
31
 
31
32
  spec.add_development_dependency 'bundler', '~> 2.1'
33
+ spec.add_development_dependency 'gitlab-dangerfiles', '~> 2.6.1'
32
34
  spec.add_development_dependency 'rake', '~> 10.0'
33
35
  spec.add_development_dependency 'rspec', '~> 3.0'
34
36
  end
@@ -10,10 +10,11 @@ module Gitlab
10
10
  class ActiveRecordDependent < RuboCop::Cop::Cop
11
11
  include ModelHelpers
12
12
 
13
- MSG = 'Do not use `dependent: to remove associated data, ' \
14
- 'use foreign keys with cascading deletes instead'
13
+ MSG = 'Do not use `dependent:` to remove associated data, ' \
14
+ 'use foreign keys with cascading deletes instead.'
15
15
 
16
16
  METHOD_NAMES = [:has_many, :has_one, :belongs_to].freeze
17
+ ALLOWED_OPTIONS = [:restrict_with_error].freeze
17
18
 
18
19
  def on_send(node)
19
20
  return unless in_model?(node)
@@ -21,6 +22,9 @@ module Gitlab
21
22
 
22
23
  node.children.last.each_node(:pair) do |pair|
23
24
  key_name = pair.children[0].children[0]
25
+ option_name = pair.children[1].children[0]
26
+
27
+ break if ALLOWED_OPTIONS.include?(option_name)
24
28
 
25
29
  add_offense(pair) if key_name == :dependent
26
30
  end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Styles
5
+ module Rubocop
6
+ module Cop
7
+ # Checks for return inside blocks.
8
+ # For more information see: https://gitlab.com/gitlab-org/gitlab-foss/issues/42889
9
+ #
10
+ # @example
11
+ # # bad
12
+ # call do
13
+ # return if something
14
+ #
15
+ # do_something_else
16
+ # end
17
+ #
18
+ # # good
19
+ # call do
20
+ # break if something
21
+ #
22
+ # do_something_else
23
+ # end
24
+ #
25
+ class AvoidReturnFromBlocks < RuboCop::Cop::Cop
26
+ MSG = 'Do not return from a block, use next or break instead.'
27
+ DEF_METHODS = %i[define_method lambda].freeze
28
+ WHITELISTED_METHODS = %i[each each_filename times loop].freeze
29
+
30
+ def on_block(node)
31
+ block_body = node.body
32
+
33
+ return unless block_body
34
+ return unless top_block?(node)
35
+
36
+ block_body.each_node(:return) do |return_node|
37
+ next if parent_blocks(node, return_node).all? { |block| whitelisted?(block) }
38
+
39
+ add_offense(return_node)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def top_block?(node)
46
+ current_node = node
47
+ top_block = nil
48
+
49
+ while current_node && current_node.type != :def
50
+ top_block = current_node if current_node.block_type?
51
+ current_node = current_node.parent
52
+ end
53
+
54
+ top_block == node
55
+ end
56
+
57
+ def parent_blocks(node, current_node)
58
+ blocks = []
59
+
60
+ until node == current_node || def?(current_node)
61
+ blocks << current_node if current_node.block_type?
62
+ current_node = current_node.parent
63
+ end
64
+
65
+ blocks << node if node == current_node && !def?(node)
66
+ blocks
67
+ end
68
+
69
+ def def?(node)
70
+ node.def_type? || node.defs_type? ||
71
+ (node.block_type? && DEF_METHODS.include?(node.method_name))
72
+ end
73
+
74
+ def whitelisted?(block_node)
75
+ WHITELISTED_METHODS.include?(block_node.method_name)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -76,52 +76,6 @@ module Gitlab
76
76
 
77
77
  add_offense(node, location: :selector)
78
78
  end
79
-
80
- # We can not auto correct code like this, as it requires manual
81
- # refactoring. Instead, we'll just allow the surrounding scope.
82
- #
83
- # Despite this method's presence, you should not use it. This method
84
- # exists to make it possible to allow large chunks of offenses we
85
- # can't fix in the short term. If you are writing new code, follow the
86
- # code reuse guidelines, instead of allowing any new offenses.
87
- def autocorrect(node)
88
- scope = surrounding_scope_of(node)
89
- indent = indentation_of(scope)
90
-
91
- lambda do |corrector|
92
- # This prevents us from inserting the same enable/disable comment
93
- # for a method or block that has multiple offenses.
94
- next if allowed_scopes.include?(scope)
95
-
96
- corrector.insert_before(
97
- scope.source_range,
98
- "# rubocop: disable #{cop_name}\n#{indent}"
99
- )
100
-
101
- corrector.insert_after(
102
- scope.source_range,
103
- "\n#{indent}# rubocop: enable #{cop_name}"
104
- )
105
-
106
- allowed_scopes << scope
107
- end
108
- end
109
-
110
- def indentation_of(node)
111
- ' ' * node.loc.expression.source_line[/\A */].length
112
- end
113
-
114
- def surrounding_scope_of(node)
115
- %i[def defs block begin].each do |type|
116
- if (found = node.each_ancestor(type).first)
117
- return found
118
- end
119
- end
120
- end
121
-
122
- def allowed_scopes
123
- @allowed_scopes ||= Set.new
124
- end
125
79
  end
126
80
  end
127
81
  end
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '6.4.0'
5
+ VERSION = '7.0.0'
6
6
  end
7
7
  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
@@ -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
@@ -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
@@ -112,3 +113,9 @@ Performance/Sum:
112
113
  # Checks for `.times.map` calls.
113
114
  Performance/TimesMap:
114
115
  Enabled: true
116
+
117
+ # Flags potentially expensive operations on ZIP archives.
118
+ Performance/Rubyzip:
119
+ Enabled: true
120
+ Exclude:
121
+ - 'spec/**/*'
data/rubocop-rspec.yml CHANGED
@@ -95,8 +95,9 @@ RSpec/ImplicitExpect:
95
95
  EnforcedStyle: is_expected
96
96
 
97
97
  # Checks for the usage of instance variables.
98
+ # https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#subject-and-let-variables
98
99
  RSpec/InstanceVariable:
99
- Enabled: false
100
+ Enabled: true
100
101
 
101
102
  # Checks for `subject` definitions that come after `let` definitions.
102
103
  RSpec/LeadingSubject:
@@ -157,4 +158,4 @@ RSpec/SubjectStub:
157
158
 
158
159
  # Prefer using verifying doubles over normal doubles.
159
160
  RSpec/VerifiedDoubles:
160
- Enabled: false
161
+ 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.0
4
+ version: 7.0.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-10-28 00:00:00.000000000 Z
11
+ date: 2022-03-02 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
@@ -100,6 +114,20 @@ dependencies:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
116
  version: '2.1'
117
+ - !ruby/object:Gem::Dependency
118
+ name: gitlab-dangerfiles
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 2.6.1
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.1
103
131
  - !ruby/object:Gem::Dependency
104
132
  name: rake
105
133
  requirement: !ruby/object:Gem::Requirement
@@ -138,12 +166,14 @@ files:
138
166
  - ".editorconfig"
139
167
  - ".gitignore"
140
168
  - ".gitlab-ci.yml"
169
+ - ".gitlab/changelog_config.yml"
141
170
  - ".gitlab/merge_request_templates/New Static Analysis Check.md"
142
171
  - ".gitlab/merge_request_templates/Release.md"
143
172
  - ".rspec"
144
173
  - ".rubocop.yml"
145
174
  - CODE_OF_CONDUCT.md
146
175
  - CONTRIBUTING.md
176
+ - Dangerfile
147
177
  - Gemfile
148
178
  - LICENSE.md
149
179
  - README.md
@@ -155,6 +185,7 @@ files:
155
185
  - lib/gitlab/styles/rubocop.rb
156
186
  - lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
157
187
  - lib/gitlab/styles/rubocop/cop/active_record_serialize.rb
188
+ - lib/gitlab/styles/rubocop/cop/avoid_return_from_blocks.rb
158
189
  - lib/gitlab/styles/rubocop/cop/code_reuse/active_record.rb
159
190
  - lib/gitlab/styles/rubocop/cop/custom_error_class.rb
160
191
  - lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
@@ -163,6 +194,7 @@ files:
163
194
  - lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb
164
195
  - lib/gitlab/styles/rubocop/cop/line_break_around_conditional_block.rb
165
196
  - lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb
197
+ - lib/gitlab/styles/rubocop/cop/performance/rubyzip.rb
166
198
  - lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
167
199
  - lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb
168
200
  - lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
@@ -186,6 +218,7 @@ files:
186
218
  - rubocop-code_reuse.yml
187
219
  - rubocop-default.yml
188
220
  - rubocop-gemspec.yml
221
+ - rubocop-graphql.yml
189
222
  - rubocop-layout.yml
190
223
  - rubocop-lint.yml
191
224
  - rubocop-metrics.yml
@@ -196,7 +229,7 @@ files:
196
229
  - rubocop-rspec.yml
197
230
  - rubocop-security.yml
198
231
  - rubocop-style.yml
199
- homepage: https://gitlab.com/gitlab-org/gitlab-styles
232
+ homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles
200
233
  licenses:
201
234
  - MIT
202
235
  metadata: {}