ezcater_rubocop 7.0.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91e99b541defc66ad56b00dc87df189f3ae1794269719f46701a44998b3438a1
4
- data.tar.gz: d00dbef72d5716d0c9fc1493bc1eeaf028eb222962a2d7a2553afa6c8eb04749
3
+ metadata.gz: 21f4e7bbf647038e8c4908c7afd359289c8ddd66ed226c36321d19c339dc3894
4
+ data.tar.gz: d305ea39433fe93fc61a758743dbd3f173c61f1d1fcf182dfd50e8b444f6137d
5
5
  SHA512:
6
- metadata.gz: e634c40c10c8758ff9c668be962c07e77ae28b6dc3af9b343c60414d2fe3c4b28b6ae59b84c213c9d6588c2d1d4fb6ad353717ef225e5c7896040212e167c73c
7
- data.tar.gz: 0366c568bac8878bb85faa4f8b5003882efee38356b74d981bef19e7745e3b63fc6fd1accfdb9f9420036d1d9e609ef3b830121a89ab91068ee1ca304f5921bd
6
+ metadata.gz: c438d47953e25c7504a53b2b4d422776827df177b3a88a13e2774329c53d50f8e4554fff20b7af6cb9c4b2d1b07dba64a15baa528f13fe75c7b8455dec321950
7
+ data.tar.gz: 8a31b06d99e472a02ba4018405c6fafcd65786893dbb8d03b8b76e61472dc2b0a4bee0da107da02ce0994f5bb62a82414daec6fcbdc38a2098d712d6932d7c24
data/CHANGELOG.md CHANGED
@@ -6,6 +6,9 @@ This gem is moving onto its own [Semantic Versioning](https://semver.org/) schem
6
6
 
7
7
  Prior to v1.0.0 this gem was versioned based on the `MAJOR`.`MINOR` version of RuboCop. The first release of the ezcater_rubocop gem was `v0.49.0`.
8
8
 
9
+ ## 7.1.0
10
+ - Upgrade rubocop to v1 API (following guide [here](https://docs.rubocop.org/rubocop/v1_upgrade_notes.html)) to stop deprecation warnings in rubocop >=1.67.
11
+
9
12
  ## 7.0.0
10
13
 
11
14
  - Drop support for ruby 2.6 & 3.0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EzcaterRubocop
4
- VERSION = "7.0.0"
4
+ VERSION = "7.1.0"
5
5
  end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # # bad
19
19
  # enforce_foo! if ENV["FOO_ENFORCED"] == "true"
20
20
  #
21
- class DirectEnvCheck < Cop
21
+ class DirectEnvCheck < Base
22
22
  MSG = <<~END_MESSAGE.split("\n").join(" ")
23
23
  Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `ENV`. Restricting
24
24
  environment variables references to be within application configuration makes it more obvious which env vars
@@ -31,7 +31,7 @@ module RuboCop
31
31
 
32
32
  def on_const(node)
33
33
  env_ref(node) do
34
- add_offense(node, location: :expression, message: MSG)
34
+ add_offense(node.loc.expression, message: MSG)
35
35
  end
36
36
  end
37
37
  end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  # EzFF.active?(:symbol_name, tracking_id: "brand:12345")
23
23
  # EzFF.active?(123, identifiers: ["user:12345"])
24
24
 
25
- class FeatureFlagActive < Cop
25
+ class FeatureFlagActive < Base
26
26
  MSG = "`EzFF.active?` must be called with at least one of `tracking_id` or `identifiers`"
27
27
  FIRST_PARAM_MSG = "The first argument to `EzFF.active?` must be a string literal or a variable " \
28
28
  "or constant assigned to a string"
@@ -57,11 +57,11 @@ module RuboCop
57
57
  return unless method_call_matcher(node)
58
58
 
59
59
  if first_param_bad(node)
60
- add_offense(node, location: :expression, message: FIRST_PARAM_MSG)
60
+ add_offense(node.loc.expression, message: FIRST_PARAM_MSG)
61
61
  end
62
62
 
63
63
  if ezff_active_one_arg(node) || !args_matcher(node)
64
- add_offense(node, location: :expression, message: MSG)
64
+ add_offense(node.loc.expression, message: MSG)
65
65
  end
66
66
  end
67
67
  end
@@ -21,7 +21,7 @@ module RuboCop
21
21
  # EzFF.at_100?("Foo::Bar && rm -rf * ")
22
22
  # EzFF.active?("foo::bar", identifiers: ["user:1"])
23
23
  # MY_FLAG="Foo:bar"
24
- class FeatureFlagNameValid < Cop
24
+ class FeatureFlagNameValid < Base
25
25
  WHITESPACE = /\s/
26
26
  ISOLATED_COLON = /(?<!:):(?!:)/
27
27
  TRIPLE_COLON = /:::/
@@ -46,7 +46,7 @@ module RuboCop
46
46
  feature_flag_constant_assignment(node) do |const_name, flag_name|
47
47
  if const_name.end_with?("_FF", "_FLAG", "_FLAG_NAME", "_FEATURE_FLAG")
48
48
  errors = find_name_violations(flag_name)
49
- add_offense(node, location: :expression, message: errors.join(", ")) if errors.any?
49
+ add_offense(node.loc.expression, message: errors.join(", ")) if errors.any?
50
50
  end
51
51
  end
52
52
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
 
57
57
  feature_flag_method_call(node) do |flag_name|
58
58
  errors = find_name_violations(flag_name)
59
- add_offense(node, location: :expression, message: errors.join(", ")) if errors.any?
59
+ add_offense(node.loc.expression, message: errors.join(", ")) if errors.any?
60
60
  end
61
61
  end
62
62
 
@@ -3,7 +3,9 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Ezcater
6
- class RailsConfiguration < Cop
6
+ class RailsConfiguration < Base
7
+ extend RuboCop::Cop::AutoCorrector
8
+
7
9
  MSG = "Use `Rails.configuration` instead of `Rails.application.config`."
8
10
  RAILS_CONFIGURATION = "Rails.configuration"
9
11
 
@@ -13,13 +15,9 @@ module RuboCop
13
15
 
14
16
  def on_send(node)
15
17
  rails_application_config(node) do
16
- add_offense(node, location: :expression, message: MSG)
17
- end
18
- end
19
-
20
- def autocorrect(node)
21
- lambda do |corrector|
22
- corrector.replace(node.source_range, RAILS_CONFIGURATION)
18
+ add_offense(node.loc.expression, message: MSG) do |corrector|
19
+ corrector.replace(node.source_range, RAILS_CONFIGURATION)
20
+ end
23
21
  end
24
22
  end
25
23
  end
@@ -21,7 +21,7 @@ module RuboCop
21
21
  # # bad
22
22
  # enforce_foo! if ENV["RAILS_ENV"] == "production"
23
23
  #
24
- class RailsEnv < Cop
24
+ class RailsEnv < Base
25
25
  MSG = <<~END_MESSAGE.split("\n").join(" ")
26
26
  Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `Rails.env`, so that
27
27
  configuration is more centralized and gives finer control. https://ezcater.atlassian.net/wiki/x/ZIChNg
@@ -33,7 +33,7 @@ module RuboCop
33
33
 
34
34
  def on_send(node)
35
35
  rails_env(node) do
36
- add_offense(node, location: :expression, message: MSG)
36
+ add_offense(node.loc.expression, message: MSG)
37
37
  end
38
38
  end
39
39
  end
@@ -14,7 +14,9 @@ module RuboCop
14
14
  # # bad
15
15
  # ActiveRecord::Base.connection.execute("...")
16
16
  #
17
- class RailsTopLevelSqlExecute < Cop
17
+ class RailsTopLevelSqlExecute < Base
18
+ extend RuboCop::Cop::AutoCorrector
19
+
18
20
  MSG = <<~END_MESSAGE.split("\n").join(" ")
19
21
  Use `execute` instead of `ActiveRecord::Base.connection.execute` in migrations. The latter is
20
22
  redundant and can bypass safety checks.
@@ -26,19 +28,15 @@ module RuboCop
26
28
 
27
29
  def on_send(node)
28
30
  ar_connection_execute(node) do
29
- add_offense(node, location: :expression, message: MSG)
30
- end
31
- end
32
-
33
- def autocorrect(node)
34
- lambda do |corrector|
35
- range = Parser::Source::Range.new(
36
- node.source_range.source_buffer,
37
- node.source_range.begin_pos,
38
- node.source_range.end_pos
39
- )
31
+ add_offense(node.loc.expression, message: MSG) do |corrector|
32
+ range = Parser::Source::Range.new(
33
+ node.source_range.source_buffer,
34
+ node.source_range.begin_pos,
35
+ node.source_range.end_pos
36
+ )
40
37
 
41
- corrector.replace(range, "execute(#{node.last_argument.source})")
38
+ corrector.replace(range, "execute(#{node.last_argument.source})")
39
+ end
42
40
  end
43
41
  end
44
42
  end
@@ -13,7 +13,7 @@ module RuboCop
13
13
  # # good
14
14
  # raise OrderActionNotAllowed
15
15
 
16
- class RequireCustomError < Cop
16
+ class RequireCustomError < Base
17
17
  MSG = "Use a custom error class that inherits from StandardError when raising an exception"
18
18
 
19
19
  def_node_matcher :raising_standard_or_argument_error,
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # # bad
20
20
  # GraphQL::ExecutionError.new("An error occurred")
21
21
  # GraphQL::ExecutionError.new("You can't access this", options: { status_code: 401 })
22
- class RequireGqlErrorHelpers < Cop
22
+ class RequireGqlErrorHelpers < Base
23
23
  MSG = "Use the helpers provided by `GQLErrors` instead of raising `GraphQL::ExecutionError` directly."
24
24
 
25
25
  def_node_matcher :graphql_const?, <<~PATTERN
@@ -29,7 +29,7 @@ module RuboCop
29
29
  def on_const(node)
30
30
  return unless graphql_const?(node)
31
31
 
32
- add_offense(node, location: :expression, message: MSG)
32
+ add_offense(node.loc.expression, message: MSG)
33
33
  end
34
34
  end
35
35
  end
@@ -23,9 +23,10 @@ module RuboCop
23
23
  # ...
24
24
  # end
25
25
 
26
- class RspecDotNotSelfDot < Cop
26
+ class RspecDotNotSelfDot < Base
27
27
  include RuboCop::RSpec::Language
28
28
  extend RuboCop::RSpec::Language::NodePattern
29
+ extend RuboCop::Cop::AutoCorrector
29
30
 
30
31
  RSPEC_EXAMPLE_PREFIXES = ["", "x", "f"].freeze
31
32
  EXAMPLE_GROUP_IDENTIFIERS = (RSPEC_EXAMPLE_PREFIXES.map do |prefix|
@@ -53,19 +54,19 @@ module RuboCop
53
54
  return unless example_group?(node)
54
55
 
55
56
  str_node = node.send_node.arguments[0]
56
- if str_node.value.match?(SELF_DOT_REGEXP)
57
- add_offense(str_node, location: :expression, message: SELF_DOT_MSG)
58
- elsif str_node.value.match?(COLON_COLON_REGEXP)
59
- add_offense(str_node, location: :expression, message: COLON_COLON_MSG)
60
- end
61
- end
57
+ message = if str_node.value.match?(SELF_DOT_REGEXP)
58
+ SELF_DOT_MSG
59
+ elsif str_node.value.match?(COLON_COLON_REGEXP)
60
+ COLON_COLON_MSG
61
+ end
62
62
 
63
- def autocorrect(node)
64
- lambda do |corrector|
65
- experession_end = node.source.match?("::") ? 3 : 6
66
- corrector.replace(Parser::Source::Range.new(node.source_range.source_buffer,
67
- node.source_range.begin_pos + 1,
68
- node.source_range.begin_pos + experession_end), ".")
63
+ if message
64
+ add_offense(str_node.loc.expression, message: message) do |corrector|
65
+ expression_end = str_node.source.match?("::") ? 3 : 6
66
+ corrector.replace(Parser::Source::Range.new(str_node.source_range.source_buffer,
67
+ str_node.source_range.begin_pos + 1,
68
+ str_node.source_range.begin_pos + expression_end), ".")
69
+ end
69
70
  end
70
71
  end
71
72
  end
@@ -14,7 +14,9 @@ module RuboCop
14
14
  # # bad
15
15
  # expect(foo).to eq([1, 2, 3])
16
16
  # expect(foo).to eq [1, 2, 3]
17
- class RspecMatchOrderedArray < Cop
17
+ class RspecMatchOrderedArray < Base
18
+ extend RuboCop::Cop::AutoCorrector
19
+
18
20
  MATCH_ORDERED_ARRAY = "match_ordered_array"
19
21
  MSG = "Use the `match_ordered_array` matcher from ezcater_matchers gem "\
20
22
  "instead of `eq` when comparing collections"
@@ -25,20 +27,16 @@ module RuboCop
25
27
 
26
28
  def on_send(node)
27
29
  eq_array(node) do
28
- add_offense(node, location: :expression, message: MSG)
29
- end
30
- end
31
-
32
- def autocorrect(node)
33
- lambda do |corrector|
34
- corrector.replace(
35
- Parser::Source::Range.new(
36
- node.source_range.source_buffer,
37
- node.source_range.begin_pos,
38
- node.source_range.begin_pos + 2
39
- ),
40
- MATCH_ORDERED_ARRAY
41
- )
30
+ add_offense(node.loc.expression, message: MSG) do |corrector|
31
+ corrector.replace(
32
+ Parser::Source::Range.new(
33
+ node.source_range.source_buffer,
34
+ node.source_range.begin_pos,
35
+ node.source_range.begin_pos + 2
36
+ ),
37
+ MATCH_ORDERED_ARRAY
38
+ )
39
+ end
42
40
  end
43
41
  end
44
42
  end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # # bad
20
20
  # allow(Browser).to receive...
21
21
  # allow(EzBrowser).to receive...
22
- class RspecRequireBrowserMock < Cop
22
+ class RspecRequireBrowserMock < Base
23
23
  MSG = "Use the mocks provided by `BrowserHelpers` instead of mocking `%<node_source>s`"
24
24
 
25
25
  def_node_matcher :browser_const?, <<~PATTERN
@@ -39,8 +39,7 @@ module RuboCop
39
39
 
40
40
  # Finish tree navigation to full line for highlighting
41
41
  match_node = match_node.parent while match_node.parent
42
- add_offense(match_node,
43
- location: :expression,
42
+ add_offense(match_node.loc.expression,
44
43
  message: format(MSG, node_source: node.source))
45
44
  end
46
45
 
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # allow(FeatureFlag).to receive(:is_active?).and_return(true)
16
16
  # allow(FeatureFlag).to receive(:is_active?).with("MyFeatureFlag").and_return(true)
17
17
  # allow(FeatureFlag).to receive(:is_active?).with("MyFeatureFlag", user: current_user).and_return(true)
18
- class RspecRequireFeatureFlagMock < Cop
18
+ class RspecRequireFeatureFlagMock < Base
19
19
  MSG = "Use the `mock_feature_flag` helper instead of mocking `allow(FeatureFlag)`"
20
20
 
21
21
  def_node_matcher :feature_flag_const?, <<~PATTERN
@@ -35,7 +35,7 @@ module RuboCop
35
35
 
36
36
  # Finish tree navigation to full line for highlighting
37
37
  match_node = match_node.parent while match_node.parent
38
- add_offense(match_node, location: :expression)
38
+ add_offense(match_node.loc.expression)
39
39
  end
40
40
 
41
41
  private
@@ -14,7 +14,7 @@ module RuboCop
14
14
  # # bad
15
15
  # expect(response.code).to eq 201
16
16
  # expect(response.code).to eq 400
17
- class RspecRequireHttpStatusMatcher < Cop
17
+ class RspecRequireHttpStatusMatcher < Base
18
18
  MSG = "Use the `have_http_status` matcher, like `expect(response).to have_http_status :bad_request`, "\
19
19
  "rather than `%<node_source>s`"
20
20
 
@@ -29,8 +29,7 @@ module RuboCop
29
29
  def on_send(node)
30
30
  return if !response_status_assertion(node) && !response_code_assertion(node)
31
31
 
32
- add_offense(node,
33
- location: :expression,
32
+ add_offense(node.loc.expression,
34
33
  message: format(MSG, node_source: node.source))
35
34
  end
36
35
  end
@@ -17,7 +17,7 @@ module RuboCop
17
17
  # ...
18
18
  # end
19
19
  #
20
- class RubyTimeout < Cop
20
+ class RubyTimeout < Base
21
21
  MSG = <<~END_MESSAGE.split("\n").join(" ")
22
22
  `Timeout.timeout` is unsafe. Find an alternative to achieve the same goal.
23
23
  Ex. Use the timeout capabilities of a networking library.
@@ -30,7 +30,7 @@ module RuboCop
30
30
 
31
31
  def on_send(node)
32
32
  timeout(node) do
33
- add_offense(node, location: :expression, message: MSG)
33
+ add_offense(node.loc.expression, message: MSG)
34
34
  end
35
35
  end
36
36
  end
@@ -16,7 +16,8 @@ module RuboCop
16
16
  # my_hash['foo'] && my_hash['foo']['bar']
17
17
  # my_array[0][1]
18
18
 
19
- class StyleDig < Cop
19
+ class StyleDig < Base
20
+ extend RuboCop::Cop::AutoCorrector
20
21
  extend TargetRubyVersion
21
22
 
22
23
  minimum_target_ruby_version 2.3
@@ -33,22 +34,19 @@ module RuboCop
33
34
  match_node = node
34
35
  # walk to outermost access node
35
36
  match_node = match_node.parent while access_node?(match_node.parent)
36
- add_offense(match_node, location: :expression, message: MSG)
37
- end
38
37
 
39
- def autocorrect(node)
40
- access_node = node
41
- source_args = [access_node.first_argument.source]
42
- while access_node?(access_node.children.first)
43
- access_node = access_node.children.first
44
- source_args << access_node.first_argument.source
45
- end
46
- root_node = access_node.children.first
38
+ add_offense(match_node.loc.expression, message: MSG) do |corrector|
39
+ access_node = match_node
40
+ source_args = [access_node.first_argument.source]
41
+ while access_node?(access_node.children.first)
42
+ access_node = access_node.children.first
43
+ source_args << access_node.first_argument.source
44
+ end
45
+ root_node = access_node.children.first
47
46
 
48
- lambda do |corrector|
49
- range = Parser::Source::Range.new(node.source_range.source_buffer,
47
+ range = Parser::Source::Range.new(match_node.source_range.source_buffer,
50
48
  root_node.source_range.end_pos,
51
- node.source_range.end_pos)
49
+ match_node.source_range.end_pos)
52
50
  corrector.replace(range, ".dig(#{source_args.reverse.join(', ')})")
53
51
  end
54
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezcater_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-25 00:00:00.000000000 Z
11
+ date: 2024-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler