ezcater_rubocop 5.2.1 → 6.0.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/README.md +15 -9
- data/config/default.yml +4 -0
- data/lib/ezcater_rubocop/version.rb +1 -1
- data/lib/ezcater_rubocop.rb +1 -0
- data/lib/rubocop/cop/ezcater/feature_flag_name_valid.rb +92 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e412cd3e88f3c5e18b537a9a81beec0396f8882aba05f3f09c87464510bd9a6
|
4
|
+
data.tar.gz: 8786ebe582591fde680b7846e9be9783d84a402f6066cd22c1f5f379dd468b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3394769cce8e62507578b3fc55b943536ba79825ed30de348e538030c96129f2f923652682087467ade43c15a0847dce7faa8bcf5d7e6bd19d98d6b810b3fc3a
|
7
|
+
data.tar.gz: 4f79ad7d080b3c8a64e85cb9521226809c9dc1d558fa334cc0146dce879c1f836e8e10766db1aef2af922f82dafa715680f8af3d0c93537912843a9fc926ff2f
|
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
|
+
## 6.0.0
|
10
|
+
- Add `FeatureFlagNameValid` cop to validate correct feature flag name format, [adopted from the cop](https://github.com/ezcater/ez-rails/blob/2d9272eb3d2c71dc5ebc2aa01a849cf9cfae3df2/cops/rubocop/cops/feature_flags_flag_name.rb_) in `ez-rails`.
|
11
|
+
|
9
12
|
## 5.2.1
|
10
13
|
- Fix the has the wrong namespace for `RSpec/Capybara/CurrentPathExpectation` and `RSpec/Capybara/VisibilityMatcher` cops, since [they've been extracted](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md#2180-2023-01-16) into a separate repo [rubocop-capybara](https://github.com/rubocop/rubocop-capybara).
|
11
14
|
|
data/README.md
CHANGED
@@ -79,20 +79,26 @@ not add cops with `enabled: false` unless you want that cop to always be disable
|
|
79
79
|
|
80
80
|
## Custom Cops
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
* [FeatureFlagActive](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/feature_flag_active.rb) - Enforce the proper arguments are given to `EzcaterFeatureFlag.active?`
|
83
|
+
* [FeatureFlagNameValid](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/feature_flag_name_valid.rb) - Enforce correct flag name format is being used.
|
84
|
+
* [RailsConfiguration](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/rails_configuration.rb) - Enforce use of `Rails.configuration` instead of `Rails.application.config`.
|
85
|
+
* [RequireGqlErrorHelpers](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/require_gql_error_helpers.rb) - Use the helpers provided by `GQLErrors` instead of raising `GraphQL::ExecutionError` directly.
|
86
|
+
* [RspecDotNotSelfDot](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb) - Enforce ".<class method>" instead of "self.<class method>" and "::<class method>" for example group description.
|
87
|
+
* [RspecMatchOrderedArray](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/rspec_match_ordered_array.rb) - Enforce use of `match_ordered_array` matcher instead of `eq` matcher. This matcher comes from the [ezcater_matchers](https://github.com/ezcater/ezcater_matchers) gem.
|
88
|
+
* [RspecRequireBrowserMock](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/rspec_require_browser_mock.rb) - Enforce use of `mock_ezcater_app`, `mock_chrome_browser` & `mock_custom_browser` helpers instead of mocking `Browser` or `EzBrowser` directly.
|
89
|
+
* [RspecRequireFeatureFlagMock](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb) - Enforce use of `mock_feature_flag` helper instead of mocking `FeatureFlag.is_active?` directly.
|
90
|
+
* [RspecRequireHttpStatusMatcher](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/rspec_require_http_status_matcher.rb) - Use the HTTP status code matcher, like `expect(response).to have_http_status :bad_request`, rather than `expect(response.code).to eq 400`
|
91
|
+
* [StyleDig](https://github.com/ezcater/ezcater_rubocop/blob/main/lib/rubocop/cop/ezcater/style_dig.rb) - Recommend `dig` for deeply nested access.
|
90
92
|
|
91
93
|
## Development
|
92
94
|
|
93
95
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
94
96
|
|
95
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
97
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
98
|
+
|
99
|
+
### Releasing a New Version
|
100
|
+
|
101
|
+
To release a new version, update the version number in `version.rb`, merge your PR to `main`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
96
102
|
|
97
103
|
## Contributing
|
98
104
|
|
data/config/default.yml
CHANGED
@@ -14,6 +14,10 @@ Ezcater/FeatureFlagActive:
|
|
14
14
|
Description: "Enforce the proper arguments are given to EzcaterFeatureFlag.active?"
|
15
15
|
Enabled: true
|
16
16
|
|
17
|
+
Ezcater/FeatureFlagNameValid:
|
18
|
+
Description: "Enforce correct flag name format is being used."
|
19
|
+
Enabled: true
|
20
|
+
|
17
21
|
Ezcater/RspecDotNotSelfDot:
|
18
22
|
Description: 'Enforce ".<class method>" instead of "self.<class method>" for example group description.'
|
19
23
|
Enabled: true
|
data/lib/ezcater_rubocop.rb
CHANGED
@@ -18,6 +18,7 @@ RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
|
|
18
18
|
|
19
19
|
require "rubocop/cop/ezcater/direct_env_check"
|
20
20
|
require "rubocop/cop/ezcater/feature_flag_active"
|
21
|
+
require "rubocop/cop/ezcater/feature_flag_name_valid"
|
21
22
|
require "rubocop/cop/ezcater/rails_configuration"
|
22
23
|
require "rubocop/cop/ezcater/rails_env"
|
23
24
|
require "rubocop/cop/ezcater/ruby_timeout"
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Ezcater
|
6
|
+
# Match the naming validations in the feature flag service.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # good
|
11
|
+
# EzFF.at_100?("Flag1")
|
12
|
+
# EzFF.active?("Foo::Bar", tracking_id: 1234)
|
13
|
+
# EzFF.at_100?("Foo::Bar::Baz")
|
14
|
+
# MY_FLAG="Foo::Bar"; EzFF.at_100?(MY_FLAG)
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# EzFF.at_100?("Foo:Bar")
|
18
|
+
# EzFF.active?("Foo:::Bar", tracking_id: 1234)
|
19
|
+
# EzFF.at_100?("Foo:Bar:Baz")
|
20
|
+
# EzFF.at_100?("Foo::Bar ")
|
21
|
+
# EzFF.at_100?("Foo::Bar && rm -rf * ")
|
22
|
+
# EzFF.active?("foo::bar", identifiers: ["user:1"])
|
23
|
+
# MY_FLAG="Foo:bar"
|
24
|
+
class FeatureFlagNameValid < Cop
|
25
|
+
WHITESPACE = /\s/.freeze
|
26
|
+
ISOLATED_COLON = /(?<!:):(?!:)/.freeze
|
27
|
+
TRIPLE_COLON = /:::/.freeze
|
28
|
+
INVALID_CHARACTERS = /[^a-zA-Z0-9:]/.freeze
|
29
|
+
TITLECASE_SEGMENT = /"^([A-Z][a-z0-9]*)+$"/.freeze
|
30
|
+
|
31
|
+
WHITESPACE_MSG = "Feature flag names must not contain whitespace."
|
32
|
+
DOUBLE_COLON_MSG = "Feature flag names must use double colons (::) as namespace separators."
|
33
|
+
INVALID_CHARACTERS_MSG = "Feature flag names must only contain alphanumeric characters and colons."
|
34
|
+
TITLECASE_SEGMENT_MSG = "Feature flag names must use titlecase for each segment."
|
35
|
+
|
36
|
+
def_node_matcher :feature_flag_constant_assignment, <<~PATTERN
|
37
|
+
(casgn nil? $_ (str $_))
|
38
|
+
PATTERN
|
39
|
+
|
40
|
+
def_node_matcher :feature_flag_method_call, <<~PATTERN
|
41
|
+
(send
|
42
|
+
(_ _ {:EzFF :EzcaterFeatureFlag}) {:active? | :at_100? | :random_sample_active?} (str $_ ...))
|
43
|
+
PATTERN
|
44
|
+
|
45
|
+
def on_casgn(node)
|
46
|
+
feature_flag_constant_assignment(node) do |const_name, flag_name|
|
47
|
+
if const_name.end_with?("_FF", "_FLAG", "_FLAG_NAME", "_FEATURE_FLAG")
|
48
|
+
errors = find_name_violations(flag_name)
|
49
|
+
add_offense(node, location: :expression, message: errors.join(", ")) if errors.any?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_send(node)
|
55
|
+
return unless feature_flag_method_call(node)
|
56
|
+
|
57
|
+
feature_flag_method_call(node) do |flag_name|
|
58
|
+
errors = find_name_violations(flag_name)
|
59
|
+
add_offense(node, location: :expression, message: errors.join(", ")) if errors.any?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def find_name_violations(name)
|
66
|
+
errors = []
|
67
|
+
|
68
|
+
if name.match?(WHITESPACE)
|
69
|
+
errors << WHITESPACE_MSG
|
70
|
+
end
|
71
|
+
|
72
|
+
if name.match?(ISOLATED_COLON) || name.match?(TRIPLE_COLON)
|
73
|
+
errors << DOUBLE_COLON_MSG
|
74
|
+
end
|
75
|
+
|
76
|
+
if name.match?(INVALID_CHARACTERS)
|
77
|
+
errors << INVALID_CHARACTERS_MSG
|
78
|
+
end
|
79
|
+
|
80
|
+
name.split(/:+/).each do |segment|
|
81
|
+
unless segment.match?(TITLECASE_SEGMENT)
|
82
|
+
errors << TITLECASE_SEGMENT_MSG
|
83
|
+
break
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
errors
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
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:
|
4
|
+
version: 6.0.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: 2023-
|
11
|
+
date: 2023-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- lib/ezcater_rubocop/version.rb
|
214
214
|
- lib/rubocop/cop/ezcater/direct_env_check.rb
|
215
215
|
- lib/rubocop/cop/ezcater/feature_flag_active.rb
|
216
|
+
- lib/rubocop/cop/ezcater/feature_flag_name_valid.rb
|
216
217
|
- lib/rubocop/cop/ezcater/rails_configuration.rb
|
217
218
|
- lib/rubocop/cop/ezcater/rails_env.rb
|
218
219
|
- lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb
|