nxt_cop 2.0.2 → 2.2.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: dbd4cf87a6cdec2af74789d277deed6b7827251b00237a6aa031bcafabef5737
4
- data.tar.gz: 1edc20eb4e39f0f7d9a9e3e9b9d2c770b4fc7817a2b3e8814dd87132770947b6
3
+ metadata.gz: 0aa842f12fc52becc03c69ab9b31ed84490cef95cfab304e560afdaedc076dab
4
+ data.tar.gz: 6f5a9aa11731b24bbe97107efec680a5e7aa7753752419c69b4f3051ea605ee5
5
5
  SHA512:
6
- metadata.gz: 51e915c704f32e3fa571b3cc3e8dd4d5d57d09fad40e81010424b75b85ddc06e6c5e12f8ee7a3efc059787cd2802d42d68fa55e379223390a46705921cb7fb65
7
- data.tar.gz: 7f34022a50fa24a7536ce367e018880d033b6a5cc6c247a50ed89c97b0cde2c0721f9992e28344ff10b54d83b6028592883d18341fbd5a7b80d36578b62ca19e
6
+ metadata.gz: 7bcca20a477fd8130a27aa595f0eb39cd548502d6f6accd75a8cef97931e0f2b7627244be6776b72afb8b0f231f1716146a74c23151968ce9c5e36e1b66f36ac
7
+ data.tar.gz: fa16aa38b4f39b64b8592774f5306ad08692a0058090f070e57f7ed794ffe9624ef3ff5e9c755ef77388ba8d4c2444632e79b013529c9199b21eee141e67aaae
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/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.3.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v2.2.0 2024-01-30
2
+ ## What's Changed
3
+ - Add rubocop-factory_bot
4
+
5
+ # v2.1.0 2024-01-26
6
+ ## What's Changed
7
+ - Add cops for Rails + NxtCore logger functionality
8
+
1
9
  # v2.0.2 2024-01-10
2
10
  ## What's Changed
3
11
  * 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.2.0)
5
5
  rubocop (~> 1.60.0)
6
6
  rubocop-rails (~> 2.8)
7
7
  rubocop-rspec (~> 2.12)
@@ -30,19 +30,19 @@ GEM
30
30
  concurrent-ruby (~> 1.0)
31
31
  json (2.7.1)
32
32
  language_server-protocol (3.17.0.3)
33
- minitest (5.21.2)
33
+ minitest (5.22.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)
40
- rack (3.0.8)
40
+ rack (3.0.9)
41
41
  rainbow (3.1.1)
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,21 @@
1
1
  require:
2
+ - rubocop-factory_bot
2
3
  - rubocop-rails
3
4
  - rubocop-rspec
5
+ - ./custom_cops/nxt_core/rails/use_of_rails_logger.rb
6
+ - ./custom_cops/nxt_core/rails/missing_logger_include.rb
4
7
 
5
8
  inherit_mode:
6
9
  merge:
7
10
  - Exclude
8
11
  - Include
9
12
 
13
+ Rails/UseOfRailsLogger:
14
+ Description: "Custom Getsafe cop to ensure the correct logger is used"
15
+ Rails/MissingLoggerInclude:
16
+ Description: "Custom Getsafe cop to find missing `include` statements when using our custom logger"
17
+ SafeAutoCorrect: false
18
+
10
19
  AllCops:
11
20
  Exclude:
12
21
  - bin/guard
@@ -1,3 +1,3 @@
1
1
  module NxtCop
2
- VERSION = '2.0.2'.freeze
2
+ VERSION = '2.2.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.2.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-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -88,6 +88,8 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - ".gitignore"
90
90
  - ".rubocop.yml"
91
+ - ".ruby-version"
92
+ - ".tool-versions"
91
93
  - CHANGELOG.md
92
94
  - Gemfile
93
95
  - Gemfile.lock
@@ -98,6 +100,8 @@ files:
98
100
  - bin/guard
99
101
  - bin/rspec
100
102
  - bin/setup
103
+ - custom_cops/nxt_core/rails/missing_logger_include.rb
104
+ - custom_cops/nxt_core/rails/use_of_rails_logger.rb
101
105
  - default.yml
102
106
  - lib/nxt_cop/version.rb
103
107
  - nxt_cop.gemspec
@@ -124,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
128
  - !ruby/object:Gem::Version
125
129
  version: '0'
126
130
  requirements: []
127
- rubygems_version: 3.4.10
131
+ rubygems_version: 3.5.3
128
132
  signing_key:
129
133
  specification_version: 4
130
134
  summary: Getsafe shared Rubocop.