rubocop-neeto 0.1.14 → 0.1.16
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 +4 -4
- data/README.md +1 -0
- data/config/default.yml +21 -6
- data/lib/rubocop/cop/neeto/deprecated_job_base_class.rb +72 -0
- data/lib/rubocop/cop/neeto/direct_env_access.rb +10 -11
- data/lib/rubocop/cop/neeto_cops.rb +1 -0
- data/lib/rubocop/neeto/version.rb +1 -1
- 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: fef927f6b5a152b14ff20ef805c7827e613f8daa8328545d523c9d9835d7aa54
|
|
4
|
+
data.tar.gz: 7042247a4a2f2c6a67ade4f63ef09269fae0ada7eea76ed0994fac82fb4d8e51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78bb3316b19e1711485815504076819bb08f336af7ae7b780dc4beb40f816ae71a54d5c11de2bf7144f3eeb970fd4e0297e530a61ac865e406329a9c57e50d1d
|
|
7
|
+
data.tar.gz: 6994e654164b41c70e859fe75517c6650be12ec56ff4d84508cd4de13bc888e8fe6b1278c58c163a8b17d67eab22a623bd413d5f55b2733b97a549686021c13b
|
data/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
1. [Neeto/UnsafeTableDeletion](https://rubocop-neeto.neetodeployapp.com/docs/RuboCop/Cop/Neeto/UnsafeTableDeletion)
|
|
6
6
|
2. [Neeto/UnsafeColumnDeletion](https://rubocop-neeto.neetodeployapp.com/docs/RuboCop/Cop/Neeto/UnsafeColumnDeletion)
|
|
7
7
|
3. [Neeto/DirectEnvAccess](https://rubocop-neeto.neetodeployapp.com/docs/RuboCop/Cop/Neeto/DirectEnvAccess)
|
|
8
|
+
4. [Neeto/DeprecatedJobBaseClass](https://rubocop-neeto.neetodeployapp.com/docs/RuboCop/Cop/Neeto/DeprecatedJobBaseClass)
|
|
8
9
|
|
|
9
10
|
## Installation
|
|
10
11
|
|
data/config/default.yml
CHANGED
|
@@ -26,14 +26,29 @@ Neeto/UnsafeColumnDeletion:
|
|
|
26
26
|
|
|
27
27
|
Neeto/DirectEnvAccess:
|
|
28
28
|
Description: >-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
their defaults. Use `Secvault.secrets` instead.
|
|
29
|
+
`config/secrets.yml` provides a single source of truth for all environment
|
|
30
|
+
variables and their fallback values, loaded via Rails' built-in
|
|
31
|
+
`config_for`. Direct usage of `ENV` bypasses this system, making it harder
|
|
32
|
+
to track what environment variables are being used and their defaults.
|
|
33
|
+
Use `Rails.application.secrets` instead.
|
|
35
34
|
Enabled: true
|
|
36
35
|
Severity: refactor
|
|
37
36
|
VersionAdded: '0.1'
|
|
38
37
|
Include:
|
|
39
38
|
- app/**/*.rb
|
|
39
|
+
|
|
40
|
+
Neeto/DeprecatedJobBaseClass:
|
|
41
|
+
Description: >-
|
|
42
|
+
Jobs should not inherit directly from the legacy
|
|
43
|
+
`NeetoCommonsBackend::BaseJobs::*` base classes. Use latency-based job
|
|
44
|
+
classes such as `LatencyBasedJobs::Within5Seconds`,
|
|
45
|
+
`LatencyBasedJobs::Within1Minute`, `LatencyBasedJobs::Within5Minutes`,
|
|
46
|
+
or `LatencyBasedJobs::Within1Hour` instead.
|
|
47
|
+
Enabled: true
|
|
48
|
+
Severity: refactor
|
|
49
|
+
VersionAdded: '0.1'
|
|
50
|
+
Include:
|
|
51
|
+
- app/jobs/**/*.rb
|
|
52
|
+
- app/workers/**/*.rb
|
|
53
|
+
- test/dummy/app/jobs/**/*.rb
|
|
54
|
+
- test/dummy/app/workers/**/*.rb
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Neeto
|
|
6
|
+
# The legacy `NeetoCommonsBackend::BaseJobs::*` base classes have been
|
|
7
|
+
# replaced with latency-based job classes such as
|
|
8
|
+
# `LatencyBasedJobs::Within5Seconds`, `LatencyBasedJobs::Within1Minute`,
|
|
9
|
+
# `LatencyBasedJobs::Within5Minutes`, and `LatencyBasedJobs::Within1Hour`.
|
|
10
|
+
# This cop prevents new jobs from inheriting directly from the legacy
|
|
11
|
+
# Neeto Commons base classes.
|
|
12
|
+
#
|
|
13
|
+
# @example DeprecatedJobBaseClass: true (default)
|
|
14
|
+
# # bad
|
|
15
|
+
# class ExportJob < NeetoCommonsBackend::BaseJobs::Default
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# # bad
|
|
19
|
+
# class SyncWebhookJob < NeetoCommonsBackend::BaseJobs::Urgent
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# # good
|
|
23
|
+
# class ExportJob < LatencyBasedJobs::Within5Minutes
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# # good
|
|
27
|
+
# class SyncWebhookJob < LatencyBasedJobs::Within5Seconds
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# # good
|
|
31
|
+
# # Defining the latency classes themselves
|
|
32
|
+
# module LatencyBasedJobs
|
|
33
|
+
# class Within5Seconds < NeetoCommonsBackend::BaseJobs::Base
|
|
34
|
+
# end
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
class DeprecatedJobBaseClass < Base
|
|
38
|
+
LEGACY_SUPERCLASSES = {
|
|
39
|
+
"NeetoCommonsBackend::BaseJobs::Urgent" => "Use `LatencyBasedJobs::Within5Seconds` instead.",
|
|
40
|
+
"NeetoCommonsBackend::BaseJobs::Auth" => "Use `LatencyBasedJobs::Within1Minute` instead.",
|
|
41
|
+
"NeetoCommonsBackend::BaseJobs::Default" => "Use `LatencyBasedJobs::Within1Minute` or `LatencyBasedJobs::Within5Minutes` based on the job's SLA.",
|
|
42
|
+
"NeetoCommonsBackend::BaseJobs::Low" => "Use `LatencyBasedJobs::Within1Hour` instead.",
|
|
43
|
+
"NeetoCommonsBackend::BaseJobs::Base" => "Use a latency-based job base class instead, for example `LatencyBasedJobs::Within5Seconds`, `LatencyBasedJobs::Within1Minute`, `LatencyBasedJobs::Within5Minutes`, or `LatencyBasedJobs::Within1Hour`."
|
|
44
|
+
}.freeze
|
|
45
|
+
|
|
46
|
+
MSG = "Do not inherit jobs directly from `%<superclass>s`. %<replacement>s"
|
|
47
|
+
|
|
48
|
+
def on_class(node)
|
|
49
|
+
return if allowed_file_path?
|
|
50
|
+
|
|
51
|
+
superclass = node.parent_class
|
|
52
|
+
return unless superclass&.const_type?
|
|
53
|
+
|
|
54
|
+
superclass_name = superclass.const_name
|
|
55
|
+
replacement = LEGACY_SUPERCLASSES[superclass_name]
|
|
56
|
+
return unless replacement
|
|
57
|
+
|
|
58
|
+
add_offense(superclass, message: format(MSG, superclass: superclass_name, replacement:))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def allowed_file_path?
|
|
64
|
+
file_path = processed_source.file_path.to_s
|
|
65
|
+
|
|
66
|
+
file_path.end_with?("app/jobs/concerns/latency_based_jobs.rb") ||
|
|
67
|
+
file_path.match?(%r{(?:\A|/)app/jobs/neeto_commons_backend/base_jobs/})
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -3,16 +3,15 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Neeto
|
|
6
|
-
#
|
|
7
|
-
# environment variables and their fallback values
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
# that all environment variable access goes through `Secvault.secrets`.
|
|
6
|
+
# `config/secrets.yml` provides a single source of truth for all
|
|
7
|
+
# environment variables and their fallback values, loaded via Rails'
|
|
8
|
+
# built-in `config_for`. Direct usage of `ENV` bypasses this system,
|
|
9
|
+
# making it harder to track what environment variables are being used
|
|
10
|
+
# and their defaults. This cop enforces that all environment variable
|
|
11
|
+
# access goes through `Rails.application.secrets`.
|
|
13
12
|
#
|
|
14
13
|
# @example DirectEnvAccess: true (default)
|
|
15
|
-
# # Enforces the usage of `
|
|
14
|
+
# # Enforces the usage of `Rails.application.secrets` over direct `ENV` access.
|
|
16
15
|
#
|
|
17
16
|
# # bad
|
|
18
17
|
# api_key = ENV['STRIPE_API_KEY']
|
|
@@ -21,17 +20,17 @@ module RuboCop
|
|
|
21
20
|
# default_timezone = ENV['DEFAULT_TIMEZONE'] || 'UTC'
|
|
22
21
|
#
|
|
23
22
|
# # good
|
|
24
|
-
# api_key =
|
|
23
|
+
# api_key = Rails.application.secrets.stripe_api_key
|
|
25
24
|
#
|
|
26
25
|
# # good
|
|
27
|
-
# default_timezone =
|
|
26
|
+
# default_timezone = Rails.application.secrets.default_timezone
|
|
28
27
|
#
|
|
29
28
|
# # good (ENV access is permitted in directories other than the app directory)
|
|
30
29
|
# config.log_level = ENV.fetch('LOG_LEVEL', 'info')
|
|
31
30
|
#
|
|
32
31
|
class DirectEnvAccess < Base
|
|
33
32
|
MSG = "Do not use ENV directly. " \
|
|
34
|
-
"Use
|
|
33
|
+
"Use Rails.application.secrets to maintain a single source of truth for configuration."
|
|
35
34
|
|
|
36
35
|
def_node_matcher :env_access?, <<~PATTERN
|
|
37
36
|
(const {nil? cbase} :ENV)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-neeto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abhay V Ashokan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|
|
@@ -35,6 +35,7 @@ files:
|
|
|
35
35
|
- Rakefile
|
|
36
36
|
- config/default.yml
|
|
37
37
|
- lib/rubocop-neeto.rb
|
|
38
|
+
- lib/rubocop/cop/neeto/deprecated_job_base_class.rb
|
|
38
39
|
- lib/rubocop/cop/neeto/direct_env_access.rb
|
|
39
40
|
- lib/rubocop/cop/neeto/unsafe_column_deletion.rb
|
|
40
41
|
- lib/rubocop/cop/neeto/unsafe_table_deletion.rb
|