gitlab-styles 3.3.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.gitlab-ci.yml +36 -4
  4. data/.gitlab/merge_request_templates/Release.md +35 -0
  5. data/Gemfile +4 -1
  6. data/README.md +5 -0
  7. data/Rakefile +2 -0
  8. data/gitlab-styles.gemspec +6 -4
  9. data/lib/gitlab/styles.rb +2 -0
  10. data/lib/gitlab/styles/rubocop.rb +5 -0
  11. data/lib/gitlab/styles/rubocop/cop/active_record_dependent.rb +3 -1
  12. data/lib/gitlab/styles/rubocop/cop/active_record_serialize.rb +3 -1
  13. data/lib/gitlab/styles/rubocop/cop/custom_error_class.rb +3 -1
  14. data/lib/gitlab/styles/rubocop/cop/gem_fetcher.rb +3 -1
  15. data/lib/gitlab/styles/rubocop/cop/in_batches.rb +3 -1
  16. data/lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb +3 -1
  17. data/lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb +64 -0
  18. data/lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb +3 -1
  19. data/lib/gitlab/styles/rubocop/cop/redirect_with_status.rb +3 -1
  20. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb +65 -0
  21. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb +65 -0
  22. data/lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb +3 -1
  23. data/lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb +3 -1
  24. data/lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb +3 -1
  25. data/lib/gitlab/styles/rubocop/cop/without_reactive_cache.rb +3 -1
  26. data/lib/gitlab/styles/rubocop/migration_helpers.rb +2 -0
  27. data/lib/gitlab/styles/rubocop/model_helpers.rb +2 -0
  28. data/lib/gitlab/styles/version.rb +3 -1
  29. data/rubocop-all.yml +1 -1
  30. data/rubocop-default.yml +1 -0
  31. data/rubocop-layout.yml +32 -22
  32. data/rubocop-lint.yml +18 -14
  33. data/rubocop-metrics.yml +0 -6
  34. data/rubocop-migrations.yml +21 -0
  35. data/rubocop-naming.yml +8 -8
  36. data/rubocop-rspec.yml +8 -0
  37. data/rubocop-style.yml +29 -14
  38. metadata +14 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b678f69301c072f2a4ff3568240a53603af1dde32d22b4bcc7bfde79477fb281
4
- data.tar.gz: c5c3462573f631914c3bd10bd84589cec1f3f75c39e40acf11b9fca28c110e50
3
+ metadata.gz: 00dda1d4ea5cfd931d74ccf3def7dd6ed3552359c2519e7b6a73464cb3612b92
4
+ data.tar.gz: 8fd90715af2921b22e53d241f12e4a546f8d53923a688028132af3e5e28f0349
5
5
  SHA512:
6
- metadata.gz: 57d30093fc6fbe46cb2039e89c16f68b97dab5d2e794e75f8ab732c8e723887bd1dc3dd3708561d12767055b46820a413a495bf3a1790af4f1caf1f4f128230f
7
- data.tar.gz: b58567db3d26db1a13f5c6327484f34cb79bc5914a1a27357b54cbe41e88fb5efbffba56d2605630c66dd91cc4cd9d5078e276cf6425caed7af789fcfd8bfa92
6
+ metadata.gz: 58e29fee8c087356c272e72e9d3a8b719581e5f185ceed85d554a9ccb664654288373b2a6d1e4c1ba9587bfce4c2225960797e4c89e321688da8fa52d4a12b81
7
+ data.tar.gz: a2c2f9843238a87f1af60f28beac5ec8c1ae5f1d236ab1554e88d07f95824e6474dda3b96ff5ec26a3219015c5415ea21824d41cc98d3cd06990b5ff55104097
data/.gitignore CHANGED
@@ -3,10 +3,12 @@
3
3
  /Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
- /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
10
9
 
11
10
  # rspec failure tracking
12
11
  .rspec_status
12
+
13
+ # Ignore IDE specific files
14
+ .idea/
@@ -1,13 +1,45 @@
1
- image: ruby:2.3
1
+ stages:
2
+ - release
3
+ - test
2
4
 
3
- before_script:
4
- - bundle --version
5
- - bundle install
5
+ default:
6
+ image: ruby:2.6
7
+ tags:
8
+ - gitlab-org
9
+ before_script:
10
+ - bundle --version
11
+ - bundle install
12
+
13
+ workflow:
14
+ rules:
15
+ # For merge requests, create a pipeline.
16
+ - if: '$CI_MERGE_REQUEST_IID'
17
+ # For `master` branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
18
+ - if: '$CI_COMMIT_BRANCH == "master"'
19
+ # For tags, create a pipeline.
20
+ - if: '$CI_COMMIT_TAG'
6
21
 
7
22
  styles:
