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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/ezcater_rubocop/version.rb +1 -1
- data/lib/rubocop/cop/ezcater/direct_env_check.rb +2 -2
- data/lib/rubocop/cop/ezcater/feature_flag_active.rb +3 -3
- data/lib/rubocop/cop/ezcater/feature_flag_name_valid.rb +3 -3
- data/lib/rubocop/cop/ezcater/rails_configuration.rb +6 -8
- data/lib/rubocop/cop/ezcater/rails_env.rb +2 -2
- data/lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb +11 -13
- data/lib/rubocop/cop/ezcater/require_custom_error.rb +1 -1
- data/lib/rubocop/cop/ezcater/require_gql_error_helpers.rb +2 -2
- data/lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb +14 -13
- data/lib/rubocop/cop/ezcater/rspec_match_ordered_array.rb +13 -15
- data/lib/rubocop/cop/ezcater/rspec_require_browser_mock.rb +2 -3
- data/lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb +2 -2
- data/lib/rubocop/cop/ezcater/rspec_require_http_status_matcher.rb +2 -3
- data/lib/rubocop/cop/ezcater/ruby_timeout.rb +2 -2
- data/lib/rubocop/cop/ezcater/style_dig.rb +12 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f4e7bbf647038e8c4908c7afd359289c8ddd66ed226c36321d19c339dc3894
|
4
|
+
data.tar.gz: d305ea39433fe93fc61a758743dbd3f173c61f1d1fcf182dfd50e8b444f6137d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
# # bad
|
19
19
|
# enforce_foo! if ENV["FOO_ENFORCED"] == "true"
|
20
20
|
#
|
21
|
-
class DirectEnvCheck <
|
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
|
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 <
|
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
|
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
|
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 <
|
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
|
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
|
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 <
|
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
|
17
|
-
|
18
|
-
|
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 <
|
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
|
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 <
|
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
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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 <
|
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 <
|
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
|
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 <
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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 <
|
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
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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 <
|
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 <
|
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
|
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 <
|
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 <
|
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
|
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 <
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
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.
|
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
|
+
date: 2024-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|