gitlab-styles 13.1.0 → 15.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab/merge_request_templates/New Static Analysis Check.md +26 -0
  3. data/.gitlab-ci.yml +3 -4
  4. data/.rubocop.yml +2 -23
  5. data/.rubocop_todo.yml +2 -19
  6. data/Gemfile.lock +248 -133
  7. data/README.md +34 -10
  8. data/gitlab-styles.gemspec +21 -22
  9. data/lib/gitlab/styles/rubocop/rspec.rb +4 -0
  10. data/lib/gitlab/styles/rubocop.rb +6 -3
  11. data/lib/gitlab/styles/version.rb +1 -1
  12. data/lib/rubocop/cop/avoid_return_from_blocks.rb +4 -4
  13. data/lib/rubocop/cop/fips/md5.rb +10 -0
  14. data/lib/rubocop/cop/fips/open_ssl.rb +11 -0
  15. data/lib/rubocop/cop/fips/sha1.rb +8 -0
  16. data/lib/rubocop/cop/gem_fetcher.rb +6 -0
  17. data/lib/rubocop/cop/gitlab_security/deep_munge.rb +10 -0
  18. data/lib/rubocop/cop/in_batches.rb +8 -0
  19. data/lib/rubocop/cop/internal_affairs/cop_description_with_example.rb +1 -1
  20. data/lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb +12 -0
  21. data/lib/rubocop/cop/internal_affairs/use_restrict_on_send.rb +17 -16
  22. data/lib/rubocop/cop/line_break_around_conditional_block.rb +31 -31
  23. data/lib/rubocop/cop/migration/update_large_table.rb +24 -1
  24. data/lib/rubocop/cop/performance/rubyzip.rb +6 -0
  25. data/lib/rubocop/cop/polymorphic_associations.rb +11 -0
  26. data/lib/rubocop/cop/rspec/base.rb +1 -0
  27. data/lib/rubocop/cop/rspec/empty_line_after_let_block.rb +1 -0
  28. data/lib/rubocop/cop/rspec/empty_line_after_shared_example.rb +3 -2
  29. data/lib/rubocop/cop/rspec/example_starting_character.rb +3 -4
  30. data/lib/rubocop/cop/rspec/feature_spec_max_examples.rb +46 -0
  31. data/lib/rubocop/cop/rspec/single_line_hook.rb +1 -0
  32. data/lib/rubocop/cop/tailwind/max_width_media_queries.rb +2 -1
  33. data/rubocop-all.yml +1 -1
  34. data/rubocop-capybara.yml +1 -2
  35. data/rubocop-code_reuse.yml +1 -1
  36. data/rubocop-default.yml +0 -3
  37. data/rubocop-factory_bot.yml +1 -2
  38. data/rubocop-fips.yml +3 -1
  39. data/rubocop-graphql.yml +1 -1
  40. data/rubocop-internal-affairs.yml +4 -1
  41. data/rubocop-layout.yml +6 -1
  42. data/rubocop-migrations.yml +1 -1
  43. data/rubocop-naming.yml +1 -1
  44. data/rubocop-performance.yml +3 -8
  45. data/rubocop-rails.yml +8 -2
  46. data/rubocop-rspec.yml +25 -2
  47. data/rubocop-security.yml +7 -1
  48. data/rubocop-style.yml +8 -1
  49. data/rubocop-tailwind.yml +2 -1
  50. metadata +58 -72
  51. data/lib/rubocop/cop/line_break_after_guard_clauses.rb +0 -99
  52. data/lib/rubocop/cop/style/open_struct_use.rb +0 -49
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop-rspec'
4
+ require_relative 'base'
5
+
6
+ module Rubocop
7
+ module Cop
8
+ module RSpec
9
+ # Limits the number of examples in feature spec files.
10
+ #
11
+ # Feature specs with too many examples are slow to run, hard to maintain,
12
+ # and often indicate the file should be split into smaller, focused specs.
13
+ #
14
+ # The maximum number of examples can be configured with the `Max` option
15
+ # (default: 25).
16
+ #
17
+ # @example Max: 25 (default)
18
+ #
19
+ # # bad
20
+ # # A feature spec file with more than 25 examples.
21
+ #
22
+ # # good
23
+ # # A feature spec file with 25 or fewer examples.
24
+ class FeatureSpecMaxExamples < Base
25
+ MSG = 'Feature spec file has %<count>d examples, which exceeds the maximum of %<max>d. ' \
26
+ 'Consider splitting into smaller, focused files grouped by user flow or feature area.'
27
+
28
+ def on_new_investigation
29
+ super
30
+ @example_count = 0
31
+ @max = cop_config['Max'] || 25
32
+ end
33
+
34
+ def on_block(node)
35
+ @example_count += 1 if example?(node)
36
+ end
37
+ alias_method :on_numblock, :on_block
38
+ alias_method :on_itblock, :on_block
39
+
40
+ def on_investigation_end
41
+ add_global_offense(format(MSG, count: @example_count, max: @max)) if @example_count > @max
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -37,6 +37,7 @@ module Rubocop
37
37
  add_offense(node, message: MESSAGE)