23
+ stage: test
8
24
  script:
9
25
  - bundle exec rubocop --debug --parallel
10
26
 
11
27
  specs:
28
+ stage: test
12
29
  script:
13
30
  - bundle exec rspec
31
+
32
+ release:
33
+ stage: release
34
+ rules:
35
+ - if: '$CI_COMMIT_TAG'
36
+ script:
37
+ - gem update --system
38
+ - ruby --version
39
+ - gem env version
40
+ - gem build gitlab-styles.gemspec
41
+ - gem push gitlab-styles*.gem
42
+ artifacts:
43
+ paths:
44
+ - gitlab-styles*.gem
45
+ expire_in: 30 days
@@ -0,0 +1,35 @@
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
4
+
5
+ - Release notes:
6
+
7
+ <!-- Keep the sections order but remove the empty sections -->
8
+
9
+ ```markdown
10
+ ### New scenarios and scenario updates
11
+
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 (CI, backstage)
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
+ - [ ] [Create a tag for the new release version](docs/release_process.md#how-to).
34
+
35
+ /label ~"Engineering Productivity" ~"tooling::workflow"
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in gitlab-rubocop.gemspec
@@ -5,6 +7,7 @@ gemspec
5
7
 
6
8
  group :test do
7
9
  # Pin these dependencies, otherwise a new rule could break the CI pipelines
8
- gem 'rubocop', '0.74.0'
10
+ gem 'rubocop', '0.82.0'
9
11
  gem 'rubocop-rspec', '1.36.0'
12
+ gem 'rspec-parameterized', '0.4.2', require: false
10
13
  end
data/README.md CHANGED
@@ -42,6 +42,7 @@ rules:
42
42
  - `rubocop-gemspec.yml`
43
43
  - `rubocop-layout.yml`
44
44
  - `rubocop-lint.yml`
45
+ - `rubocop-migrations.yml`
45
46
  - `rubocop-metrics.yml`
46
47
  - `rubocop-naming.yml`
47
48
  - `rubocop-performance.yml`
@@ -77,6 +78,10 @@ https://gitlab.com/gitlab-org/gitlab-styles. This project is intended to be a
77
78
  safe, welcoming space for collaboration, and contributors are expected to adhere
78
79
  to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
80
 
81
+ ## Release Process
82
+
83
+ Please refer to the [Release Process](docs/release_process.md).
84
+
80
85
  ## License
81
86
 
82
87
  The gem is available as open source under the terms of the
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'gitlab/styles/version'
@@ -13,16 +15,16 @@ Gem::Specification.new do |spec|
13
15
  spec.license = 'MIT'
14
16
 
15
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
18
+ f.match(%r{^(docs|test|spec|features)/})
17
19
  end
18
20
  spec.bindir = 'exe'
19
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
22
  spec.require_paths = ['lib']
21
23
 
22
- spec.add_dependency 'rubocop', '~> 0.74.0'
24
+ spec.add_dependency 'rubocop', '~> 0.82.0'
23
25
  spec.add_dependency 'rubocop-gitlab-security', '~> 0.1.0'
24
- spec.add_dependency 'rubocop-performance', '~> 1.4.1'
25
- spec.add_dependency 'rubocop-rails', '~> 2.0'
26
+ spec.add_dependency 'rubocop-performance', '~> 1.5.2'
27
+ spec.add_dependency 'rubocop-rails', '~> 2.5'
26
28
  spec.add_dependency 'rubocop-rspec', '~> 1.36'
27
29
 
28
30
  spec.add_development_dependency 'bundler', '~> 1.16'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab/styles/version'
2
4
 
3
5
  module Gitlab
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gitlab/styles/rubocop/cop/custom_error_class'
2
4
  require 'gitlab/styles/rubocop/cop/gem_fetcher'
3
5
  require 'gitlab/styles/rubocop/cop/active_record_serialize'
@@ -6,10 +8,13 @@ require 'gitlab/styles/rubocop/cop/polymorphic_associations'
6
8
  require 'gitlab/styles/rubocop/cop/active_record_dependent'
7
9
  require 'gitlab/styles/rubocop/cop/in_batches'
8
10
  require 'gitlab/styles/rubocop/cop/line_break_after_guard_clauses'
11
+ require 'gitlab/styles/rubocop/cop/migration/update_large_table'
9
12
  require 'gitlab/styles/rubocop/cop/without_reactive_cache'
10
13
  require 'gitlab/styles/rubocop/cop/rspec/single_line_hook'
11
14
  require 'gitlab/styles/rubocop/cop/rspec/have_link_parameters'
12
15
  require 'gitlab/styles/rubocop/cop/rspec/verbose_include_metadata'
16
+ require 'gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example'
17
+ require 'gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block'
13
18
 
14
19
  module Gitlab
15
20
  module Styles
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../model_helpers'
2
4
 
3
5
  module Gitlab
@@ -9,7 +11,7 @@ module Gitlab
9
11
  include ModelHelpers
10
12
 
11
13
  MSG = 'Do not use `dependent: to remove associated data, ' \
12
- 'use foreign keys with cascading deletes instead'.freeze
14
+ 'use foreign keys with cascading deletes instead'
13
15
 
