nxt_cop 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbd4cf87a6cdec2af74789d277deed6b7827251b00237a6aa031bcafabef5737
4
- data.tar.gz: 1edc20eb4e39f0f7d9a9e3e9b9d2c770b4fc7817a2b3e8814dd87132770947b6
3
+ metadata.gz: 31120e5b23ae4a12f07a900c4331cf782390dd6e33d1e1f85ec700bfb6b40bc4
4
+ data.tar.gz: b6177b79c00d01220d57ded64b554e84106db6d87a0173b106bdc8e4d5f70aa0
5
5
  SHA512:
6
- metadata.gz: 51e915c704f32e3fa571b3cc3e8dd4d5d57d09fad40e81010424b75b85ddc06e6c5e12f8ee7a3efc059787cd2802d42d68fa55e379223390a46705921cb7fb65
7
- data.tar.gz: 7f34022a50fa24a7536ce367e018880d033b6a5cc6c247a50ed89c97b0cde2c0721f9992e28344ff10b54d83b6028592883d18341fbd5a7b80d36578b62ca19e
6
+ metadata.gz: c78924a1a8ad16e71c65989580e6b22b17e9fca132829fcd8d0b179284ba37c0aea827633acd1fb0ddfb30b29e8b1c904bf4e4398f3d814dce8ea2a1762775a3
7
+ data.tar.gz: a4526ac0f36242d8114a3d681453585dda82f9a0c5cb5420f3d2d7afe3b128a5ad277660c6fba0c75cd0dab85993b0af495a41c2ca5d783ed2c65da4e42d2ca7
data/.rubocop.yml CHANGED
@@ -1 +1,4 @@
1
1
  inherit_from: default.yml
2
+
3
+ Rails:
4
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v2.1.0 2024-01-26
2
+ ## What's Changed
3
+ - Add cops for Rails + NxtCore logger functionality
4
+
1
5
  # v2.0.2 2024-01-10
2
6
  ## What's Changed
3
7
  * Disable more cops depending on the code style in our backend-services
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_cop (2.0.2)
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.4)
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.1)
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
@@ -1,3 +1,3 @@
1
1
  module NxtCop
2
- VERSION = '2.0.2'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
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.2
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-18 00:00:00.000000000 Z
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.4.10
130
+ rubygems_version: 3.5.3
128
131
  signing_key:
129
132
  specification_version: 4
130
133
  summary: Getsafe shared Rubocop.