gitlab-styles 6.5.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f15e657637a0d30fed824f3d8312b970b9ee9bebc5a0feb603b83fa884b1705
4
- data.tar.gz: fef3baec21ab04501f316d754a02aab77fb4dc816a048f87070d6d1b4a28f74c
3
+ metadata.gz: bdbe53a3630aedb6f9a4eb87e46ab9becc5b924dbaf2122eca8f8634ffa46d11
4
+ data.tar.gz: 8b64b09817b3d57edec615305e973f9aa86312bfc19b25cf999111f721d16cf3
5
5
  SHA512:
6
- metadata.gz: 9954e550cf2ead877c73939a6f20893be5a584eb2c4f0850ea2cb5c8f4e976f3a20d3f910c0a39072c87e666cba51a8f5d283c56e33e2b2db76b1376f18cab7f
7
- data.tar.gz: a54833e11f28072707ca11e21428820d888a8c95f89a5577e2633d324311400eca5d277b93311a405239397ca9ad3abac2a9982fcd5ace63f5a4491af970d513
6
+ metadata.gz: 691d29df5dd389a90f9169e0caa3637c5abad270eeab8e55742b2d45542056d819c18f24723b1e897e1f1cc343d1a6aa740efcb17df1eb6b1517ef580ad2dabd
7
+ data.tar.gz: e1ceae95be87aec10561836e415f7d12d3e59404d24604097efae1fb99290038eb77d1013f03982fae00d5ad1c819d72385a505b247580b2d16c32c7c390e7c2
@@ -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|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency 'rubocop-rspec', '~> 1.44'
31
31
 
32
32
  spec.add_development_dependency 'bundler', '~> 2.1'
33
+ spec.add_development_dependency 'gitlab-dangerfiles', '~> 2.11.0'
33
34
  spec.add_development_dependency 'rake', '~> 10.0'
34
35
  spec.add_development_dependency 'rspec', '~> 3.0'
35
36
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Styles
5
+ module Common
6
+ module BannedConstants
7
+ attr_reader :replacements, :message_template, :autocorrect
8
+
9
+ def on_const(node)
10
+ constant = node.source.delete_prefix('::')
11
+
12
+ return unless replacements.key?(constant)
13
+
14
+ replacement = replacements.fetch(constant)
15
+ message = format(message_template, { replacement: replacement })
16
+
17
+ add_offense(node, message: message) do |corrector|
18
+ next unless autocorrect
19
+
20
+ replacement = "::#{replacement}" if node.source.start_with?("::")
21
+
22
+ corrector.replace(node, replacement)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ 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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../common/banned_constants'
4
+
5
+ module Gitlab
6
+ module Styles
7
+ module Rubocop
8
+ module Cop
9
+ module Fips
10
+ class MD5 < RuboCop::Cop::Base
11
+ include Gitlab::Styles::Common::BannedConstants
12
+
13
+ MESSAGE_TEMPLATE = 'MD5 is not FIPS-compliant. Use %{replacement} instead.'
14
+
15
+ REPLACEMENTS = {
16
+ 'OpenSSL::Digest::MD5' => 'OpenSSL::Digest::SHA256',
17
+ 'Digest::MD5' => 'OpenSSL::Digest::SHA256'
18
+ }.freeze
19
+
20
+ def initialize(config = nil, options = nil)
21
+ @message_template = MESSAGE_TEMPLATE
22
+ @replacements = REPLACEMENTS
23
+ @autocorrect = false
24
+ super(config, options)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../common/banned_constants'
4
+
5
+ module Gitlab
6
+ module Styles
7
+ module Rubocop
8
+ module Cop
9
+ module Fips
10
+ class OpenSSL < RuboCop::Cop::Base
11
+ extend RuboCop::Cop::AutoCorrector
12
+ include Gitlab::Styles::Common::BannedConstants
13
+
14
+ MESSAGE_TEMPLATE = 'Usage of this class is not FIPS-compliant. Use %{replacement} instead.'
15
+
16
+ REPLACEMENTS = {
17
+ 'Digest::SHA1' => 'OpenSSL::Digest::SHA1',
18
+ 'Digest::SHA2' => 'OpenSSL::Digest::SHA2',
19
+ 'Digest::SHA256' => 'OpenSSL::Digest::SHA256',
20
+ 'Digest::SHA384' => 'OpenSSL::Digest::SHA384',
21
+ 'Digest::SHA512' => 'OpenSSL::Digest::SHA512'
22
+ }.freeze
23
+
24
+ def initialize(config = nil, options = nil)
25
+ @message_template = MESSAGE_TEMPLATE
26
+ @replacements = REPLACEMENTS
27
+ @autocorrect = true
28
+ super(config, options)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../common/banned_constants'
4
+
5
+ module Gitlab
6
+ module Styles
7
+ module Rubocop
8
+ module Cop
9
+ module Fips
10
+ class SHA1 < RuboCop::Cop::Base
11
+ include Gitlab::Styles::Common::BannedConstants
12
+
13
+ MESSAGE_TEMPLATE = 'SHA1 is likely to become non-compliant in the near future. Use %{replacement} instead.'
14
+
15
+ REPLACEMENTS = {
16
+ 'OpenSSL::Digest::SHA1' => 'OpenSSL::Digest::SHA256',
17
+ 'Digest::SHA1' => 'OpenSSL::Digest::SHA256'
18
+ }.freeze
19
+
20
+ def initialize(config = nil, options = nil)
21
+ @message_template = MESSAGE_TEMPLATE
22
+ @replacements = REPLACEMENTS
23
+ @autocorrect = false
24
+ super(config, options)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ 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.5.0'
5
+ VERSION = '7.1.0'
6
6
  end