38
38
  end
39
39
  alias_method :on_numblock, :on_block
40
+ alias_method :on_itblock, :on_block
40
41
  end
41
42
  end
42
43
  end
@@ -14,7 +14,8 @@ module Rubocop
14
14
  # css_classes = ["gl-mt-3", "md:gl-mt-5"]
15
15
  # %div{ class: ["gl-mt-3", "md:gl-mt-5"] }
16
16
  class MaxWidthMediaQueries < RuboCop::Cop::Base
17
- TAILWIND_CSS_CLASS = /max-(sm|md|lg|xl):gl-/
17
+ ALLOWLIST = ['hidden'].freeze
18
+ TAILWIND_CSS_CLASS = /max-(sm|md|lg|xl):gl-(?!#{ALLOWLIST.join('|')})/
18
19
  MSG = 'Do not use max-width media query utility classes unless absolutely necessary. ' \
19
20
  'Use min-width media query utility classes instead.'
20
21
 
data/rubocop-all.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  AllCops:
3
3
  # The oldest supported Ruby version.
4
- TargetRubyVersion: 3.1
4
+ TargetRubyVersion: 3.3
5
5
  # Cop names are not displayed in offense messages by default. Change behavior
6
6
  # by overriding DisplayCopNames, or by giving the -D/--display-cop-names
7
7
  # option.
data/rubocop-capybara.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  ---
2
- require:
2
+ plugins:
3
3
  - rubocop-capybara
4
- - ./lib/gitlab/styles/rubocop
5
4
 
6
5
  # Checks if there is a more specific finder offered by Capybara.
7
6
  # https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/merge_requests/131#note_1141024624
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/code_reuse/active_record
4
4
 
5
5
  # Denies the use of ActiveRecord methods outside of configured
6
6
  # excluded directories
data/rubocop-default.yml CHANGED
@@ -1,7 +1,4 @@
1
1
  ---
2
- require:
3
- - ./lib/gitlab/styles/rubocop
4
-
5
2
  inherit_from:
6
3
  - rubocop-all.yml
7
4
  - rubocop-capybara.yml
@@ -1,7 +1,6 @@
1
1
  ---
2
- require:
2
+ plugins:
3
3
  - rubocop-factory_bot
4
- - ./lib/gitlab/styles/rubocop
5
4
 
6
5
  # Check for create_list FactoryBot declarations higher than MaxAmount
7
6
  FactoryBot/ExcessiveCreateList:
data/rubocop-fips.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/fips/md5
4
+ - ./lib/rubocop/cop/fips/open_ssl
5
+ - ./lib/rubocop/cop/fips/sha1
4
6
 
5
7
  # Denies usage of MD5
6
8
  Fips/MD5:
data/rubocop-graphql.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- require:
2
+ plugins:
3
3
  - rubocop-graphql
4
4
 
5
5
  # Ensures all arguments have a description
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/internal_affairs/cop_description_with_example
4
+ - ./lib/rubocop/cop/internal_affairs/deprecate_cop_helper
5
+ - ./lib/rubocop/cop/internal_affairs/missing_cop_department
6
+ - ./lib/rubocop/cop/internal_affairs/use_restrict_on_send
4
7
 
5
8
  InternalAffairs/DeprecateCopHelper:
6
9
  Include:
data/rubocop-layout.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/layout/line_break_after_final_mixin
4
+ - ./lib/rubocop/cop/line_break_around_conditional_block
4
5
 
5
6
  # Check indentation of private/protected visibility modifiers.
6
7
  Layout/AccessModifierIndentation:
@@ -57,6 +58,10 @@ Layout/DotPosition:
57
58
  Layout/ElseAlignment:
58
59
  Enabled: true
59
60
 
61
+ # Add an empty line after guard clauses.
62
+ Layout/EmptyLineAfterGuardClause:
63
+ Enabled: true
64
+
60
65
  # Checks for a newline after the final magic comment.
61
66
  Layout/EmptyLineAfterMagicComment:
62
67
  Enabled: true
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/migration/update_large_table
4
4
 
5
5
  # Checks for methods that may lead to batch type issues on a table that's been
6
6
  # explicitly denied because of its size.
data/rubocop-naming.yml CHANGED
@@ -48,7 +48,7 @@ Naming/MethodParameterName:
48
48
  # NamePrefix: is_, has_, have_
49
49
  # NamePrefixBlacklist: is_, has_, have_
50
50
  # NameWhitelist: is_a?
51
- Naming/PredicateName:
51
+ Naming/PredicatePrefix:
52
52
  Enabled: true
53
53
  ForbiddenPrefixes:
54
54
  - is_
@@ -1,19 +1,14 @@
1
1
  ---
2
- require:
2
+ plugins:
3
3
  - rubocop-performance
4
- - ./lib/gitlab/styles/rubocop
4
+ require:
5
+ - ./lib/rubocop/cop/performance/rubyzip
5
6
 
6
7
  # Used to identify usages of ancestors.include? and change them to use ⇐ instead.
7
8
  # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performanceancestorsinclude
8
9
  Performance/AncestorsInclude:
9
10
  Enabled: true
10
11
 
11
- # Identifies places where numeric argument to BigDecimal should be converted to string.
12
- # Initializing from String is faster than from Numeric for BigDecimal.
13
- # https://docs.rubocop.org/rubocop-performance/1.8/cops_performance.html#performancebigdecimalwithnumericargument
14
- Performance/BigDecimalWithNumericArgument:
15
- Enabled: true
16
-
17
12
  Performance/BlockGivenWithExplicitBlock: # (new in 1.9)
18
13
  Enabled: true
19
14
 
data/rubocop-rails.yml CHANGED
@@ -1,7 +1,13 @@
1
1
  ---
2
- require:
2
+ plugins:
3
3
  - rubocop-rails
4
- - ./lib/gitlab/styles/rubocop
4
+ require:
5
+ - ./lib/rubocop/cop/active_record_dependent
6
+ - ./lib/rubocop/cop/active_record_serialize
7
+ - ./lib/rubocop/cop/in_batches
8
+ - ./lib/rubocop/cop/polymorphic_associations
9
+ - ./lib/rubocop/cop/redirect_with_status
10
+ - ./lib/rubocop/cop/rails/include_url_helper
5
11
 
6
12
  # Cop that prevents the use of `dependent: ...` in ActiveRecord models.
7
13
  Cop/ActiveRecordDependent:
data/rubocop-rspec.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  ---
2
- require:
2
+ plugins:
3
3
  - rubocop-rspec
4
4
  - rubocop-rspec_rails
5
- - ./lib/gitlab/styles/rubocop
5
+ require:
6
+ - ./lib/gitlab/styles/rubocop/rspec
6
7
 
7
8
  # Check that instances are not being stubbed globally.
8
9
  RSpec/AnyInstance:
@@ -21,6 +22,22 @@ RSpec/BeforeAfterAll:
21
22
  RSpec/ClassCheck:
22
23
  Enabled: false
23
24
 
25
+ # Checks that `context` docstrings start with an allowed prefix. These are the
26
+ # most common prefixes in gitlab-org/gitlab:
27
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/92980
28
+ # Quote them all, because YAML reads unquoted `on` as `true`.
29
+ RSpec/ContextWording:
30
+ Prefixes:
31
+ - 'when'
32
+ - 'with'
33
+ - 'without'
34
+ - 'for'
35
+ - 'and'
36
+ - 'on'
37
+ - 'in'
38
+ - 'as'
39
+ - 'if'
40
+
24
41
  # Check that the first argument to the top level describe is the tested class or
25
42
  # module.
26
43
  RSpec/DescribeClass:
@@ -96,6 +113,12 @@ RSpec/ExpectChange:
96
113
  RSpec/ExpectOutput:
97
114
  Enabled: true
98
115
 
116
+ # Limits the number of examples in feature spec files to encourage splitting
117
+ # large specs into smaller, focused files.
118
+ RSpec/FeatureSpecMaxExamples:
119
+ Enabled: false
120
+ Max: 25
121
+
99
122
  # Checks if there are focused specs.
100
123
  RSpec/Focus:
101
124
  Enabled: true
data/rubocop-security.yml CHANGED
@@ -1,6 +1,12 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/gitlab_security/deep_munge
4
+ - ./lib/rubocop/cop/gitlab_security/json_serialization
5
+ - ./lib/rubocop/cop/gitlab_security/public_send
6
+ - ./lib/rubocop/cop/gitlab_security/redirect_to_params_update
7
+ - ./lib/rubocop/cop/gitlab_security/send_file_params
8
+ - ./lib/rubocop/cop/gitlab_security/sql_injection
9
+ - ./lib/rubocop/cop/gitlab_security/system_command_injection
4
10
 
5
11
  # Checks for implementations of the hash method which combine values using
6
12
  # custom logic instead of delegating to Array#hash.
data/rubocop-style.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/avoid_return_from_blocks
4
+ - ./lib/rubocop/cop/custom_error_class
5
+ - ./lib/rubocop/cop/style/hash_transformation
6
+ - ./lib/rubocop/cop/style/iso8601_date
4
7
 
5
8
  # Checks for grouping of accessors in class and module bodies.
6
9
  # https://docs.rubocop.org/rubocop/0.89/cops_style.html#styleaccessorgrouping
@@ -475,6 +478,10 @@ Style/TrailingCommaInArguments:
475
478
  Enabled: true
476
479
  EnforcedStyleForMultiline: no_comma
477
480
 
481
+ # Checks for the use of logical operators in an unless condition.
482
+ Style/UnlessLogicalOperators:
483
+ Enabled: true
484
+
478
485
  # Don't interpolate global, instance and class variables directly in strings.
479
486
  Style/VariableInterpolation:
480
487
  Enabled: true
data/rubocop-tailwind.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  require:
3
- - ./lib/gitlab/styles/rubocop
3
+ - ./lib/rubocop/cop/tailwind/max_width_media_queries
4
+ - ./lib/rubocop/cop/tailwind/string_interpolation
4
5
 
5
6
  # Prevent string interpolation when building Tailwind CSS utils names
6
7
  Tailwind/StringInterpolation: