rubocop-packs 0.0.27 → 0.0.29
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 +11 -4
- 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: 3696297e1ff13e40a7dbfee5a582c67490833b383b968469f9d2d94ab5ffee5d
|
4
|
+
data.tar.gz: ff4e0adde358d7540e3e5a568d9fd4e75b20145df58513579b30d9c754a00509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a78487b44c2b54f4b4f96f829bb436b928c044005d9625e76d27a4453f278f08fb78b9605246e67125168b64479111ed157d54b129d19df9da98e09d4593772
|
7
|
+
data.tar.gz: 19dbf44e2bb2424e6638efdab5b366b6a06ffdaeb4649cabf5aa6008bc6a4158a5569769f505a040c4dab75b068dac82b64a5cb8c50164818d5f0ee6adaf311e
|
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
@@ -35,9 +35,14 @@ module RuboCop
|
|
35
35
|
end
|
36
36
|
|
37
37
|
paths = packs.empty? ? files : packs.map(&:name).reject { |name| name == ParsePackwerk::ROOT_PACKAGE_NAME }
|
38
|
+
|
39
|
+
cop_names = config.permitted_pack_level_cops.select do |cop_name|
|
40
|
+
YAML.load_file('.rubocop.yml').fetch(cop_name, {})['Enabled']
|
41
|
+
end
|
42
|
+
|
38
43
|
offenses = Private.offenses_for(
|
39
44
|
paths: paths,
|
40
|
-
cop_names:
|
45
|
+
cop_names: cop_names
|
41
46
|
)
|
42
47
|
|
43
48
|
offenses.group_by(&:pack).each do |pack, offenses_for_pack|
|
@@ -51,9 +56,11 @@ module RuboCop
|
|
51
56
|
rubocop_todo = {}
|
52
57
|
end
|
53
58
|
|
54
|
-
offenses_for_pack.each do |
|
55
|
-
|
56
|
-
|
59
|
+
offenses_for_pack.group_by(&:filepath).each do |filepath, offenses_by_filepath|
|
60
|
+
offenses_by_filepath.map(&:cop_name).uniq.each do |cop_name|
|
61
|
+
rubocop_todo[cop_name] ||= { 'Exclude' => [] }
|
62
|
+
rubocop_todo[cop_name]['Exclude'] << filepath
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
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.29
|
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: []
|