7
7
  end
data/rubocop-default.yml CHANGED
@@ -10,6 +10,7 @@ require:
10
10
  inherit_from:
11
11
  - rubocop-all.yml
12
12
  - rubocop-bundler.yml
13
+ - rubocop-fips.yml
13
14
  - rubocop-gemspec.yml
14
15
  - rubocop-graphql.yml
15
16
  - rubocop-layout.yml
data/rubocop-fips.yml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ require:
3
+ - ./lib/gitlab/styles/rubocop
4
+
5
+ # Denies usage of MD5
6
+ Fips/MD5:
7
+ Enabled: true
8
+
9
+ # Denies usage of SHA1
10
+ Fips/SHA1:
11
+ Enabled: true
12
+
13
+ # Replaces ::Digest with ::OpenSSL::Digest
14
+ Fips/OpenSSL:
15
+ Enabled: true
@@ -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.5.0
4
+ version: 7.1.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-17 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
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.11.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 2.11.0
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: rake
119
133
  requirement: !ruby/object:Gem::Requirement
@@ -152,12 +166,14 @@ files:
152
166
  - ".editorconfig"
153
167
  - ".gitignore"
154
168
  - ".gitlab-ci.yml"
169
+ - ".gitlab/changelog_config.yml"
155
170
  - ".gitlab/merge_request_templates/New Static Analysis Check.md"
156
171
  - ".gitlab/merge_request_templates/Release.md"
157
172
  - ".rspec"
158
173
  - ".rubocop.yml"
159
174
  - CODE_OF_CONDUCT.md
160
175
  - CONTRIBUTING.md
176
+ - Dangerfile
161
177
  - Gemfile
162
178
  - LICENSE.md
163
179
  - README.md
@@ -166,17 +182,23 @@ files:
166
182
  - bin/setup
167
183
  - gitlab-styles.gemspec
168
184
  - lib/gitlab/styles.rb
185
+ - lib/gitlab/styles/common/banned_constants.rb
169
186
  - lib/gitlab/styles/rubocop.rb
170
187
  - lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
171
188
  - lib/gitlab/styles/rubocop/cop/active_record_serialize.rb
189
+ - lib/gitlab/styles/rubocop/cop/avoid_return_from_blocks.rb
172
190
  - lib/gitlab/styles/rubocop/cop/code_reuse/active_record.rb
173
191
  - lib/gitlab/styles/rubocop/cop/custom_error_class.rb
192
+ - lib/gitlab/styles/rubocop/cop/fips/md5.rb
193
+ - lib/gitlab/styles/rubocop/cop/fips/open_ssl.rb
194
+ - lib/gitlab/styles/rubocop/cop/fips/sha1.rb
174
195
  - lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
175
196
  - lib/gitlab/styles/rubocop/cop/in_batches.rb
176
197
  - lib/gitlab/styles/rubocop/cop/internal_affairs/deprecate_cop_helper.rb
177
198
  - lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb
178
199
  - lib/gitlab/styles/rubocop/cop/line_break_around_conditional_block.rb
179
200
  - lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb
201
+ - lib/gitlab/styles/rubocop/cop/performance/rubyzip.rb
180
202
  - lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
181
203
  - lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb
182
204
  - lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
@@ -199,6 +221,7 @@ files:
199
221
  - rubocop-bundler.yml
200
222
  - rubocop-code_reuse.yml
201
223
  - rubocop-default.yml
224
+ - rubocop-fips.yml
202
225
  - rubocop-gemspec.yml
203
226
  - rubocop-graphql.yml
204
227
  - rubocop-layout.yml
@@ -211,7 +234,7 @@ files:
211
234
  - rubocop-rspec.yml
212
235
  - rubocop-security.yml
213
236
  - rubocop-style.yml
214
- homepage: https://gitlab.com/gitlab-org/gitlab-styles
237
+ homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles
215
238
  licenses:
216
239
  - MIT
217
240
  metadata: {}