rubocop-packs 0.0.22 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/packs/private.rb +17 -0
- data/lib/rubocop/packs.rb +46 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86c7a0f38ce8943c88c771c4516e63885c5b400ca9c9084b88bed7573b157afd
|
4
|
+
data.tar.gz: b34b6c97ce2c969aaee9269f383b98a200103871f5ffc3936ae19c0ea7b742f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a8d92eec135704409fb4eb76fe25dc5118c197e9c0256546958758734dff552c77bbcda5495d8eb788bde648c1335734823e34d5bfb5f283c9fa6a6e9207024
|
7
|
+
data.tar.gz: 5a56441cdf2b6dd335a39db3defd87df4360f388431ee1ef7d883bb50c712f156515fdc0556b2ce05c82be4312bffbc4ca69a85825e56d49880f0cd60bfd5e5e
|
@@ -146,6 +146,23 @@ module RuboCop
|
|
146
146
|
|
147
147
|
errors
|
148
148
|
end
|
149
|
+
|
150
|
+
sig { params(args: T.untyped).returns(String) }
|
151
|
+
def self.execute_rubocop(args)
|
152
|
+
with_captured_stdout do
|
153
|
+
RuboCop::CLI.new.run(args)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
sig { params(block: T.untyped).returns(String) }
|
158
|
+
def self.with_captured_stdout(&block)
|
159
|
+
original_stdout = $stdout # capture previous value of $stdout
|
160
|
+
$stdout = StringIO.new # assign a string buffer to $stdout
|
161
|
+
yield # perform the body of the user code
|
162
|
+
$stdout.string # return the contents of the string buffer
|
163
|
+
ensure
|
164
|
+
$stdout = original_stdout # restore $stdout to its previous value
|
165
|
+
end
|
149
166
|
end
|
150
167
|
|
151
168
|
private_constant :Private
|
data/lib/rubocop/packs.rb
CHANGED
@@ -23,47 +23,60 @@ module RuboCop
|
|
23
23
|
|
24
24
|
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
25
25
|
|
26
|
+
class Offense < T::Struct
|
27
|
+
extend T::Sig
|
28
|
+
|
29
|
+
const :cop_name, String
|
30
|
+
const :filepath, String
|
31
|
+
|
32
|
+
sig { returns(ParsePackwerk::Package) }
|
33
|
+
def pack
|
34
|
+
ParsePackwerk.package_from_path(filepath)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
sig { params(paths: T::Array[String], cop_names: T::Array[String]).returns(T::Array[Offense]) }
|
39
|
+
def self.offenses_for(paths:, cop_names:)
|
40
|
+
path_arguments = paths.join(' ')
|
41
|
+
cop_arguments = cop_names.join(',')
|
42
|
+
# I think we can potentially use `RuboCop::CLI.new(args)` for this to avoid shelling out and starting another process that needs to reload the bundle
|
43
|
+
args = [path_arguments, "--only=#{cop_arguments}", '--format=json']
|
44
|
+
puts "Executing: bundle exec rubocop #{args.join(' ')}"
|
45
|
+
json = JSON.parse(Private.execute_rubocop(args))
|
46
|
+
offenses = T.let([], T::Array[Offense])
|
47
|
+
json['files'].each do |file_hash|
|
48
|
+
filepath = file_hash['path']
|
49
|
+
file_hash['offenses'].each do |offense_hash|
|
50
|
+
offenses << Offense.new(
|
51
|
+
cop_name: offense_hash['cop_name'],
|
52
|
+
filepath: filepath
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
offenses
|
58
|
+
end
|
59
|
+
|
26
60
|
#
|
27
61
|
# Ideally, this is API that is available to us via `rubocop` itself.
|
28
62
|
# That is: the ability to preserve the location of `.rubocop_todo.yml` files and associate
|
29
63
|
# exclusions with the closest ancestor `.rubocop_todo.yml`
|
30
64
|
#
|
31
65
|
sig { params(packs: T::Array[ParsePackwerk::Package]).void }
|
32
|
-
def self.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
json = JSON.parse(`#{command}`)
|
38
|
-
new_rubocop_todo_exclusions = {}
|
39
|
-
json['files'].each do |file_hash|
|
40
|
-
filepath = file_hash['path']
|
41
|
-
pack = ParsePackwerk.package_from_path(filepath)
|
42
|
-
next if pack.name == ParsePackwerk::ROOT_PACKAGE_NAME
|
66
|
+
def self.regenerate_todo(packs:)
|
67
|
+
offenses = offenses_for(
|
68
|
+
paths: packs.map(&:name).reject { |name| name == ParsePackwerk::ROOT_PACKAGE_NAME },
|
69
|
+
cop_names: config.permitted_pack_level_cops
|
70
|
+
)
|
43
71
|
|
44
|
-
|
45
|
-
cop_name = offense_hash['cop_name']
|
46
|
-
next unless config.permitted_pack_level_cops.include?(cop_name)
|
47
|
-
|
48
|
-
new_rubocop_todo_exclusions[pack.name] ||= {}
|
49
|
-
new_rubocop_todo_exclusions[pack.name][filepath] ||= []
|
50
|
-
new_rubocop_todo_exclusions[pack.name][filepath] << cop_name
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
new_rubocop_todo_exclusions.each do |pack_name, file_hash|
|
55
|
-
pack = T.must(ParsePackwerk.find(pack_name))
|
72
|
+
offenses.group_by(&:pack).each do |pack, offenses_for_pack|
|
56
73
|
rubocop_todo_yml = pack.directory.join(PACK_LEVEL_RUBOCOP_TODO_YML)
|
57
|
-
if rubocop_todo_yml.exist?
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
failing_cops.each do |failing_cop|
|
64
|
-
rubocop_todo[failing_cop] ||= { 'Exclude' => [] }
|
65
|
-
rubocop_todo[failing_cop]['Exclude'] << file
|
66
|
-
end
|
74
|
+
rubocop_todo_yml.delete if rubocop_todo_yml.exist?
|
75
|
+
rubocop_todo = {}
|
76
|
+
|
77
|
+
offenses_for_pack.each do |offense|
|
78
|
+
rubocop_todo[offense.cop_name] ||= { 'Exclude' => [] }
|
79
|
+
rubocop_todo[offense.cop_name]['Exclude'] << offense.filepath
|
67
80
|
end
|
68
81
|
|
69
82
|
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.24
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|