betterlint 1.26.0 → 1.27.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: 521829c1a24b2013526ec739c7767473854130c2e57f7c29b184011f059264a4
4
- data.tar.gz: a7cb5622266cc225688096b99811eae23fec5a1af226e410f205986c3d7414ac
3
+ metadata.gz: 6bd1ad5be3babcc02d2b5c8f481e9106bf90d575849e9f309d44b137298b1ab0
4
+ data.tar.gz: d999b55f53b8528b169110f2257b1b0cb0127629b50ecdfcc5a59250cb9f79c3
5
5
  SHA512:
6
- metadata.gz: cc3c3e063757b97e37257303a939e2d6d13bd8534646c5b0047f2fd58a229979bf2687702025a6d24971dac784b987c2393d67df79bc58875842500d67f55cb0
7
- data.tar.gz: 0e1171c10b8c6b26f71cc13ddd77694487fce3749e40d84931ad82d90d0f57bf9eaea48bd16504c64695cdc95686932625de0dd4c56853c6bb2bf2807539a6ce
6
+ metadata.gz: af695c343d0618c7d0ac9bc937a67e99fdc5732e6d507bf8efb6a11d1d4981c437dd3118881bd09e504a3427de8e44a852cc7790502767022671de9c2fa88bfa
7
+ data.tar.gz: 56309c5e67dbdd2c4c6a83eb51cf466b2195f5f3deb6ad9b16409e4595b032c2c7aa3140b731a00b325ee5bbcfe14a694ec96b2c3c0d99c53c124059fb680c18
data/STYLEGUIDE.md CHANGED
@@ -110,6 +110,39 @@ expect(response).to have_http_status :internal_server_error
110
110
  expect(response).to have_http_status 500
111
111
  ```
112
112
 
113
+ ## Betterment/NonNamespacedClass
114
+
115
+ This cop prevents defining classes at the top level without a namespace. All classes should be defined within a module namespace to avoid polluting the global namespace and to better organize code.
116
+
117
+ ### BAD:
118
+
119
+ ```ruby
120
+ class MyClass
121
+ def my_method
122
+ end
123
+ end
124
+ ```
125
+
126
+ ### GOOD:
127
+
128
+ ```ruby
129
+ module MyNamespace
130
+ class MyClass
131
+ def my_method
132
+ end
133
+ end
134
+ end
135
+ ```
136
+
137
+ or using the `::` syntax:
138
+
139
+ ```ruby
140
+ class MyNamespace::MyClass
141
+ def my_method
142
+ end
143
+ end
144
+ ```
145
+
113
146
  ## Betterment/SimpleDelegator
114
147
 
115
148
  This cop requires you to use Rail's `delegate` class method instead of `SimpleDelegator` in order to explicitly specify
data/config/default.yml CHANGED
@@ -62,6 +62,11 @@ Betterment/InternalsProtection:
62
62
  StyleGuide: '#bettermentinternalsprotection'
63
63
  Enabled: false
64
64
 
65
+ Betterment/NonNamespacedClass:
66
+ Description: Detects classes that are not namespaced under a module or constant
67
+ StyleGuide: '#bettermentnonamespacedclass'
68
+ Enabled: false
69
+
65
70
  Betterment/NonStandardActions:
66
71
  AdditionalAllowedActions: []
67
72
  Description: Detects non-standard controller actions.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betterlint
4
- VERSION = '1.26.0'
4
+ VERSION = '1.27.0'
5
5
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Betterment
6
+ class NonNamespacedClass < Base
7
+ MSG = <<~TEXT.gsub(/\s+/, " ").strip
8
+ Do not add new classes that are not namespaced underneath another constant.
9
+ Classes should be defined within a module namespace (e.g., `module MyNamespace; class Foo; end; end`)
10
+ or use the `::` syntax (e.g., `class MyNamespace::Foo`).
11
+ TEXT
12
+
13
+ def on_class(node)
14
+ class_name_node = node.children[0]
15
+
16
+ # Skip if the class name is nil (anonymous class)
17
+ return unless class_name_node
18
+
19
+ if class_name_node.const_type? && !namespaced?(class_name_node) && !inside_namespace?(node)
20
+ add_offense(node)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def namespaced?(node)
27
+ node.children.first&.const_type?
28
+ end
29
+
30
+ def inside_namespace?(node)
31
+ node.each_ancestor(:module, :class).any?
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -12,6 +12,7 @@ require 'rubocop/cop/betterment/hardcoded_id'
12
12
  require 'rubocop/cop/betterment/implicit_redirect_type'
13
13
  require 'rubocop/cop/betterment/internals_protection'
14
14
  require 'rubocop/cop/betterment/memoization_with_arguments'
15
+ require 'rubocop/cop/betterment/non_namespaced_class'
15
16
  require 'rubocop/cop/betterment/non_standard_actions'
16
17
  require 'rubocop/cop/betterment/non_standard_controller'
17
18
  require 'rubocop/cop/betterment/not_using_rswag'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.26.0
4
+ version: 1.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-17 00:00:00.000000000 Z
11
+ date: 2026-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lint_roller
@@ -180,6 +180,7 @@ files:
180
180
  - lib/rubocop/cop/betterment/implicit_redirect_type.rb
181
181
  - lib/rubocop/cop/betterment/internals_protection.rb
182
182
  - lib/rubocop/cop/betterment/memoization_with_arguments.rb
183
+ - lib/rubocop/cop/betterment/non_namespaced_class.rb
183
184
  - lib/rubocop/cop/betterment/non_standard_actions.rb
184
185
  - lib/rubocop/cop/betterment/non_standard_controller.rb
185
186
  - lib/rubocop/cop/betterment/not_using_rswag.rb
@@ -202,10 +203,10 @@ licenses:
202
203
  - MIT
203
204
  metadata:
204
205
  homepage_uri: https://github.com/Betterment/betterlint
205
- source_code_uri: https://github.com/Betterment/betterlint/tree/v1.26.0
206
- changelog_uri: https://github.com/Betterment/betterlint/blob/v1.26.0/CHANGELOG.md
206
+ source_code_uri: https://github.com/Betterment/betterlint/tree/v1.27.0
207
+ changelog_uri: https://github.com/Betterment/betterlint/blob/v1.27.0/CHANGELOG.md
207
208
  bug_tracker_uri: https://github.com/Betterment/betterlint/issues
208
- documentation_uri: https://www.rubydoc.info/gems/betterlint/1.26.0
209
+ documentation_uri: https://www.rubydoc.info/gems/betterlint/1.27.0
209
210
  rubygems_mfa_required: 'true'
210
211
  default_lint_roller_plugin: Betterlint::Plugin
211
212
  post_install_message: