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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e25f6b7faaf75d2877d830e784211d96ba5d6cb29b442c959552e1de28c5adbd
4
- data.tar.gz: eff6ee7fe761edb2bb142f4cf543557b4d17a160990dccc364972bd87208ccd8
3
+ metadata.gz: e4888c0b36e59d1da1aaa62d1390da897fce811909d99c5e1189bca0efd36050
4
+ data.tar.gz: 7d1957e8c598a6acbcfa3b0b8f49578dcb3424d01c20178c2045459654a2478f
5
5
  SHA512:
6
- metadata.gz: cd2ffeb81ef84b49be4ae73216d3318f45d1bf9ad70bcc77061509bbae0f848a1ff0a87ba12082c6091f32b00fef0a1a303d360dba7d07a8c2de60e255186888
7
- data.tar.gz: 52163c30ba8037b43c0aaa1659bf42723e4dcd0b570b5b6e7d0f2e72e526a2e3fab6456ed3c9e934bad894b3aed9b9e3103b908dbe9d012be2081c5d42312022
6
+ metadata.gz: b55558140df2b0d0e68f64668a94e814c30a6ac42b144d0dc7fbc7118bdf982fb87b45085592ca219946ae6a2df73bb22562a83ae888fb021343ec0cea7c685c
7
+ data.tar.gz: fa54dc58358e0f32104c2acfa0536ff6239430c287a75e5ad0a346ae9979360f59a67037a34599e98a1df525cbe6c31c7350af95b6c33dba1dcdacb02cbdfe88
data/config/default.yml CHANGED
@@ -5,6 +5,7 @@ Packs/ClassMethodsAsPublicApis:
5
5
  - T::Struct
6
6
  - Struct
7
7
  - OpenStruct
8
+ AcceptableMixins: []
8
9
  FailureMode: default
9
10
 
10
11
  Packs/RootNamespaceIsPackName:
@@ -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 |offense|
55
- rubocop_todo[offense.cop_name] ||= { 'Exclude' => [] }
56
- rubocop_todo[offense.cop_name]['Exclude'] << offense.filepath
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.27
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-19 00:00:00.000000000 Z
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: Fill this out!
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: Fill this out!
233
+ summary: A collection of Rubocop rules for gradually modularizing a ruby codebase
234
234
  test_files: []