14
16
  METHOD_NAMES = [:has_many, :has_one, :belongs_to].freeze
15
17
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../model_helpers'
2
4
 
3
5
  module Gitlab
@@ -8,7 +10,7 @@ module Gitlab
8
10
  class ActiveRecordSerialize < RuboCop::Cop::Cop
9
11
  include ModelHelpers
10
12
 
11
- MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'.freeze
13
+ MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'
12
14
 
13
15
  def on_send(node)
14
16
  return unless in_model?(node)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
@@ -16,7 +18,7 @@ module Gitlab
16
18
  # # good
17
19
  # FooError = Class.new(StandardError)
18
20
  class CustomErrorClass < RuboCop::Cop::Cop
19
- MSG = 'Use `Class.new(SuperClass)` to define an empty custom error class.'.freeze
21
+ MSG = 'Use `Class.new(SuperClass)` to define an empty custom error class.'
20
22
 
21
23
  def on_class(node)
22
24
  _klass, parent, body = node.children
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
@@ -6,7 +8,7 @@ module Gitlab
6
8
  # `Gemfile` in order to avoid additional points of failure beyond
7
9
  # rubygems.org.
8
10
  class GemFetcher < RuboCop::Cop::Cop
9
- MSG = 'Do not use gems from git repositories, only use gems from RubyGems.'.freeze
11
+ MSG = 'Do not use gems from git repositories, only use gems from RubyGems.'
10
12
 
11
13
  GIT_KEYS = [:git, :github].freeze
12
14
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../model_helpers'
2
4
 
3
5
  module Gitlab
@@ -6,7 +8,7 @@ module Gitlab
6
8
  module Cop
7
9
  # Cop that prevents the use of `in_batches`
8
10
  class InBatches < RuboCop::Cop::Cop
9
- MSG = 'Do not use `in_batches`, use `each_batch` from the EachBatch module instead'.freeze
11
+ MSG = 'Do not use `in_batches`, use `each_batch` from the EachBatch module instead'
10
12
 
11
13
  def on_send(node)
12
14
  return unless node.children[1] == :in_batches
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
@@ -56,7 +58,7 @@ module Gitlab
56
58
  #
57
59
  # do_something_more
58
60
  class LineBreakAfterGuardClauses < RuboCop::Cop::Cop
59
- MSG = 'Add a line break after guard clauses'.freeze
61
+ MSG = 'Add a line break after guard clauses'
60
62
 
61
63
  def_node_matcher :guard_clause_node?, <<-PATTERN
