betterlint 1.26.0 → 1.28.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/STYLEGUIDE.md +33 -0
- data/config/default.yml +6 -0
- data/lib/betterlint/version.rb +1 -1
- data/lib/rubocop/cop/betterment/non_namespaced_class.rb +52 -0
- data/lib/rubocop/cop/betterment.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 070e58e2493975205fb3f5f52f1c6082109835db4388e67d7876bfd471861e59
|
|
4
|
+
data.tar.gz: 73a4c6ddd11054bd6b2c3add1e3963f62b6849241b2eb4be2a41a1bec41cc2f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c212dd812b46431b40bea0876f5aeefe5d4f657ef59bb0355342a4e22d19e167cbe950ca7edd237ad581e17cc2400f7c08cabc84ce677b16731f56957ba517d6
|
|
7
|
+
data.tar.gz: 486bdb3b54a34ee2363cf482e113a928840bda36ca94a9407e2b269748fa534a24d75e407df839d5b86561dedb50c9a1648558b507ae49acf6152b77866cfb8a
|
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,12 @@ 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
|
+
AllowedClasses: []
|
|
70
|
+
|
|
65
71
|
Betterment/NonStandardActions:
|
|
66
72
|
AdditionalAllowedActions: []
|
|
67
73
|
Description: Detects non-standard controller actions.
|
data/lib/betterlint/version.rb
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Betterment
|
|
6
|
+
class NonNamespacedClass < Base
|
|
7
|
+
attr_accessor :allowed_classes
|
|
8
|
+
|
|
9
|
+
MSG = <<~TEXT
|
|
10
|
+
Do not add new classes that are not namespaced underneath another constant.
|
|
11
|
+
Classes should be defined within a module namespace (e.g., `module MyNamespace; class Foo; end; end`)
|
|
12
|
+
or use the `::` syntax (e.g., `class MyNamespace::Foo`).
|
|
13
|
+
|
|
14
|
+
See here for more information on this cop:
|
|
15
|
+
https://github.com/Betterment/betterlint/blob/main/README.md#bettermentnonamespacedclass
|
|
16
|
+
TEXT
|
|
17
|
+
|
|
18
|
+
def initialize(config = nil, options = nil)
|
|
19
|
+
super
|
|
20
|
+
@allowed_classes = cop_config.fetch("AllowedClasses", []).map(&:to_sym)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def on_class(node)
|
|
24
|
+
class_name_node = node.children[0]
|
|
25
|
+
|
|
26
|
+
# Skip if the class name is nil (anonymous class)
|
|
27
|
+
return unless class_name_node
|
|
28
|
+
|
|
29
|
+
class_name = class_name_node.short_name
|
|
30
|
+
|
|
31
|
+
if class_name_node.const_type? &&
|
|
32
|
+
!namespaced?(class_name_node) &&
|
|
33
|
+
!inside_namespace?(node) &&
|
|
34
|
+
!allowed_classes.include?(class_name)
|
|
35
|
+
|
|
36
|
+
add_offense(node)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def namespaced?(node)
|
|
43
|
+
node.children.first&.const_type?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def inside_namespace?(node)
|
|
47
|
+
node.each_ancestor(:module, :class).any?
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
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.
|
|
4
|
+
version: 1.28.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Development
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-28 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.
|
|
206
|
-
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.
|
|
206
|
+
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.28.0
|
|
207
|
+
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.28.0/CHANGELOG.md
|
|
207
208
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
|
208
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
|
209
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.28.0
|
|
209
210
|
rubygems_mfa_required: 'true'
|
|
210
211
|
default_lint_roller_plugin: Betterlint::Plugin
|
|
211
212
|
post_install_message:
|