ezcater_rubocop 6.1.1 → 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: 26eaaa7f867ad999360777e40da32e1a0e591e4906e4fadc9b23a4fb70189b94
4
- data.tar.gz: 8d9fa27414f264d03cc0f5a15146aa563d23bbfdc9eddfb031fbddbe7557a617
3
+ metadata.gz: 21f4e7bbf647038e8c4908c7afd359289c8ddd66ed226c36321d19c339dc3894
4
+ data.tar.gz: d305ea39433fe93fc61a758743dbd3f173c61f1d1fcf182dfd50e8b444f6137d
5
5
  SHA512:
6
- metadata.gz: 3fa02d546b7ce79d540d1d079937d36622635e3c2ddf800544ade72924ea9520ec1f592957653d20ec156fea1f042c49519487999a2da00ddcdfc7b15b46fcfe
7
- data.tar.gz: f3869c5b24b6b8ae92878a10185e6403ce937d027c9b7eb8bd52f2a97fd6f402e443c86119039b44444d70ac2a1ebcb889f851ca589c34499b12503939e5ab56
6
+ metadata.gz: c438d47953e25c7504a53b2b4d422776827df177b3a88a13e2774329c53d50f8e4554fff20b7af6cb9c4b2d1b07dba64a15baa528f13fe75c7b8455dec321950
7
+ data.tar.gz: 8a31b06d99e472a02ba4018405c6fafcd65786893dbb8d03b8b76e61472dc2b0a4bee0da107da02ce0994f5bb62a82414daec6fcbdc38a2098d712d6932d7c24
data/CHANGELOG.md CHANGED
@@ -6,6 +6,18 @@ 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
+
12
+ ## 7.0.0
13
+
14
+ - Drop support for ruby 2.6 & 3.0
15
+
16
+ ## 6.1.2
17
+
18
+ - Disable `Naming/RescuedExceptionsVariableName` so exception variable names are less restrictive.
19
+
20
+
9
21
  ## 6.1.1
10
22
 
11
23
  - Lock `rubocop-rspec` below `v2.28.0` to avoid an upstream namespacing issue.
data/conf/rubocop.yml CHANGED
@@ -50,6 +50,9 @@ Naming/MethodParameterName:
50
50
  - ex
51
51
  - id
52
52
 
53
+ Naming/RescuedExceptionsVariableName:
54
+ Enabled: false
55
+
53
56
  Naming/VariableNumber:
54
57
  Enabled: false
55
58
 
data/conf/rubocop_gem.yml CHANGED
@@ -2,7 +2,7 @@ inherit_from:
2
2
  - ../conf/rubocop.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.6
5
+ TargetRubyVersion: 3.1
6
6
  Exclude:
7
7
  - 'vendor/bundle/**/*'
8
8
  - 'gemfiles/vendor/**/*'
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.executables << "circle_rubocop.rb"
43
43
  spec.require_paths = ["lib"]
44
44
 
45
- spec.required_ruby_version = ">= 2.6"
45
+ spec.required_ruby_version = ">= 3.1"
46
46
 
47
47
  spec.add_development_dependency "bundler"
48
48
  spec.add_development_dependency "pry-byebug"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EzcaterRubocop
4
- VERSION = "6.1.1"
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: 6.1.1
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-04 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
@@ -235,7 +235,7 @@ licenses:
235
235
  - MIT
236
236
  metadata:
237
237
  allowed_push_host: https://rubygems.org
238
- post_install_message:
238
+ post_install_message:
239
239
  rdoc_options: []
240
240
  require_paths:
241
241
  - lib
@@ -243,7 +243,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
243
  requirements:
244
244
  - - ">="
245
245
  - !ruby/object:Gem::Version
246
- version: '2.6'
246
+ version: '3.1'
247
247
  required_rubygems_version: !ruby/object:Gem::Requirement
248
248
  requirements:
249
249
  - - ">="
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  version: '0'
252
252
  requirements: []
253
253
  rubygems_version: 3.3.7
254
- signing_key:
254
+ signing_key:
255
255
  specification_version: 4
256
256
  summary: ezCater custom cops and shared configuration
257
257
  test_files: []