ezcater_rubocop 1.0.2 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d02f5757933c7be1b1a9e9a241538356c9065b6a04c34b1dfaa277654731c7b
4
- data.tar.gz: 57202741bf6252b2ac2bbd5199032bbd9c6bdde31246a48324a02ad4b95fbb6b
3
+ metadata.gz: 63b5162f2f4de001caee81127febb34027aa4199181d6c098936deec38a83068
4
+ data.tar.gz: ef6e3e1a319ecdd9db2550bffc519879df3d77182a54c470930214d811fc060e
5
5
  SHA512:
6
- metadata.gz: 5392b2b295c38b07aea42910192df5c5f095b12cdbbc0863f95acf558b91e994c404eaca0e8c8044bbc7a819214accb44b713342771ab310e028ab326f307f71
7
- data.tar.gz: dac7a7cfbf12311396c612bbe4831801b0ec8dac98d3ed13bcf2cd1ac23b4ce1b24ef0bb48998eb2d96322a17f8418b1062db97b6cedfa49022bc16173210a86
6
+ metadata.gz: 345e0c7c537cc2081b9469ea91261dfda7abe63d5b60a087bc8cb16084bf95054490c0232cab8bd17201023448a0b180077d3732aae60cc325e36ab07a58d912
7
+ data.tar.gz: 92976b7169ad4de3b931afb570a40946371716e49634f99a0f1e524f78b9d076a869a405a6ad95f055659e6a498489d32587e85fe319d40ba82d0b9751f7d64d
@@ -0,0 +1 @@
1
+ * @agrobbin @aprescott @tjwp
data/CHANGELOG.md CHANGED
@@ -4,8 +4,16 @@
4
4
 
