rubocop-packs 0.0.23 → 0.0.25

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 906e2ee0ee85e6c02849013bd37034fe6f0f3d8e99ba1597767da463e9f864a4
4
- data.tar.gz: eeec895514ef54dd70846947ecfd37e5577e842938ea93fc220c4d0b086c1247
3
+ metadata.gz: 8bd2b6fe8873467709b0d319443a7cfc13441869c1b93f9ad03120880539da6a
4
+ data.tar.gz: 442ab7d01be0e1d6f0f762d317e2594cad7cae0d12de5ef06949e6668e1b41f4
5
5
  SHA512:
6
- metadata.gz: 481e3a029eaa4e69e0a5f6cf5736356e0f3dd1bb602c7ef24bda112486fb1c1fcfa7e48b40ff2f7bb2eaa38dbf2d3093d2ac4d3603c8d604876efb5213eef53c
7
- data.tar.gz: 9c0901dd0da0d2365e53488e1d12d281f407cb271db4c35013046548a2bfbc80cc25f0f47e4d4bec79ba043fca4fb0d37d331ad431a947e5dfd4131ce8b2779c
6
+ metadata.gz: 1555cca928585f81cd62ec8a055b828a7be4b384b4af89bf4af4e9d61de7eae2ac1b7affe1a258dc26b863aca4b74d714660645c45bc74f2c662e8cf21375a43
7
+ data.tar.gz: 7fa7e16536caa4712fa34508782c0480790b5db7fa2bf9cf4243cbafd5622887142057b1ffbccf941dcf44abfb11fe1077aa1d90b77a75834775b9c8ffe08940
@@ -0,0 +1,19 @@
1
+ # typed: strict
2
+
3
+ module RuboCop
4
+ module Packs
5
+ module Private
6
+ class Offense < T::Struct
7
+ extend T::Sig
8
+
9
+ const :cop_name, String
10
+ const :filepath, String
11
+
12
+ sig { returns(ParsePackwerk::Package) }
13
+ def pack
14
+ ParsePackwerk.package_from_path(filepath)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rubocop/packs/private/configuration'
5
+ require 'rubocop/packs/private/offense'
5
6
 
6
7
  module RuboCop
7
8
  module Packs
@@ -154,6 +155,28 @@ module RuboCop
154
155
  end
155
156
  end
156
157
 
158
+ sig { params(paths: T::Array[String], cop_names: T::Array[String]).returns(T::Array[Offense]) }
159
+ def self.offenses_for(paths:, cop_names:)
160
+ path_arguments = paths.join(' ')
161
+ cop_arguments = cop_names.join(',')
162
+ # 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
163
+ args = [path_arguments, "--only=#{cop_arguments}", '--format=json']
164
+ puts "Executing: bundle exec rubocop #{args.join(' ')}"
165
+ json = JSON.parse(Private.execute_rubocop(args))
166
+ offenses = T.let([], T::Array[Offense])
167
+ json['files'].each do |file_hash|
168
+ filepath = file_hash['path']
169
+ file_hash['offenses'].each do |offense_hash|
170
+ offenses << Offense.new(
171
+ cop_name: offense_hash['cop_name'],
172
+ filepath: filepath
173
+ )
174
+ end
175
+ end
176
+
177
+ offenses
178
+ end
179
+
157
180
  sig { params(block: T.untyped).returns(String) }
158
181
  def self.with_captured_stdout(&block)
159
182
  original_stdout = $stdout # capture previous value of $stdout
data/lib/rubocop/packs.rb CHANGED
@@ -5,6 +5,8 @@ require 'rubocop/packs/private'
5
5
 
6
6
  module RuboCop
7
7
  module Packs
8
+ extend T::Sig
9
+
8
10
  # Pack-level rubocop and rubocop_todo YML files are named differently because they are not integrated
9
11
  # into rubocop in the standard way. For example, we could call these the standard `.rubocop.yml` and
10
12
  # `.rubocop_todo.yml`. However, this introduces a number of path relativity issues (https://docs.rubocop.org/rubocop/configuration.html#path-relativity)
@@ -13,65 +15,35 @@ module RuboCop
13
15
  PACK_LEVEL_RUBOCOP_YML = 'package_rubocop.yml'
14
16
  PACK_LEVEL_RUBOCOP_TODO_YML = 'package_rubocop_todo.yml'
15
17
 
16
- class Error < StandardError; end
17
- extend T::Sig
18
-
19
- # Your code goes here...
20
18
  PROJECT_ROOT = T.let(Pathname.new(__dir__).parent.parent.expand_path.freeze, Pathname)
21
19
  CONFIG_DEFAULT = T.let(PROJECT_ROOT.join('config', 'default.yml').freeze, Pathname)
22
20
  CONFIG = T.let(YAML.safe_load(CONFIG_DEFAULT.read).freeze, T.untyped)
23
21
 
24
22
  private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
25
23
 
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
-
60
24
  #
61
25
  # Ideally, this is API that is available to us via `rubocop` itself.
62
26
  # That is: the ability to preserve the location of `.rubocop_todo.yml` files and associate
63
27
  # exclusions with the closest ancestor `.rubocop_todo.yml`
64
28
  #
65
- sig { params(packs: T::Array[ParsePackwerk::Package]).void }
66
- def self.auto_generate_rubocop_todo(packs:)
67
- offenses = offenses_for(
68
- paths: packs.map(&:name).reject { |name| name == ParsePackwerk::ROOT_PACKAGE_NAME },
29
+ sig { params(packs: T::Array[ParsePackwerk::Package], files: T::Array[String]).void }
30
+ def self.regenerate_todo(packs: [], files: [])
31
+ paths = packs.empty? ? files : packs.map(&:name).reject { |name| name == ParsePackwerk::ROOT_PACKAGE_NAME }
32
+ offenses = Private.offenses_for(
33
+ paths: paths,
69
34
  cop_names: config.permitted_pack_level_cops
70
35
  )
71
36
 
72
37
  offenses.group_by(&:pack).each do |pack, offenses_for_pack|
38
+ next if pack.name == ParsePackwerk::ROOT_PACKAGE_NAME
39
+ next if !pack.directory.join(PACK_LEVEL_RUBOCOP_YML).exist?
40
+
73
41
  rubocop_todo_yml = pack.directory.join(PACK_LEVEL_RUBOCOP_TODO_YML)
74
- if rubocop_todo_yml.exist?
42
+ # If the user is passing in packs, then regenerate from scratch.
43
+ if packs.any? && rubocop_todo_yml.exist?
44
+ rubocop_todo_yml.delete
45
+ rubocop_todo = {}
46
+ elsif rubocop_todo_yml.exist?
75
47
  rubocop_todo = YAML.load_file(rubocop_todo_yml)
76
48
  else
77
49
  rubocop_todo = {}
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.23
4
+ version: 0.0.25
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-18 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -202,6 +202,7 @@ files:
202
202
  - lib/rubocop/packs/inject.rb
203
203
  - lib/rubocop/packs/private.rb
204
204
  - lib/rubocop/packs/private/configuration.rb
205
+ - lib/rubocop/packs/private/offense.rb
205
206
  - lib/rubocop/packwerk_lite.rb
206
207
  homepage: https://github.com/rubyatscale/rubocop-packs
207
208
  licenses: