gitlab-styles 6.6.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab/changelog_config.yml +13 -0
  3. data/.gitlab/merge_request_templates/Release.md +9 -31
  4. data/.gitlab-ci.yml +3 -1
  5. data/Dangerfile +5 -0
  6. data/gitlab-styles.gemspec +1 -0
  7. data/lib/gitlab/styles/common/banned_constants.rb +28 -0
  8. data/lib/gitlab/styles/rubocop/model_helpers.rb +1 -1
  9. data/lib/gitlab/styles/rubocop.rb +2 -2
  10. data/lib/gitlab/styles/version.rb +1 -1
  11. data/lib/rubocop/cop/active_record_dependent.rb +32 -0
  12. data/lib/rubocop/cop/active_record_serialize.rb +20 -0
  13. data/lib/rubocop/cop/avoid_return_from_blocks.rb +77 -0
  14. data/lib/rubocop/cop/code_reuse/active_record.rb +80 -0
  15. data/lib/rubocop/cop/custom_error_class.rb +69 -0
  16. data/lib/rubocop/cop/fips/md5.rb +27 -0
  17. data/lib/rubocop/cop/fips/open_ssl.rb +31 -0
  18. data/lib/rubocop/cop/fips/sha1.rb +27 -0
  19. data/lib/rubocop/cop/gem_fetcher.rb +37 -0
  20. data/lib/rubocop/cop/in_batches.rb +18 -0
  21. data/lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb +39 -0
  22. data/lib/rubocop/cop/line_break_after_guard_clauses.rb +100 -0
  23. data/lib/rubocop/cop/line_break_around_conditional_block.rb +128 -0
  24. data/lib/rubocop/cop/migration/update_large_table.rb +60 -0
  25. data/lib/rubocop/cop/performance/rubyzip.rb +35 -0
  26. data/lib/rubocop/cop/polymorphic_associations.rb +25 -0
  27. data/lib/rubocop/cop/rails/include_url_helper.rb +27 -0
  28. data/lib/rubocop/cop/redirect_with_status.rb +46 -0
  29. data/lib/rubocop/cop/rspec/base.rb +14 -0
  30. data/lib/rubocop/cop/rspec/empty_line_after_final_let_it_be.rb +47 -0
  31. data/lib/rubocop/cop/rspec/empty_line_after_let_block.rb +61 -0
  32. data/lib/rubocop/cop/rspec/empty_line_after_shared_example.rb +61 -0
  33. data/lib/rubocop/cop/rspec/example_starting_character.rb +120 -0
  34. data/lib/rubocop/cop/rspec/have_link_parameters.rb +44 -0
  35. data/lib/rubocop/cop/rspec/single_line_hook.rb +41 -0
  36. data/lib/rubocop/cop/rspec/verbose_include_metadata.rb +71 -0
  37. data/lib/rubocop/cop/style/hash_transformation.rb +83 -0
  38. data/lib/rubocop/cop/style/open_struct_use.rb +39 -0
  39. data/lib/rubocop/cop/without_reactive_cache.rb +16 -0
  40. data/rubocop-default.yml +1 -0
  41. data/rubocop-fips.yml +15 -0
  42. data/rubocop-rspec.yml +3 -2
  43. metadata +49 -27
  44. data/lib/gitlab/styles/rubocop/cop/active_record_dependent.rb +0 -32
  45. data/lib/gitlab/styles/rubocop/cop/active_record_serialize.rb +0 -24
  46. data/lib/gitlab/styles/rubocop/cop/code_reuse/active_record.rb +0 -130
  47. data/lib/gitlab/styles/rubocop/cop/custom_error_class.rb +0 -73
  48. data/lib/gitlab/styles/rubocop/cop/gem_fetcher.rb +0 -41
  49. data/lib/gitlab/styles/rubocop/cop/in_batches.rb +0 -22
  50. data/lib/gitlab/styles/rubocop/cop/internal_affairs/deprecate_cop_helper.rb +0 -43
  51. data/lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb +0 -104
  52. data/lib/gitlab/styles/rubocop/cop/line_break_around_conditional_block.rb +0 -132
  53. data/lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb +0 -64
  54. data/lib/gitlab/styles/rubocop/cop/performance/rubyzip.rb +0 -39
  55. data/lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb +0 -29
  56. data/lib/gitlab/styles/rubocop/cop/rails/include_url_helper.rb +0 -31
  57. data/lib/gitlab/styles/rubocop/cop/redirect_with_status.rb +0 -50
  58. data/lib/gitlab/styles/rubocop/cop/rspec/base.rb +0 -18
  59. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_final_let_it_be.rb +0 -51
  60. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb +0 -65
  61. data/lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb +0 -65
  62. data/lib/gitlab/styles/rubocop/cop/rspec/example_starting_character.rb +0 -124
  63. data/lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb +0 -48
  64. data/lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb +0 -45
  65. data/lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb +0 -75
  66. data/lib/gitlab/styles/rubocop/cop/style/hash_transformation.rb +0 -87
  67. data/lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb +0 -43
  68. data/lib/gitlab/styles/rubocop/cop/without_reactive_cache.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f43bff11daad05b1bb5f442c18f3fa7b8ef871e60f7675dd165f55b1515953f7
4
- data.tar.gz: 57317b8cb40639df642e1d058f342eba63979b237f18cc5d5290065aef5a3a5f
3
+ metadata.gz: 6b56e4d8be26ddd4c64b078c7ba35ee9cde92ee9aa8510303fc8e56f55d76b4c
4
+ data.tar.gz: 9e3aae79876619f3f189ad51133ad0e5b6c9f2b50a9d08fcaa1d37275bfe4ccc
5
5
  SHA512:
6
- metadata.gz: bb319a3ada8ae43e77ba1de5aeb4234e9c6d8c97848f3ae3870222a4b0a4f4ae2f8f2d6356f8cd9b9747101482758834ceacb5cd2cef09519fd17e736a272c05
7
- data.tar.gz: bb37685d5084df12a4820c47ce43ec0106aa50e05f9a7ddbde97c9956a7ec50e62fac388a968ba909c356c66324511fa5f407455b538ea1d183d2fa2f20367d1
6
+ metadata.gz: 7bf2ad47042480c6e187b5643c963e8e2560c8f7d38ed9431308902b0074aca0a52f740790fc2cd82e59611e50156b7dc18d89a562b17c1c8cce2c1db3ebe50b
7
+ data.tar.gz: b97431178490c4344cf1eaec23c1bf2596b7e44a2a8182ea2295add370e7e0c67da6bfa5fc4b213540306a681534e62272736669549e2949168b09bc4b1ddf8d
@@ -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.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
@@ -3,7 +3,7 @@
3
3
  module Gitlab
4
4
  module Styles
5
5
  module Rubocop
6
- module ModelHelpers
6
+ module Gitlab::Styles::Rubocop::ModelHelpers
7
7
  # Returns true if the given node originated from the models directory.
8
8
  def in_model?(node)
9
9
  path = node.location.expression.source_buffer.name
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Auto-require all cops under `gitlab/styles/rubocop/cop/**/*.rb`
4
- cops_glob = File.join(__dir__, 'rubocop', 'cop', '**', '*.rb')
3
+ # Auto-require all cops under `rubocop/cop/**/*.rb`
4
+ cops_glob = File.join(__dir__, '..', '..', 'rubocop', 'cop', '**', '*.rb')
5
5
  Dir[cops_glob].sort.each { |cop| require(cop) }
6
6
 
7
7
  module Gitlab
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '6.6.0'
5
+ VERSION = '8.0.0'
6
6
  end