5
5
  This gem is moving onto its own [Semantic Versioning](https://semver.org/) scheme starting with v1.0.0. All version bumps moving forward should increment using `MAJOR.MINOR.PATCH` based on changes.
6
6
 
7
- Prior to v1.0.0 this gem was versioned based on the `MAJOR`.`MINOR` version of RuboCop. The first release of the
8
- ezcater_rubocop gem was `v0.49.0`.
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
+
9
+ ## Unreleased
10
+
11
+ - ...
12
+
13
+ ## v1.1.0
14
+
15
+ - Add `Ezcater/RailsEnv` cop.
16
+ - Add `Ezcater/DirectEnvCheck` cop.
9
17
 
10
18
  ## v1.0.2
11
19
  - Exclude bootsnap cache directory (`tmp/cache`).
@@ -46,3 +46,20 @@ Rails/UnknownEnv:
46
46
  - test
47
47
  - staging
48
48
  - production
49
+
50
+ Ezcater/RailsEnv:
51
+ Description: 'Enforce the use of `Rails.configuration.x.<foo>` instead of checking `Rails.env`.'
52
+ Enabled: true
53
+ Exclude:
54
+ - "config/**/*"
55
+ - "spec/rails_helper.rb"
56
+ - "db/**/*"
57
+
58
+ Ezcater/DirectEnvCheck:
59
+ Description: 'Enforce the use of `Rails.configuration.x.<foo>` instead of checking `ENV`.'
60
+ Enabled: true
61
+ Exclude:
62
+ - "bin/**/*"
63
+ - "config/**/*"
64
+ - "spec/rails_helper.rb"
65
+ - "db/**/*"
data/config/default.yml CHANGED
@@ -2,6 +2,14 @@ Ezcater/RailsConfiguration:
2
2
  Description: 'Enforce the use of `Rails.configuration` instead of `Rails.application.config`.'
3
3
  Enabled: true
4
4
 
5
+ Ezcater/RailsEnv:
6
+ Description: 'Enforce the use of `Rails.configuration.x.<foo>` instead of checking `Rails.env`.'
7
+ Enabled: false
8
+
9
+ Ezcater/DirectEnvCheck:
10
+ Description: 'Enforce the use of `Rails.configuration.x.<foo>` instead of checking `ENV`.'
11
+ Enabled: false
12
+
5
13
  Ezcater/RspecDotNotSelfDot:
6
14
  Description: 'Enforce ".<class method>" instead of "self.<class method>" for example group description.'
7
15
  Enabled: true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EzcaterRubocop
4
- VERSION = "1.0.2"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -14,7 +14,9 @@ puts "configuration from #{DEFAULT_FILES}" if RuboCop::ConfigLoader.debug?
14
14
  config = RuboCop::ConfigLoader.merge_with_default(config, path)
15
15
  RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
16
16
 
17
+ require "rubocop/cop/ezcater/direct_env_check"
17
18
  require "rubocop/cop/ezcater/rails_configuration"
19
+ require "rubocop/cop/ezcater/rails_env"
18
20
  require "rubocop/cop/ezcater/require_gql_error_helpers"
19
21
  require "rubocop/cop/ezcater/rspec_match_ordered_array"
20
22
  require "rubocop/cop/ezcater/rspec_require_browser_mock"
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Ezcater
6
+ # Use the `Rails.configuration.x` namespace for configuration backed by
7
+ # environment variables, rather than inspecting `ENV` directly.
8
+ #
9
+ # Restricting environment variables references to be within application
10
+ # configuration makes it more obvious which env vars an application relies
11
+ # upon. See https://ezcater.atlassian.net/wiki/x/ZIChNg.
12
+ #
13
+ # @example
14
+ #
15
+ # # good
16
+ # enforce_foo! if Rails.configuration.x.foo_enforced
17
+ #
18
+ # # bad
19
+ # enforce_foo! if ENV["FOO_ENFORCED"] == "true"
20
+ #
21
+ class DirectEnvCheck < Cop
22
+ MSG = <<~END_MESSAGE.split("\n").join(" ")
23
+ Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `ENV`. Restricting
24
+ environment variables references to be within application configuration makes it more obvious which env vars
25
+ an application relies upon. https://ezcater.atlassian.net/wiki/x/ZIChNg
26
+ END_MESSAGE
27
+
28
+ def_node_matcher "env_ref", <<-PATTERN
29
+ (const _ :ENV)
30
+ PATTERN
31
+
32
+ def on_const(node)
33
+ env_ref(node) do
34
+ add_offense(node, location: :expression, message: MSG)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Ezcater
6
+ # Use the `Rails.configuration.x` namespace for configuration backed by
7
+ # environment variables, rather than inspecting `Rails.env` directly.
8
+ #
9
+ # Centralizing application configuration helps avoid scattering it
10
+ # throughout the codebase, and avoids coarse environment grouping under
11
+ # a single env var. See https://ezcater.atlassian.net/wiki/x/ZIChNg.
12
+ #
13
+ # @example
14
+ #
15
+ # # good
16
+ # enforce_foo! if Rails.configuration.x.foo_enforced
17
+ #
18
+ # # bad
19
+ # enforce_foo! if Rails.env.production?
20
+ #
21
+ # # bad
22
+ # enforce_foo! if ENV["RAILS_ENV"] == "production"
23
+ #
24
+ class RailsEnv < Cop
25
+ MSG = <<~END_MESSAGE.split("\n").join(" ")
26
+ Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `Rails.env`, so that
27
+ configuration is more centralized and gives finer control. https://ezcater.atlassian.net/wiki/x/ZIChNg
28
+ END_MESSAGE
29
+
30
+ def_node_matcher "rails_env", <<-PATTERN
31
+ (send (send (const _ :Rails) :env) _ ...)
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ rails_env(node) do
36
+ add_offense(node, location: :expression, message: MSG)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ 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: 1.0.2
4
+ version: 1.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: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,7 @@ executables:
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
+ - ".github/CODEOWNERS"
147
148
  - ".github/PULL_REQUEST_TEMPLATE.md"
148
149
  - CHANGELOG.md
149
150
  - Gemfile
@@ -157,7 +158,9 @@ files:
157
158
  - ezcater_rubocop.gemspec
158
159
  - lib/ezcater_rubocop.rb
159
160
  - lib/ezcater_rubocop/version.rb
161
+ - lib/rubocop/cop/ezcater/direct_env_check.rb
160
162
  - lib/rubocop/cop/ezcater/rails_configuration.rb
163
+ - lib/rubocop/cop/ezcater/rails_env.rb
161
164
  - lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
162
165
  - lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
163
166
  - lib/rubocop/cop/ezcater/rspec_match_ordered_array.rb
@@ -186,8 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
189
  - !ruby/object:Gem::Version
187
190
  version: '0'
188
191
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.7.6
192
+ rubygems_version: 3.0.3
191
193
  signing_key:
192
194
  specification_version: 4
193
195
  summary: ezCater custom cops and shared configuration