62
64
  [{(send nil? {:raise :fail :throw} ...) return break next} single_line?]
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../../migration_helpers'
3
+
4
+ module Gitlab
5
+ module Styles
6
+ module Rubocop
7
+ module Cop
8
+ module Migration
9
+ # This cop checks for methods that may lead to batch type issues on a table that's been
10
+ # explicitly denied because of its size.
11
+ #
12
+ # Even though though these methods perform functions to avoid
13
+ # downtime, using it with tables with millions of rows still causes a
14
+ # significant delay in the deploy process and is best avoided.
15
+ #
16
+ # See https://gitlab.com/gitlab-com/infrastructure/issues/1602 for more
17
+ # information.
18
+ class UpdateLargeTable < RuboCop::Cop::Cop
19
+ include MigrationHelpers
20
+
21
+ MSG = 'Using `%s` on the `%s` table will take a long time to ' \
22
+ 'complete, and should be avoided unless absolutely ' \
23
+ 'necessary'
24
+
25
+ def_node_matcher :batch_update?, <<~PATTERN
26
+ (send nil? ${#denied_method?}
27
+ (sym $...)
28
+ ...)
29
+ PATTERN
30
+
31
+ def on_send(node)
32
+ return if denied_tables.empty? || denied_methods.empty?
33
+ return unless in_migration?(node)
34
+
35
+ matches = batch_update?(node)
36
+ return unless matches
37
+
38
+ update_method = matches.first
39
+ table = matches.last.to_a.first
40
+
41
+ return unless denied_tables.include?(table)
42
+
43
+ add_offense(node, location: :expression, message: format(MSG, update_method, table))
44
+ end
45
+
46
+ private
47
+
48
+ def denied_tables
49
+ cop_config['DeniedTables'] || []
50
+ end
51
+
52
+ def denied_method?(method_name)
53
+ denied_methods.include?(method_name)
54
+ end
55
+
56
+ def denied_methods
57
+ cop_config['DeniedMethods'] || []
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../model_helpers'
2
4
 
3
5
  module Gitlab
@@ -8,7 +10,7 @@ module Gitlab
8
10
  class PolymorphicAssociations < RuboCop::Cop::Cop
9
11
  include ModelHelpers
10
12
 
11
- MSG = 'Do not use polymorphic associations, use separate tables instead'.freeze
13
+ MSG = 'Do not use polymorphic associations, use separate tables instead'
12
14
 
13
15
  def on_send(node)
14
16
  return unless in_model?(node)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
@@ -5,7 +7,7 @@ module Gitlab
5
7
  # This cop prevents usage of 'redirect_to' in actions 'destroy' without specifying 'status'.
6
8
  # See https://gitlab.com/gitlab-org/gitlab-ce/issues/31840
7
9
  class RedirectWithStatus < RuboCop::Cop::Cop
8
- MSG = 'Do not use "redirect_to" without "status" in "destroy" action'.freeze
10
+ MSG = 'Do not use "redirect_to" without "status" in "destroy" action'
9
11
 
10
12
  def on_def(node)
11
13
  return unless in_controller?(node)
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop-rspec'
4
+
5
+ module Gitlab
6
+ module Styles
7
+ module Rubocop
8
+ module Cop
9
+ module RSpec
10
+ # Checks if there is an empty line after let blocks.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # RSpec.describe Foo do
15
+ # let(:something) { 'something' }
16
+ # let(:another_thing) do
17
+ # end
18
+ # let(:something_else) do
19
+ # end
20
+ # let(:last_thing) { 'last thing' }
21
+ # end
22
+ #
23
+ # # good
24
+ # RSpec.describe Foo do
25
+ # let(:something) { 'something' }
26
+ # let(:another_thing) do
27
+ # end
28
+ #
29
+ # let(:something_else) do
30
+ # end
31
+ #
32
+ # let(:last_thing) { 'last thing' }
33
+ # end
34
+ #
35
+ # # good - it's ok to have non-separated without do/end blocks
36
+ # RSpec.describe Foo do
37
+ # let(:something) { 'something' }
38
+ # let(:last_thing) { 'last thing' }
39
+ # end
40
+ #
41
+ class EmptyLineAfterLetBlock < RuboCop::Cop::RSpec::Cop
42
+ include RuboCop::RSpec::BlankLineSeparation
43
+
44
+ MSG = 'Add an empty line after `%<let>s` block.'
45
+
46
+ def_node_matcher :lets, Helpers::ALL.block_pattern
47
+
48
+ def on_block(node)
49
+ lets(node) do
50
+ break if last_child?(node)
51
+ next if node.single_line?
52
+
53
+ missing_separating_line(node) do |location|
54
+ add_offense(node,
55
+ location: location,
56
+ message: format(MSG, let: node.method_name))
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop-rspec'
4
+
5
+ module Gitlab
6
+ module Styles
7
+ module Rubocop
8
+ module Cop
9
+ module RSpec
10
+ # Checks if there is an empty line after shared example blocks.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # RSpec.describe Foo do
15
+ # it_behaves_like 'do this first'
16
+ # it_behaves_like 'does this' do
17
+ # end
18
+ # it_behaves_like 'does that' do
19
+ # end
20
+ # it_behaves_like 'do some more'
21
+ # end
22
+ #
23
+ # # good
24
+ # RSpec.describe Foo do
25
+ # it_behaves_like 'do this first'
26
+ # it_behaves_like 'does this' do
27
+ # end
28
+ #
29
+ # it_behaves_like 'does that' do
30
+ # end
31
+ #
32
+ # it_behaves_like 'do some more'
33
+ # end
34
+ #
35
+ # # fair - it's ok to have non-separated without blocks
36
+ # RSpec.describe Foo do
37
+ # it_behaves_like 'do this first'
38
+ # it_behaves_like 'does this'
39
+ # end
40
+ #
41
+ class EmptyLineAfterSharedExample < RuboCop::Cop::RSpec::Cop
42
+ include RuboCop::RSpec::BlankLineSeparation
43
+
44
+ MSG = 'Add an empty line after `%<example>s` block.'
45
+
46
+ def_node_matcher :shared_examples,
47
+ (SharedGroups::ALL + Includes::ALL).block_pattern
48
+
49
+ def on_block(node)
50
+ shared_examples(node) do
51
+ break if last_child?(node)
52
+
53
+ missing_separating_line(node) do |location|
54
+ add_offense(node,
55
+ location: location,
56
+ message: format(MSG, example: node.method_name))
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubocop-rspec'
2
4
 
3
5
  module Gitlab
@@ -16,7 +18,7 @@ module Gitlab
16
18
  # expect(page).to have_link('Link', href: 'https://example.com')
17
19
  # expect(page).to have_link('Example')
18
20
  class HaveLinkParameters < RuboCop::Cop::RSpec::Cop
19
- MESSAGE = "The second argument to `have_link` should be a Hash.".freeze
21
+ MESSAGE = "The second argument to `have_link` should be a Hash."
20
22
 
21
23
  def_node_matcher :unused_parameters?, <<~PATTERN
22
24
  (send nil? :have_link
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubocop-rspec'
2
4
 
3
5
  module Gitlab
@@ -22,7 +24,7 @@ module Gitlab
22
24
  # undo_something
23
25
  # end
24
26
  class SingleLineHook < RuboCop::Cop::RSpec::Cop
25
- MESSAGE = "Don't use single-line hook blocks.".freeze
27
+ MESSAGE = "Don't use single-line hook blocks."
26
28
 
27
29
  def_node_search :rspec_hook?, <<~PATTERN
28
30
  (send nil? {:after :around :before} ...)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubocop-rspec'
2
4
 
3
5
  module Gitlab
@@ -16,7 +18,7 @@ module Gitlab
16
18
  # describe MyClass, :js do
17
19
  # end
18
20
  class VerboseIncludeMetadata < RuboCop::Cop::RSpec::Cop
19
- MSG = 'Use `%s` instead of `%s`.'.freeze
21
+ MSG = 'Use `%s` instead of `%s`.'
20
22
 
21
23
  SELECTORS = %i[describe context feature example_group it specify example scenario its].freeze
22
24
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
4
6
  module Cop
5
7
  # Cop that prevents the use of `without_reactive_cache`
6
8
  class WithoutReactiveCache < RuboCop::Cop::Cop
7
- MSG = 'without_reactive_cache is for debugging purposes only. Please use with_reactive_cache.'.freeze
9
+ MSG = 'without_reactive_cache is for debugging purposes only. Please use with_reactive_cache.'
8
10
 
9
11
  def on_send(node)
10
12
  return unless node.children[1] == :without_reactive_cache
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
5
  module Rubocop
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module Styles
3
- VERSION = '3.3.0'.freeze
5
+ VERSION = '4.3.0'
4
6
  end
5
7
  end
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.6
3
3
  # Cop names are not displayed in offense messages by default. Change behavior
4
4
  # by overriding DisplayCopNames, or by giving the -D/--display-cop-names
5
5
  # option.
@@ -12,6 +12,7 @@ inherit_from:
12
12
  - rubocop-layout.yml
13
13
  - rubocop-lint.yml
14
14
  - rubocop-metrics.yml
15
+ - rubocop-migrations.yml
15
16
  - rubocop-naming.yml
16
17
  - rubocop-performance.yml
17
18
  - rubocop-rails.yml
@@ -3,18 +3,14 @@ Layout/AccessModifierIndentation:
3
3
  Enabled: true
4
4
 
5
5
  # Align the elements of an array literal if they span more than one line.
6
- Layout/AlignArray:
6
+ Layout/ArrayAlignment:
7
7
  Enabled: true
8
8
 
9
- # Align the elements of a hash literal if they span more than one line.
10
- Layout/AlignHash:
9
+ # Checks the indentation of the first line of the right-hand-side of a
10
+ # multi-line assignment.
11
+ Layout/AssignmentIndentation:
11
12
  Enabled: true
12
13
 
13
- # Here we check if the parameters on a multi-line method call or
14
- # definition are aligned.
15
- Layout/AlignParameters:
16
- Enabled: false
17
-
18
14
  # Align block ends correctly.
19
15
  Layout/BlockAlignment:
20
16
  Enabled: true
@@ -102,27 +98,36 @@ Layout/ExtraSpacing:
102
98
  Layout/FirstMethodParameterLineBreak:
103
99
  Enabled: true
104
100
 
101
+ # Align the elements of a hash literal if they span more than one line.
102
+ Layout/HashAlignment:
103
+ Enabled: true
104
+
105
+ # This cops checks the indentation of the here document bodies.
106
+ Layout/HeredocIndentation:
107
+ Enabled: false
108
+
105
109
  # Keep indentation straight.
106
110
  Layout/IndentationConsistency:
107
111
  Enabled: true
108
112
 
109
- # Use 2 spaces for indentation.
110
- Layout/IndentationWidth:
113
+ # No hard tabs.
114
+ Layout/IndentationStyle:
111
115
  Enabled: true
112
116
 
113
- # Checks the indentation of the first line of the right-hand-side of a
114
- # multi-line assignment.
115
- Layout/IndentAssignment:
117
+ # Use 2 spaces for indentation.
118
+ Layout/IndentationWidth:
116
119
  Enabled: true
117
120
 
118
- # This cops checks the indentation of the here document bodies.
119
- Layout/IndentHeredoc:
120
- Enabled: false
121
-
122
121
  # Comments should start with a space.
123
122
  Layout/LeadingCommentSpace:
124
123
  Enabled: true
125
124
 
125
+ # Limit lines to 120 characters.
126
+ Layout/LineLength:
127
+ Enabled: true
128
+ Max: 120
129
+ IgnoredPatterns: ['\s#\srubocop']
130
+
126
131
  # Checks that the closing brace in an array literal is either on the same line
127
132
  # as the last array element, or a new line.
128
133
  Layout/MultilineArrayBraceLayout:
@@ -160,6 +165,11 @@ Layout/MultilineOperationIndentation:
160
165
  Enabled: true
161
166
  EnforcedStyle: indented
162
167
 
168
+ # Here we check if the parameters on a multi-line method call or
169
+ # definition are aligned.
170
+ Layout/ParameterAlignment:
171
+ Enabled: false
172
+
163
173
  # Use spaces after colons.
164
174
  Layout/SpaceAfterColon:
165
175
  Enabled: true
@@ -189,6 +199,10 @@ Layout/SpaceAroundEqualsInParameterDefault:
189
199
  Layout/SpaceAroundKeyword:
190
200
  Enabled: true
191
201
 
202
+ # Checks method call operators to not have spaces around them.
203
+ Layout/SpaceAroundMethodCallOperator:
204
+ Enabled: true
205
+
192
206
  # Use a single space around operators.
193
207
  Layout/SpaceAroundOperators:
194
208
  Enabled: true
@@ -235,12 +249,8 @@ Layout/SpaceInsideStringInterpolation:
235
249
  EnforcedStyle: no_space
236
250
  Enabled: true
237
251
 
238
- # No hard tabs.
239
- Layout/Tab:
240
- Enabled: true
241
-
242
252
  # Checks trailing blank lines and final newline.
243
- Layout/TrailingBlankLines:
253
+ Layout/TrailingEmptyLines:
244
254
  Enabled: true
245
255
 
246
256
  # Avoid trailing whitespace.
@@ -47,10 +47,6 @@ Lint/EmptyEnsure:
47
47
  Lint/EmptyWhen:
48
48
  Enabled: true
49
49
 
50
- # END blocks should not be placed inside method definitions.
51
- Lint/EndInMethod:
52
- Enabled: true
53
-
54
50
  # Do not use return in an ensure block.
55
51
  Lint/EnsureReturn:
56
52
  Enabled: true
@@ -67,10 +63,6 @@ Lint/FloatOutOfRange:
67
63
  Lint/FormatParameterMismatch:
68
64
  Enabled: true
69
65
 
70
- # This cop checks for *rescue* blocks with no body.
71
- Lint/HandleExceptions:
72
- Enabled: false
73
-
74
66
  # Checks for adjacent string literals on the same line, which could better be
75
67
  # represented as a single string literal.
76
68
  Lint/ImplicitStringConcatenation:
@@ -105,11 +97,23 @@ Lint/NextWithoutAccumulator:
105
97
  Lint/ParenthesesAsGroupedExpression:
106
98
  Enabled: true
107
99
 
100
+ # Checks for raise or fail statements which are raising Exception class.
101
+ Lint/RaiseException:
102
+ Enabled: true
103
+
108
104
  # Checks for `rand(1)` calls. Such calls always return `0` and most likely
109
105
  # a mistake.
110
106
  Lint/RandOne:
111
107
  Enabled: true
112
108
 
109
+ # This cop checks for unneeded usages of splat expansion
110
+ Lint/RedundantSplatExpansion:
111
+ Enabled: false
112
+
113
+ # Checks for Object#to_s usage in string interpolation.
114
+ Lint/RedundantStringCoercion:
115
+ Enabled: true
116
+
113
117
  # Use parentheses in the method call to avoid confusion about precedence.
114
118
  Lint/RequireParentheses:
115
119
  Enabled: true
@@ -131,10 +135,14 @@ Lint/ShadowedException:
131
135
  Lint/ShadowingOuterLocalVariable:
132
136
  Enabled: false
133
137
 
134
- # Checks for Object#to_s usage in string interpolation.
135
- Lint/StringConversionInInterpolation:
138
+ # Checks unexpected overrides of the Struct built-in methods via Struct.new.
139
+ Lint/StructNewOverride:
136
140
  Enabled: true
137
141
 
142
+ # This cop checks for *rescue* blocks with no body.
143
+ Lint/SuppressedException:
144
+ Enabled: false
145
+
138
146
  # Do not use prefix `_` for a variable that is used.
139
147
  Lint/UnderscorePrefixedVariableName:
140
148
  Enabled: true
@@ -143,10 +151,6 @@ Lint/UnderscorePrefixedVariableName:
143
151
  Lint/UnifiedInteger:
144
152
  Enabled: true
145
153
 
146
- # This cop checks for unneeded usages of splat expansion
147
- Lint/UnneededSplatExpansion:
148
- Enabled: false
149
-
150
154
  # Unreachable code.
151
155
  Lint/UnreachableCode:
152
156
  Enabled: true
@@ -23,12 +23,6 @@ Metrics/CyclomaticComplexity:
23
23
  Enabled: true
24
24
  Max: 13
25
25
 
26
- # Limit lines to 120 characters.
27
- Metrics/LineLength:
28
- Enabled: true
29
- Max: 120
30
- IgnoredPatterns: ['\s#\srubocop']
31
-
32
26
  # Avoid methods longer than 10 lines of code.
33
27
  Metrics/MethodLength:
34
28
  Enabled: false
@@ -0,0 +1,21 @@
1
+ # Checks for methods that may lead to batch type issues on a table that's been
2
+ # explicitly denied because of its size.
3
+ #
4
+ # Even though these methods perform functions to avoid
5
+ # downtime, using it with tables with millions of rows still causes a
6
+ # significant delay in the deploy process and is best avoided.
7
+ #
8
+ # See https://gitlab.com/gitlab-com/infrastructure/issues/1602 for more
9
+ # information.
10
+ # The default can be changed as follows:
11
+ # Migration/UpdateLargeTable:
12
+ # DeniedTables:
13
+ # - :usage_data
14
+ # - :version_checks
15
+ # DeniedMethods:
16
+ # - :add_column_with_default
17
+ # - :change_column_type_concurrently
18
+ # - :rename_column_concurrently
19
+ # - :update_column_in_batches
20
+ Migration/UpdateLargeTable:
21
+ Enabled: false
@@ -30,6 +30,13 @@ Naming/MemoizedInstanceVariableName:
30
30
  Naming/MethodName:
31
31
  Enabled: true
32
32
 
33
+ # Method parameter names for how descriptive they are.
34
+ Naming/MethodParameterName:
35
+ Enabled: true
36
+ MinNameLength: 2
37
+ AllowedNames:
38
+ - _
39
+
33
40
  # Use `spam?` instead of `is_spam?`
34
41
  # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
35
42
  # NamePrefix: is_, has_, have_
@@ -37,18 +44,11 @@ Naming/MethodName:
37
44
  # NameWhitelist: is_a?
38
45
  Naming/PredicateName:
39
46
  Enabled: true
40
- NamePrefixBlacklist: is_
47
+ ForbiddenPrefixes: is_
41
48
  Exclude:
42
49
  - 'spec/**/*'
43
50
  - 'features/**/*'
44
51
 
45
- # Method parameter names for how descriptive they are.
46
- Naming/UncommunicativeMethodParamName:
47
- Enabled: true
48
- MinNameLength: 2
49
- AllowedNames:
50
- - _
51
-
52
52
  # Use the configured style when naming variables.
53
53
  Naming/VariableName:
54
54
  EnforcedStyle: snake_case
@@ -36,6 +36,14 @@ RSpec/EmptyExampleGroup:
36
36
  - it_should_email!
37
37
  - it_should_not_email!
38
38
 
39
+ # Checks if there is an empty line after let blocks.
40
+ RSpec/EmptyLineAfterLetBlock:
41
+ Enabled: true
42
+
43
+ # Checks if there is an empty line after shared example blocks.
44
+ RSpec/EmptyLineAfterSharedExample:
45
+ Enabled: true
46
+
39
47
  # Checks for long example.
40
48
  RSpec/ExampleLength:
41
49
  Enabled: false
@@ -33,11 +33,6 @@ Style/BlockComments:
33
33
  Style/BlockDelimiters:
34
34
  Enabled: true
35
35
 
36
- # This cop checks for braces around the last parameter in a method call
37
- # if the last parameter is a hash.
38
- Style/BracesAroundHashParameters:
39
- Enabled: false
40
-
41
36
  # This cop checks for uses of the case equality operator(===).
42
37
  Style/CaseEquality:
43
38
  Enabled: false
@@ -100,6 +95,10 @@ Style/EndBlock:
100
95
  Style/EvenOdd:
101
96
  Enabled: true
102
97
 
98
+ # Enforces consistency when using exponential notation for numbers in the code
99
+ Style/ExponentialNotation:
100
+ Enabled: true
101
+
103
102
  # Checks use of for or each in multiline loops.
104
103
  Style/For:
105
104
  Enabled: true
@@ -110,7 +109,7 @@ Style/FormatStringToken:
110
109
 
111
110
  # Checks if there is a magic comment to enforce string literals
112
111
  Style/FrozenStringLiteralComment:
113
- Enabled: false
112
+ Enabled: true
114
113
 
115
114
  # Do not introduce global variables.
116
115
  Style/GlobalVars:
@@ -119,11 +118,27 @@ Style/GlobalVars:
119
118
  - 'lib/backup/**/*'
120
119
  - 'lib/tasks/**/*'
121
120
 
121
+ # Checks for uses of each_key and each_value Hash methods.
122
+ Style/HashEachMethods:
123
+ Enabled: true
124
+
122
125
  # Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }`
123
126
  # over 1.8 syntax `{ :a => 1, :b => 2 }`.
124
127
  Style/HashSyntax:
125
128
  Enabled: true
126
129
 
130
+ # looks for uses of _.each_with_object({}) {...}, _.map {...}.to_h, and Hash[_.map {...}]
131
+ # that are actually just transforming the keys of a hash, and tries to use a simpler & faster
132
+ # call to transform_keys instead.
133
+ Style/HashTransformKeys:
134
+ Enabled: true
135
+
136
+ # looks for uses of _.each_with_object({}) {...}, _.map {...}.to_h, and Hash[_.map {...}]
137
+ # that are actually just transforming the values of a hash, and tries to use a simpler & faster
138
+ # call to transform_values instead.
139
+ Style/HashTransformValues:
140
+ Enabled: true
141
+
127
142
  # Checks that conditional statements do not have an identical line at the
128
143
  # end of each branch, which can validly be moved out of the conditional.
129
144
  Style/IdenticalConditionalBranches:
@@ -229,6 +244,10 @@ Style/ParenthesesAroundCondition:
229
244
  Style/PreferredHashMethods:
230
245
  Enabled: false
231
246
 
247
+ # Checks for %W when interpolation is not needed.
248
+ Style/RedundantCapitalW:
249
+ Enabled: true
250
+
232
251
  # Checks for an obsolete RuntimeException argument in raise/fail.
233
252
  Style/RedundantException:
234
253
  Enabled: true
@@ -237,6 +256,10 @@ Style/RedundantException:
237
256
  Style/RedundantParentheses:
238
257
  Enabled: true
239
258
 
259
+ # Checks for %q/%Q when single quotes or double quotes would do.
260
+ Style/RedundantPercentQ:
261
+ Enabled: false
262
+
240
263
  # Use `sort` instead of `sort_by { |x| x }`.
241
264
  Style/RedundantSortBy:
242
265
  Enabled: true
@@ -284,14 +307,6 @@ Style/TrailingCommaInArguments:
284
307
  Enabled: true
285
308
  EnforcedStyleForMultiline: no_comma
286
309
 
287
- # Checks for %W when interpolation is not needed.
288
- Style/UnneededCapitalW:
289
- Enabled: true
290
-
291
- # Checks for %q/%Q when single quotes or double quotes would do.
292
- Style/UnneededPercentQ:
293
- Enabled: false
294
-
295
310
  # Don't interpolate global, instance and class variables directly in strings.
296
311
  Style/VariableInterpolation:
297
312
  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: 3.3.0
4
+ version: 4.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: 2020-03-31 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.74.0
19
+ version: 0.82.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.74.0
26
+ version: 0.82.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-gitlab-security
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.4.1
47
+ version: 1.5.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.4.1
54
+ version: 1.5.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '2.5'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '2.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +131,7 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
133
  - ".gitlab-ci.yml"
134
+ - ".gitlab/merge_request_templates/Release.md"
134
135
  - ".rspec"
135
136
  - ".rubocop.yml"
136
137
  - ".rubocop_todo.yml"
@@ -151,8 +152,11 @@ files:
151
152
  - lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
152
153
  - lib/gitlab/styles/rubocop/cop/in_batches.rb
153
154
  - lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb
155
+ - lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb
154
156
  - lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
155
157
  - lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
158
+ - lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb
159
+ - lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
156
160
  - lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
157
161
  - lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
158
162
  - lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb
@@ -167,6 +171,7 @@ files:
167
171
  - rubocop-layout.yml
168
172
  - rubocop-lint.yml
169
173
  - rubocop-metrics.yml
174
+ - rubocop-migrations.yml
170
175
  - rubocop-naming.yml
171
176
  - rubocop-performance.yml
172
177
  - rubocop-rails.yml
@@ -192,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
197
  - !ruby/object:Gem::Version
193
198
  version: '0'
194
199
  requirements: []
195
- rubygems_version: 3.0.3
200
+ rubygems_version: 3.1.4
196
201
  signing_key:
197
202
  specification_version: 4
198
203
  summary: GitLab style guides and shared style configs.