7
7
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../gitlab/styles/rubocop/model_helpers'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ # Cop that prevents the use of `dependent: ...` in ActiveRecord models.
8
+ class ActiveRecordDependent < RuboCop::Cop::Cop
9
+ include Gitlab::Styles::Rubocop::ModelHelpers
10
+
11
+ MSG = 'Do not use `dependent:` to remove associated data, ' \
12
+ 'use foreign keys with cascading deletes instead.'
13
+
14
+ METHOD_NAMES = [:has_many, :has_one, :belongs_to].freeze
15
+ ALLOWED_OPTIONS = [:restrict_with_error].freeze
16
+
17
+ def on_send(node)
18
+ return unless in_model?(node)
19
+ return unless METHOD_NAMES.include?(node.children[1])
20
+
21
+ node.children.last.each_node(:pair) do |pair|
22
+ key_name = pair.children[0].children[0]
23
+ option_name = pair.children[1].children[0]
24
+
25
+ break if ALLOWED_OPTIONS.include?(option_name)
26
+
27
+ add_offense(pair) if key_name == :dependent
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../gitlab/styles/rubocop/model_helpers'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ # Cop that prevents the use of `serialize` in ActiveRecord models.
8
+ class ActiveRecordSerialize < RuboCop::Cop::Cop
9
+ include Gitlab::Styles::Rubocop::ModelHelpers
10
+
11
+ MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'
12
+
13
+ def on_send(node)
14
+ return unless in_model?(node)
15
+
16
+ add_offense(node, location: :selector) if node.children[1] == :serialize
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Cop
5
+ # Checks for return inside blocks.
6
+ # For more information see: https://gitlab.com/gitlab-org/gitlab-foss/issues/42889
7
+ #
8
+ # @example
9
+ # # bad
10
+ # call do
11
+ # return if something
12
+ #
13
+ # do_something_else
14
+ # end
15
+ #
16
+ # # good
17
+ # call do
18
+ # break if something
19
+ #
20
+ # do_something_else
21
+ # end
22
+ #
23
+ class AvoidReturnFromBlocks < RuboCop::Cop::Cop
24
+ MSG = 'Do not return from a block, use next or break instead.'
25
+ DEF_METHODS = %i[define_method lambda].freeze
26
+ WHITELISTED_METHODS = %i[each each_filename times loop].freeze
27
+
28
+ def on_block(node)
29
+ block_body = node.body
30
+
31
+ return unless block_body
32
+ return unless top_block?(node)
33
+
34
+ block_body.each_node(:return) do |return_node|
35
+ next if parent_blocks(node, return_node).all? { |block| whitelisted?(block) }
36
+
37
+ add_offense(return_node)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def top_block?(node)
44
+ current_node = node
45
+ top_block = nil
46
+
47
+ while current_node && current_node.type != :def
48
+ top_block = current_node if current_node.block_type?
49
+ current_node = current_node.parent
50
+ end
51
+
52
+ top_block == node
53
+ end
54
+
55
+ def parent_blocks(node, current_node)
56
+ blocks = []
57
+
58
+ until node == current_node || def?(current_node)
59
+ blocks << current_node if current_node.block_type?
60
+ current_node = current_node.parent
61
+ end
62
+
63
+ blocks << node if node == current_node && !def?(node)
64
+ blocks
65
+ end
66
+
67
+ def def?(node)
68
+ node.def_type? || node.defs_type? ||
69
+ (node.block_type? && DEF_METHODS.include?(node.method_name))
70
+ end
71
+
72
+ def whitelisted?(block_node)
73
+ WHITELISTED_METHODS.include?(block_node.method_name)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Cop
5
+ module CodeReuse
6
+ # Cop that denies the use of ActiveRecord methods outside of models.
7
+ class ActiveRecord < RuboCop::Cop::Cop
8
+ MSG = 'This method can only be used inside an ActiveRecord model: ' \
9
+ 'https://gitlab.com/gitlab-org/gitlab-foss/issues/49653'
10
+
11
+ # Various methods from ActiveRecord::Querying that are denied. We
12
+ # exclude some generic ones such as `any?` and `first`, as these may
13
+ # lead to too many false positives, since `Array` also supports these
14
+ # methods.
15
+ #
16
+ # The keys of this Hash are the denied method names. The values are
17
+ # booleans that indicate if the method should only be denied if any
18
+ # arguments are provided.
19
+ NOT_ALLOWED = {
20
+ average: true,
21
+ calculate: true,
22
+ count_by_sql: true,
23
+ create_with: true,
24
+ distinct: false,
25
+ eager_load: true,
26
+ exists?: true,
27
+ find_by: true,
28
+ find_by!: true,
29
+ find_by_sql: true,
30
+ find_each: true,
31
+ find_in_batches: true,
32
+ find_or_create_by: true,
33
+ find_or_create_by!: true,
34
+ find_or_initialize_by: true,
35
+ first!: false,
36
+ first_or_create: true,
37
+ first_or_create!: true,
38
+ first_or_initialize: true,
39
+ from: true,
40
+ group: true,
41
+ having: true,
42
+ ids: false,
43
+ includes: true,
44
+ joins: true,
45
+ lock: false,
46
+ many?: false,
47
+ offset: true,
48
+ order: true,
49
+ pluck: true,
50
+ preload: true,
51
+ readonly: false,
52
+ references: true,
53
+ reorder: true,
54
+ rewhere: true,
55
+ take: false,
56
+ take!: false,
57
+ unscope: false,
58
+ where: false,
59
+ with: true
60
+ }.freeze
61
+
62
+ def on_send(node)
63
+ receiver = node.children[0]
64
+ send_name = node.children[1]
65
+ first_arg = node.children[2]
66
+
67
+ return unless receiver && NOT_ALLOWED.key?(send_name)
68
+
69
+ # If the rule requires an argument to be given, but none are
70
+ # provided, we won't register an offense. This prevents us from
71
+ # adding offenses for `project.group`, while still covering
72
+ # `Project.group(:name)`.
73
+ return if NOT_ALLOWED[send_name] && !first_arg
74
+
75
+ add_offense(node, location: :selector)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Cop
5
+ # This cop makes sure that custom error classes, when empty, are declared
6
+ # with Class.new.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # class FooError < StandardError
11
+ # end
12
+ #
13
+ # # okish
14
+ # class FooError < StandardError; end
15
+ #
16
+ # # good
17
+ # FooError = Class.new(StandardError)
18
+ class CustomErrorClass < RuboCop::Cop::Cop
19
+ MSG = 'Use `Class.new(SuperClass)` to define an empty custom error class.'
20
+
21
+ def on_class(node)
22
+ parent = node.parent_class
23
+ body = node.body
24
+
25
+ return if body
26
+
27
+ parent_klass = class_name_from_node(parent)
28
+
29
+ return unless parent_klass&.to_s&.end_with?('Error')
30
+
31
+ add_offense(node)
32
+ end
33
+
34
+ def autocorrect(node)
35
+ klass = node.identifier
36
+ parent = node.parent_class
37
+
38
+ replacement = "#{class_name_from_node(klass)} = Class.new(#{class_name_from_node(parent)})"
39
+
40
+ lambda do |corrector|
41
+ corrector.replace(node.source_range, replacement)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ # The nested constant `Foo::Bar::Baz` looks like:
48
+ #
49
+ # s(:const,
50
+ # s(:const,
51
+ # s(:const, nil, :Foo), :Bar), :Baz)
52
+ #
53
+ # So recurse through that to get the name as written in the source.
54
+ #
55
+ def class_name_from_node(node, suffix = nil)
56
+ return unless node&.type == :const
57
+
58
+ name = node.children[1].to_s
59
+ name = "#{name}::#{suffix}" if suffix
60
+
61
+ if node.children[0]
62
+ class_name_from_node(node.children[0], name)
63
+ else
64
+ name
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../gitlab/styles/common/banned_constants'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module Fips
8
+ class MD5 < RuboCop::Cop::Base
9
+ include Gitlab::Styles::Common::BannedConstants
10
+
11
+ MESSAGE_TEMPLATE = 'MD5 is not FIPS-compliant. Use %{replacement} instead.'
12
+
13
+ REPLACEMENTS = {
14
+ 'OpenSSL::Digest::MD5' => 'OpenSSL::Digest::SHA256',
15
+ 'Digest::MD5' => 'OpenSSL::Digest::SHA256'
16
+ }.freeze
17
+
18
+ def initialize(config = nil, options = nil)
19
+ @message_template = MESSAGE_TEMPLATE
20
+ @replacements = REPLACEMENTS
21
+ @autocorrect = false
22
+ super(config, options)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../gitlab/styles/common/banned_constants'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module Fips
8
+ class OpenSSL < RuboCop::Cop::Base
9
+ extend RuboCop::Cop::AutoCorrector
10
+ include Gitlab::Styles::Common::BannedConstants
11
+
12
+ MESSAGE_TEMPLATE = 'Usage of this class is not FIPS-compliant. Use %{replacement} instead.'
13
+
14
+ REPLACEMENTS = {
15
+ 'Digest::SHA1' => 'OpenSSL::Digest::SHA1',
16
+ 'Digest::SHA2' => 'OpenSSL::Digest::SHA256',
17
+ 'Digest::SHA256' => 'OpenSSL::Digest::SHA256',
18
+ 'Digest::SHA384' => 'OpenSSL::Digest::SHA384',
19
+ 'Digest::SHA512' => 'OpenSSL::Digest::SHA512'
20
+ }.freeze
21
+
22
+ def initialize(config = nil, options = nil)
23
+ @message_template = MESSAGE_TEMPLATE
24
+ @replacements = REPLACEMENTS
25
+ @autocorrect = true
26
+ super(config, options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../gitlab/styles/common/banned_constants'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module Fips
8
+ class SHA1 < RuboCop::Cop::Base
9
+ include Gitlab::Styles::Common::BannedConstants
10
+
11
+ MESSAGE_TEMPLATE = 'SHA1 is likely to become non-compliant in the near future. Use %{replacement} instead.'
12
+
13
+ REPLACEMENTS = {
14
+ 'OpenSSL::Digest::SHA1' => 'OpenSSL::Digest::SHA256',
15
+ 'Digest::SHA1' => 'OpenSSL::Digest::SHA256'
16
+ }.freeze
17
+
18
+ def initialize(config = nil, options = nil)
19
+ @message_template = MESSAGE_TEMPLATE
20
+ @replacements = REPLACEMENTS
21
+ @autocorrect = false
22
+ super(config, options)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Cop
5
+ # This cop prevents usage of the `git` and `github` arguments to `gem` in a
6
+ # `Gemfile` in order to avoid additional points of failure beyond
7
+ # rubygems.org.
8
+ class GemFetcher < RuboCop::Cop::Cop
9
+ MSG = 'Do not use gems from git repositories, only use gems from RubyGems.'
10
+
11
+ GIT_KEYS = [:git, :github].freeze
12
+
13
+ def on_send(node)
14
+ return unless gemfile?(node)
15
+
16
+ func_name = node.children[1]
17
+ return unless func_name == :gem
18
+
19
+ node.children.last.each_node(:pair) do |pair|
20
+ key_name = pair.children[0].children[0].to_sym
21
+ add_offense(node, location: pair.source_range) if GIT_KEYS.include?(key_name)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def gemfile?(node)
28
+ node
29
+ .location
30
+ .expression
31
+ .source_buffer
32
+ .name
33
+ .end_with?("Gemfile")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../gitlab/styles/rubocop/model_helpers'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ # Cop that prevents the use of `in_batches`
8
+ class InBatches < RuboCop::Cop::Cop
9
+ MSG = 'Do not use `in_batches`, use `each_batch` from the EachBatch module instead'
10
+
11
+ def on_send(node)
12
+ return unless node.children[1] == :in_batches
13
+
14
+ add_offense(node, location: :selector)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Cop
5
+ module InternalAffairs
6
+ # Cop that denies the use of CopHelper.
7
+ class DeprecateCopHelper < RuboCop::Cop::Cop
8
+ MSG = 'Do not use `CopHelper` or methods from it, use improved patterns described in https://www.rubydoc.info/gems/rubocop/RuboCop/RSpec/ExpectOffense'
9
+
10
+ def_node_matcher :cop_helper, <<~PATTERN
11
+ (send nil? ${:include :extend :prepend}
12
+ (const _ {:CopHelper}))
13
+ PATTERN
14
+
15
+ def_node_search :cop_helper_method, <<~PATTERN
16
+ (send nil? {:inspect_source :inspect_source_file :parse_source :autocorrect_source_file :autocorrect_source :_investigate} ...)
17
+ PATTERN
18
+
19
+ def_node_search :cop_helper_method_on_instance, <<~PATTERN
20
+ (send (send nil? _) {:messages :highlights :offenses} ...)
21
+ PATTERN
22
+
23
+ def on_send(node)
24
+ cop_helper(node) do
25
+ add_offense(node)
26
+ end
27
+
28
+ cop_helper_method(node) do
29
+ add_offense(node)
30
+ end
31
+
32
+ cop_helper_method_on_instance(node) do
33
+ add_offense(node)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end