rubocop-packs 0.0.27 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +1 -0
- data/lib/rubocop/cop/packs/class_methods_as_public_apis.rb +21 -1
- data/lib/rubocop/packs.rb +5 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4888c0b36e59d1da1aaa62d1390da897fce811909d99c5e1189bca0efd36050
|
4
|
+
data.tar.gz: 7d1957e8c598a6acbcfa3b0b8f49578dcb3424d01c20178c2045459654a2478f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b55558140df2b0d0e68f64668a94e814c30a6ac42b144d0dc7fbc7118bdf982fb87b45085592ca219946ae6a2df73bb22562a83ae888fb021343ec0cea7c685c
|
7
|
+
data.tar.gz: fa54dc58358e0f32104c2acfa0536ff6239430c287a75e5ad0a346ae9979360f59a67037a34599e98a1df525cbe6c31c7350af95b6c33dba1dcdacb02cbdfe88
|
data/config/default.yml
CHANGED
@@ -10,6 +10,7 @@ module RuboCop
|
|
10
10
|
# Options:
|
11
11
|
#
|
12
12
|
# * `AcceptableParentClasses`: A list of classes that, if inherited from, non-class methods are permitted (useful when value objects are a part of your public API)
|
13
|
+
# * `AcceptableMixins`: A list of modules that, if included, non-class methods are permitted
|
13
14
|
#
|
14
15
|
# @example
|
15
16
|
#
|
@@ -47,11 +48,14 @@ module RuboCop
|
|
47
48
|
|
48
49
|
acceptable_parent_classes = cop_config['AcceptableParentClasses'] || []
|
49
50
|
|
50
|
-
# Used this PR as inspiration to check if we're within a `class << self` block
|
51
51
|
uses_implicit_static_methods = node.each_ancestor(:sclass).first&.identifier&.source == 'self'
|
52
52
|
class_is_allowed_to_have_instance_methods = acceptable_parent_classes.include?(parent_class&.const_name)
|
53
53
|
return if uses_implicit_static_methods || class_is_allowed_to_have_instance_methods
|
54
54
|
|
55
|
+
is_sorbet_interface_or_abstract_class = !module_node.nil? && module_node.descendants.any? { |d| d.is_a?(RuboCop::AST::SendNode) && (d.method_name == :interface! || d.method_name == :abstract!) }
|
56
|
+
return if is_sorbet_interface_or_abstract_class
|
57
|
+
return if node_includes_acceptable_mixin?(class_node || module_node)
|
58
|
+
|
55
59
|
add_offense(
|
56
60
|
node.source_range,
|
57
61
|
message: format(
|
@@ -59,6 +63,22 @@ module RuboCop
|
|
59
63
|
)
|
60
64
|
)
|
61
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
sig { params(node: T.untyped).returns(T::Boolean) }
|
70
|
+
def node_includes_acceptable_mixin?(node)
|
71
|
+
acceptable_mixins = cop_config['AcceptableMixins'] || []
|
72
|
+
return false if node.nil?
|
73
|
+
|
74
|
+
node.descendants.any? do |d|
|
75
|
+
d.is_a?(RuboCop::AST::SendNode) &&
|
76
|
+
d.method_name == :include &&
|
77
|
+
d.arguments.count == 1 &&
|
78
|
+
d.arguments.first.is_a?(RuboCop::AST::ConstNode) &&
|
79
|
+
acceptable_mixins.include?(d.arguments.first.const_name)
|
80
|
+
end
|
81
|
+
end
|
62
82
|
end
|
63
83
|
end
|
64
84
|
end
|
data/lib/rubocop/packs.rb
CHANGED
@@ -51,9 +51,11 @@ module RuboCop
|
|
51
51
|
rubocop_todo = {}
|
52
52
|
end
|
53
53
|
|
54
|
-
offenses_for_pack.each do |
|
55
|
-
|
56
|
-
|
54
|
+
offenses_for_pack.group_by(&:filepath).each do |filepath, offenses_by_filepath|
|
55
|
+
offenses_by_filepath.map(&:cop_name).uniq.each do |cop_name|
|
56
|
+
rubocop_todo[cop_name] ||= { 'Exclude' => [] }
|
57
|
+
rubocop_todo[cop_name]['Exclude'] << filepath
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
61
|
next if rubocop_todo.empty?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-packs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gusto Engineers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -178,7 +178,7 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
-
description:
|
181
|
+
description: A collection of Rubocop rules for gradually modularizing a ruby codebase
|
182
182
|
email:
|
183
183
|
- dev@gusto.com
|
184
184
|
executables: []
|
@@ -230,5 +230,5 @@ requirements: []
|
|
230
230
|
rubygems_version: 3.1.6
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
|
-
summary:
|
233
|
+
summary: A collection of Rubocop rules for gradually modularizing a ruby codebase
|
234
234
|
test_files: []
|