gitlab-styles 6.0.0 → 6.3.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 +4 -4
- data/.gitlab-ci.yml +2 -2
- data/gitlab-styles.gemspec +1 -1
- data/lib/gitlab/styles/rubocop/cop/code_reuse/active_record.rb +0 -1
- data/lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb +31 -0
- data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_final_let_it_be.rb +51 -0
- data/lib/gitlab/styles/rubocop/cop/style/hash_transformation.rb +87 -0
- data/lib/gitlab/styles/rubocop/rspec/helpers.rb +2 -1
- data/lib/gitlab/styles/version.rb +1 -1
- data/rubocop-code_reuse.yml +4 -0
- data/rubocop-migrations.yml +3 -0
- data/rubocop-performance.yml +9 -0
- data/rubocop-rails.yml +8 -0
- data/rubocop-rspec.yml +3 -0
- data/rubocop-security.yml +3 -0
- data/rubocop-style.yml +10 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdb4b922d729575676263e2cb9cf6f63b50be1d8b4205d96af7ecb6aaa2c4c84
|
4
|
+
data.tar.gz: 46a11af0a19079547b1d25e988e80d8271a5fe15fda707096662aee73a4cc9c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df88cc8b9ea74b138c8768130b310d50d2204bed62e4648b292a8b0f058dad46335e23432564a546e0acc0ae9ef3c8a2487f4690f8e4ee2a73e6209665441746
|
7
|
+
data.tar.gz: 2d744fd1097268298c1073404bf84ddd4d65b28dbfa4b5bfad95857ea310734d24f93b81870e0c03454c26a2aa8de19470c7f75374e73db25ac0067a2665bebf
|
data/.gitlab-ci.yml
CHANGED
@@ -14,8 +14,8 @@ workflow:
|
|
14
14
|
rules:
|
15
15
|
# For merge requests, create a pipeline.
|
16
16
|
- if: '$CI_MERGE_REQUEST_IID'
|
17
|
-
# For
|
18
|
-
- if: '$CI_COMMIT_BRANCH ==
|
17
|
+
# For the default branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
|
18
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
19
19
|
# For tags, create a pipeline.
|
20
20
|
- if: '$CI_COMMIT_TAG'
|
21
21
|
|
data/gitlab-styles.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_dependency 'rubocop', '~> 0.91.1'
|
25
|
+
spec.add_dependency 'rubocop', '~> 0.91', '>= 0.91.1'
|
26
26
|
spec.add_dependency 'rubocop-gitlab-security', '~> 0.1.1'
|
27
27
|
spec.add_dependency 'rubocop-performance', '~> 1.9.2'
|
28
28
|
spec.add_dependency 'rubocop-rails', '~> 2.9'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../model_helpers'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module Styles
|
7
|
+
module Rubocop
|
8
|
+
module Cop
|
9
|
+
module Rails
|
10
|
+
class IncludeUrlHelper < RuboCop::Cop::Cop
|
11
|
+
MSG = <<~MSG
|
12
|
+
Avoid including `ActionView::Helpers::UrlHelper`.
|
13
|
+
It adds/overrides ~40 methods while usually only one is needed.
|
14
|
+
Instead, use the `Gitlab::Routing.url_helpers`/`Application.routes.url_helpers`(outside of gitlab)
|
15
|
+
and `ActionController::Base.helpers.link_to`.
|
16
|
+
See https://gitlab.com/gitlab-org/gitlab/-/issues/340567.
|
17
|
+
MSG
|
18
|
+
|
19
|
+
def_node_matcher :include_url_helpers_node?, <<~PATTERN
|
20
|
+
(send nil? :include (const (const (const {nil? cbase} :ActionView) :Helpers) :UrlHelper))
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
add_offense(node) if include_url_helpers_node?(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop-rspec'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module Gitlab
|
7
|
+
module Styles
|
8
|
+
module Rubocop
|
9
|
+
module Cop
|
10
|
+
module RSpec
|
11
|
+
# Checks if there is an empty line after the last `let_it_be` block.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # bad
|
15
|
+
# let_it_be(:foo) { bar }
|
16
|
+
# let_it_be(:something) { other }
|
17
|
+
# it { does_something }
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# let_it_be(:foo) { bar }
|
21
|
+
# let_it_be(:something) { other }
|
22
|
+
#
|
23
|
+
# it { does_something }
|
24
|
+
class EmptyLineAfterFinalLetItBe < Base
|
25
|
+
extend RuboCop::Cop::AutoCorrector
|
26
|
+
include RuboCop::RSpec::EmptyLineSeparation
|
27
|
+
|
28
|
+
MSG = 'Add an empty line after the last `let_it_be`.'
|
29
|
+
|
30
|
+
def_node_matcher :let_it_be?, <<-PATTERN
|
31
|
+
{
|
32
|
+
(block (send #rspec? {:let_it_be :let_it_be_with_refind :let_it_be_with_reload} ...) ...)
|
33
|
+
(send #rspec? {:let_it_be :let_it_be_with_refind :let_it_be_with_reload} _ block_pass)
|
34
|
+
}
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
def on_block(node)
|
38
|
+
return unless example_group_with_body?(node)
|
39
|
+
|
40
|
+
final_let_it_be = node.body.child_nodes.reverse.find { |child| let_it_be?(child) }
|
41
|
+
|
42
|
+
return if final_let_it_be.nil?
|
43
|
+
|
44
|
+
missing_separating_line_offense(final_let_it_be) { MSG }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module Styles
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
module Style
|
8
|
+
# This cop identifies places where `map { ... }.to_h` or
|
9
|
+
# `Hash[map { ... }]` can be replaced with `to_h { ... }`,
|
10
|
+
# saving an intermediate array allocation.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# hash.map { |k, v| [v.upcase, k.downcase] }.to_h
|
15
|
+
# hash.collect { |k, v| [v.upcase, k.downcase] }.to_h
|
16
|
+
# Hash[hash.map { |k, v| [v.upcase, k.downcase] }]
|
17
|
+
# Hash[hash.collect { |k, v| [v.upcase, k.downcase] }]
|
18
|
+
# array.map { |x| [x, x + 1] }.to_h
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# hash.to_h { |k, v| [v.upcase, k.downcase] }
|
22
|
+
# array.to_h { |x| [x, x + 1] }
|
23
|
+
#
|
24
|
+
# Full credit: https://github.com/eugeneius/rubocop-performance/blob/hash_transformation/lib/rubocop/cop/performance/hash_transformation.rb
|
25
|
+
class HashTransformation < RuboCop::Cop::Cop
|
26
|
+
include RuboCop::Cop::RangeHelp
|
27
|
+
|
28
|
+
MSG = 'Use `to_h { ... }` instead of `%<current>s`.'
|
29
|
+
|
30
|
+
def_node_matcher :to_h_candidate?, <<~PATTERN
|
31
|
+
{
|
32
|
+
[(send
|
33
|
+
$(block $(send _ {:map :collect}) ...) :to_h) !block_literal?]
|
34
|
+
(send (const nil? :Hash) :[]
|
35
|
+
$(block $(send _ {:map :collect}) ...))
|
36
|
+
}
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
to_h_candidate?(node) do |_block, call|
|
41
|
+
range = offense_range(node, call)
|
42
|
+
message = message(node, call)
|
43
|
+
add_offense(node, location: range, message: message)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
block, call = to_h_candidate?(node)
|
49
|
+
|
50
|
+
lambda do |corrector|
|
51
|
+
corrector.remove(after_block(node, block))
|
52
|
+
corrector.replace(call.loc.selector, 'to_h')
|
53
|
+
corrector.remove(before_block(node, block))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def offense_range(node, call)
|
60
|
+
return node.source_range if node.children.first.const_type?
|
61
|
+
|
62
|
+
range_between(call.loc.selector.begin_pos, node.loc.selector.end_pos)
|
63
|
+
end
|
64
|
+
|
65
|
+
def message(node, call)
|
66
|
+
current = if node.children.first.const_type?
|
67
|
+
"Hash[#{call.method_name} { ... }]"
|
68
|
+
else
|
69
|
+
"#{call.method_name} { ... }.to_h"
|
70
|
+
end
|
71
|
+
|
72
|
+
format(MSG, current: current)
|
73
|
+
end
|
74
|
+
|
75
|
+
def after_block(node, block)
|
76
|
+
block.source_range.end.join(node.source_range.end)
|
77
|
+
end
|
78
|
+
|
79
|
+
def before_block(node, block)
|
80
|
+
node.source_range.begin.join(block.source_range.begin)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -9,7 +9,8 @@ module Gitlab
|
|
9
9
|
module Helpers
|
10
10
|
include RuboCop::RSpec::Language
|
11
11
|
|
12
|
-
|
12
|
+
LET_IT_BE_HELPERS = SelectorSet.new(%i[let_it_be let_it_be_with_refind let_it_be_with_reload])
|
13
|
+
LET = LET_IT_BE_HELPERS + RuboCop::RSpec::Language::Helpers::ALL
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/rubocop-code_reuse.yml
CHANGED
data/rubocop-migrations.yml
CHANGED
data/rubocop-performance.yml
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
---
|
2
|
+
require:
|
3
|
+
- rubocop-performance
|
4
|
+
|
2
5
|
# Used to identify usages of ancestors.include? and change them to use ⇐ instead.
|
3
6
|
# https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performanceancestorsinclude
|
4
7
|
Performance/AncestorsInclude:
|
@@ -35,6 +38,12 @@ Performance/DoubleStartEndWith:
|
|
35
38
|
Performance/MethodObjectAsBlock: # (new in 1.9)
|
36
39
|
Enabled: true
|
37
40
|
|
41
|
+
# Use `Struct.new(..., keyword_init: true)` instead of `OpenStruct.new(...)`.
|
42
|
+
Performance/OpenStruct:
|
43
|
+
Enabled: true
|
44
|
+
Exclude:
|
45
|
+
- 'spec/**/*'
|
46
|
+
|
38
47
|
# Use `Range#cover?` instead of `Range#include?`.
|
39
48
|
Performance/RangeInclude:
|
40
49
|
Enabled: true
|
data/rubocop-rails.yml
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
---
|
2
|
+
require:
|
3
|
+
- rubocop-rails
|
4
|
+
- ./lib/gitlab/styles/rubocop
|
5
|
+
|
2
6
|
# Enables Rails cops.
|
3
7
|
Rails:
|
4
8
|
Enabled: true
|
@@ -183,3 +187,7 @@ Rails/WhereExists:
|
|
183
187
|
# https://docs.rubocop.org/rubocop-rails/2.8/cops_rails.html#railswherenot
|
184
188
|
Rails/WhereNot:
|
185
189
|
Enabled: true
|
190
|
+
|
191
|
+
# Bans the use of `include ActionView::Helpers::UrlHelper`.
|
192
|
+
Rails/IncludeUrlHelper:
|
193
|
+
Enabled: true
|
data/rubocop-rspec.yml
CHANGED
data/rubocop-security.yml
CHANGED
data/rubocop-style.yml
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
---
|
2
|
+
require:
|
3
|
+
- ./lib/gitlab/styles/rubocop
|
4
|
+
|
2
5
|
# Checks for grouping of accessors in class and module bodies.
|
3
6
|
# https://docs.rubocop.org/rubocop/0.89/cops_style.html#styleaccessorgrouping
|
4
7
|
Style/AccessorGrouping:
|
@@ -187,6 +190,13 @@ Style/HashTransformKeys:
|
|
187
190
|
Style/HashTransformValues:
|
188
191
|
Enabled: true
|
189
192
|
|
193
|
+
|
194
|
+
# This cop identifies places where `map { ... }.to_h` or
|
195
|
+
# `Hash[map { ... }]` can be replaced with `to_h { ... }`,
|
196
|
+
# saving an intermediate array allocation.
|
197
|
+
Style/HashTransformation:
|
198
|
+
Enabled: true
|
199
|
+
|
190
200
|
# Checks that conditional statements do not have an identical line at the
|
191
201
|
# end of each branch, which can validly be moved out of the conditional.
|
192
202
|
Style/IdenticalConditionalBranches:
|
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-styles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.3.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-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.91'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 0.91.1
|
20
23
|
type: :runtime
|
@@ -22,6 +25,9 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.91'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 0.91.1
|
27
33
|
- !ruby/object:Gem::Dependency
|
@@ -158,14 +164,17 @@ files:
|
|
158
164
|
- lib/gitlab/styles/rubocop/cop/line_break_around_conditional_block.rb
|
159
165
|
- lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb
|
160
166
|
- lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
|
167
|
+
- lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb
|
161
168
|
- lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
|
162
169
|
- lib/gitlab/styles/rubocop/cop/rspec/base.rb
|
170
|
+
- lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_final_let_it_be.rb
|
163
171
|
- lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb
|
164
172
|
- lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
|
165
173
|
- lib/gitlab/styles/rubocop/cop/rspec/example_starting_character.rb
|
166
174
|
- lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
|
167
175
|
- lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
|
168
176
|
- lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb
|
177
|
+
- lib/gitlab/styles/rubocop/cop/style/hash_transformation.rb
|
169
178
|
- lib/gitlab/styles/rubocop/cop/without_reactive_cache.rb
|
170
179
|
- lib/gitlab/styles/rubocop/migration_helpers.rb
|
171
180
|
- lib/gitlab/styles/rubocop/model_helpers.rb
|
@@ -205,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
214
|
- !ruby/object:Gem::Version
|
206
215
|
version: '0'
|
207
216
|
requirements: []
|
208
|
-
rubygems_version: 3.1.
|
217
|
+
rubygems_version: 3.1.6
|
209
218
|
signing_key:
|
210
219
|
specification_version: 4
|
211
220
|
summary: GitLab style guides and shared style configs.
|