gitlab-styles 6.6.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: f43bff11daad05b1bb5f442c18f3fa7b8ef871e60f7675dd165f55b1515953f7
4
- data.tar.gz: 57317b8cb40639df642e1d058f342eba63979b237f18cc5d5290065aef5a3a5f
3
+ metadata.gz: 9fcbcb3937df65b5a6ef170918f4abd96786642c5ba2e379b4f0c3273cd21411
4
+ data.tar.gz: dde017a2f0091139175945e0bafd2f0d9c43f2ad280ca9f60c350093fe441dd2
5
5
  SHA512:
6
- metadata.gz: bb319a3ada8ae43e77ba1de5aeb4234e9c6d8c97848f3ae3870222a4b0a4f4ae2f8f2d6356f8cd9b9747101482758834ceacb5cd2cef09519fd17e736a272c05
7
- data.tar.gz: bb37685d5084df12a4820c47ce43ec0106aa50e05f9a7ddbde97c9956a7ec50e62fac388a968ba909c356c66324511fa5f407455b538ea1d183d2fa2f20367d1
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)
@@ -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.6.1'
33
34
  spec.add_development_dependency 'rake', '~> 10.0'
34
35
  spec.add_development_dependency 'rspec', '~> 3.0'
35
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '6.6.0'
5
+ VERSION = '7.0.0'
6
6
  end
7
7
  end
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.6.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-11-23 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
@@ -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.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
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
@@ -169,6 +185,7 @@ files:
169
185
  - lib/gitlab/styles/rubocop.rb
170
186
  - lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
171
187
  - lib/gitlab/styles/rubocop/cop/active_record_serialize.rb
188
+ - lib/gitlab/styles/rubocop/cop/avoid_return_from_blocks.rb
172
189
  - lib/gitlab/styles/rubocop/cop/code_reuse/active_record.rb
173
190
  - lib/gitlab/styles/rubocop/cop/custom_error_class.rb
174
191
  - lib/gitlab/styles/rubocop/cop/gem_fetcher.rb