nxt_cop 2.0.2 → 2.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 +4 -4
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -3
- data/custom_cops/nxt_core/rails/missing_logger_include.rb +39 -0
- data/custom_cops/nxt_core/rails/use_of_rails_logger.rb +25 -0
- data/default.yml +8 -0
- data/lib/nxt_cop/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31120e5b23ae4a12f07a900c4331cf782390dd6e33d1e1f85ec700bfb6b40bc4
|
4
|
+
data.tar.gz: b6177b79c00d01220d57ded64b554e84106db6d87a0173b106bdc8e4d5f70aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c78924a1a8ad16e71c65989580e6b22b17e9fca132829fcd8d0b179284ba37c0aea827633acd1fb0ddfb30b29e8b1c904bf4e4398f3d814dce8ea2a1762775a3
|
7
|
+
data.tar.gz: a4526ac0f36242d8114a3d681453585dda82f9a0c5cb5420f3d2d7afe3b128a5ad277660c6fba0c75cd0dab85993b0af495a41c2ca5d783ed2c65da4e42d2ca7
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_cop (2.0
|
4
|
+
nxt_cop (2.1.0)
|
5
5
|
rubocop (~> 1.60.0)
|
6
6
|
rubocop-rails (~> 2.8)
|
7
7
|
rubocop-rspec (~> 2.12)
|
@@ -33,7 +33,7 @@ GEM
|
|
33
33
|
minitest (5.21.2)
|
34
34
|
mutex_m (0.2.0)
|
35
35
|
parallel (1.24.0)
|
36
|
-
parser (3.3.0.
|
36
|
+
parser (3.3.0.5)
|
37
37
|
ast (~> 2.4.1)
|
38
38
|
racc
|
39
39
|
racc (1.7.3)
|
@@ -42,7 +42,7 @@ GEM
|
|
42
42
|
rake (13.1.0)
|
43
43
|
regexp_parser (2.9.0)
|
44
44
|
rexml (3.2.6)
|
45
|
-
rubocop (1.60.
|
45
|
+
rubocop (1.60.2)
|
46
46
|
json (~> 2.3)
|
47
47
|
language_server-protocol (>= 3.17.0)
|
48
48
|
parallel (~> 1.10)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomCops
|
4
|
+
module NxtCore
|
5
|
+
module Rails
|
6
|
+
# The NxtCore logger requires an include in most cases. Ensures it is present.
|
7
|
+
#
|
8
|
+
# @safety
|
9
|
+
# This cop's autocorrection is unsafe because
|
10
|
+
# `logger` may refer to an instance variable or other method of the class.
|
11
|
+
class MissingLoggerInclude < RuboCop::Cop::Base
|
12
|
+
extend RuboCop::Cop::AutoCorrector
|
13
|
+
|
14
|
+
RESTRICT_ON_SEND = [:logger].freeze
|
15
|
+
|
16
|
+
MSG = 'Missing `include Nxt::Loggable` for a class which uses the logger.'
|
17
|
+
|
18
|
+
# NodePattern docs: https://github.com/rubocop/rubocop-ast/blob/master/docs/modules/ROOT/pages/node_pattern.adoc
|
19
|
+
def_node_matcher :includes_nxt_loggable?, <<~PATTERN
|
20
|
+
(begin <(send nil? :include (const (const nil? :Nxt) :Loggable)) ...>)
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
return unless node.receiver.nil?
|
25
|
+
|
26
|
+
class_node = node.ancestors.find(&:class_type?)
|
27
|
+
return unless class_node
|
28
|
+
|
29
|
+
class_definition_node = class_node.each_child_node(:begin).first
|
30
|
+
return if includes_nxt_loggable?(class_definition_node)
|
31
|
+
|
32
|
+
add_offense(class_node, message: MSG) do |corrector|
|
33
|
+
corrector.insert_before(class_definition_node.child_nodes.first, "include Nxt::Loggable\n")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomCops
|
4
|
+
module NxtCore
|
5
|
+
module Rails
|
6
|
+
# Ensures that the NxtCore logger is used instead of `Rails.logger`.
|
7
|
+
class UseOfRailsLogger < RuboCop::Cop::Base
|
8
|
+
extend RuboCop::Cop::AutoCorrector
|
9
|
+
|
10
|
+
RESTRICT_ON_SEND = [:logger].freeze
|
11
|
+
|
12
|
+
MSG = 'Use of Rails.logger is not allowed. Use `logger` and include `Nxt::Loggable`'
|
13
|
+
|
14
|
+
def on_send(node)
|
15
|
+
return unless node.receiver&.const_type? && node.receiver.short_name == :Rails
|
16
|
+
|
17
|
+
add_offense(node, message: MSG) do |corrector|
|
18
|
+
corrected = node.source.gsub('Rails.logger', 'logger')
|
19
|
+
corrector.replace(node, corrected)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/default.yml
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
require:
|
2
2
|
- rubocop-rails
|
3
3
|
- rubocop-rspec
|
4
|
+
- ./custom_cops/nxt_core/rails/use_of_rails_logger.rb
|
5
|
+
- ./custom_cops/nxt_core/rails/missing_logger_include.rb
|
4
6
|
|
5
7
|
inherit_mode:
|
6
8
|
merge:
|
7
9
|
- Exclude
|
8
10
|
- Include
|
9
11
|
|
12
|
+
Rails/UseOfRailsLogger:
|
13
|
+
Description: "Custom Getsafe cop to ensure the correct logger is used"
|
14
|
+
Rails/MissingLoggerInclude:
|
15
|
+
Description: "Custom Getsafe cop to find missing `include` statements when using our custom logger"
|
16
|
+
SafeAutoCorrect: false
|
17
|
+
|
10
18
|
AllCops:
|
11
19
|
Exclude:
|
12
20
|
- bin/guard
|
data/lib/nxt_cop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nxt_cop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Livingstone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -88,6 +88,7 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- ".gitignore"
|
90
90
|
- ".rubocop.yml"
|
91
|
+
- ".ruby-version"
|
91
92
|
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- Gemfile.lock
|
@@ -98,6 +99,8 @@ files:
|
|
98
99
|
- bin/guard
|
99
100
|
- bin/rspec
|
100
101
|
- bin/setup
|
102
|
+
- custom_cops/nxt_core/rails/missing_logger_include.rb
|
103
|
+
- custom_cops/nxt_core/rails/use_of_rails_logger.rb
|
101
104
|
- default.yml
|
102
105
|
- lib/nxt_cop/version.rb
|
103
106
|
- nxt_cop.gemspec
|
@@ -124,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
127
|
- !ruby/object:Gem::Version
|
125
128
|
version: '0'
|
126
129
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.5.3
|
128
131
|
signing_key:
|
129
132
|
specification_version: 4
|
130
133
|
summary: Getsafe shared Rubocop.
|