rubocop-packs 0.0.16 → 0.0.18

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: 82853530c4d01d7eb8f804f48eeb8b9558eb5d0fb006d5841c2c22f6265d5a38
4
- data.tar.gz: 55fdebf202b61a5c09b6f2e125fe2821c756f0c7aa7f4b03e383750992c62764
3
+ metadata.gz: ad176fde4b980a18810e2563daf9c097bf4569d83a713e7d0efab4a7118e32c8
4
+ data.tar.gz: cd71dc7323afd1bf9c4dea9818cc6e177cacce44e94337c0746c6db01bb69a1b
5
5
  SHA512:
6
- metadata.gz: 350a4b8cff981e078f6c87e3fece33ba40c678be475f305702398033b3856817ac7eb60e98268f8f10e58b7098f05bb622f77089cca1d20ce64d1faba37db663
7
- data.tar.gz: bbc768b93c9f41cc886cdb8b1514d41cf8688a622ec4d6d4573eff06ef347eaf602751afc5ca6de663ff0564c33e263778b2eeae3933142b5831027518e8c776
6
+ metadata.gz: b19478228beb486ac967de7479048a6f01ffd0ba2cb608ce9a5e6c5ad6966f2431fb5df38636cdc079e7e89e8e574ddd126f5be28d307209430b9e3389596ec5
7
+ data.tar.gz: a5b7ea366640f39b2631b02d2d8fe59997c1449e57e6b9c3f7da7a58acc4fe471627c9bdf55734ef085e4b6de5bd562979833793e121a4532c3c52fee29d0b18
data/README.md CHANGED
@@ -36,7 +36,7 @@ All cops are located under [`lib/rubocop/cop/packs`](lib/rubocop/cop/packs), and
36
36
  In your `.rubocop.yml`, you may treat the Packs cops just like any other cop. For example:
37
37
 
38
38
  ```yaml
39
- Packs/NamespaceConvention:
39
+ Packs/RootNamespaceIsPackName:
40
40
  Exclude:
41
41
  - lib/example.rb
42
42
  ```
@@ -52,9 +52,9 @@ To add a per-pack `.rubocop.yml`, you just need to create a `packs/your_pack/.ru
52
52
  inherit_from: '../../.rubocop.yml'
53
53
  ```
54
54
 
55
- Note though that inherited paths are relative to your pack-level `.rubocop.yml`. To avoid that, you can rename your `.rubocop.yml` to `.inherited_rubocop.yml`, set `.rubocop.yml` to:
55
+ Note though that inherited paths are relative to your pack-level `.rubocop.yml`. To avoid that, you can rename your `.rubocop.yml` to `.base_rubocop.yml`, set `.rubocop.yml` to:
56
56
  ```
57
- inherit_from: '.inherited_rubocop.yml'
57
+ inherit_from: '.base_rubocop.yml'
58
58
  ```
59
59
  And then similarly change the `inherit_from` in `packs/your_pack/.rubocop.yml`.
60
60
 
@@ -70,8 +70,8 @@ To use per-pack `.rubocop.yml` and `.rubocop_todo.yml` files, you need to config
70
70
  ```ruby
71
71
  # config/rubocop_packs.rb
72
72
  RuboCop::Packs.configure do |config|
73
- config.permitted_pack_level_cops = ['Packs/NamespaceConvention']
74
- config.required_pack_level_cops = ['Packs/NamespaceConvention']
73
+ config.permitted_pack_level_cops = ['Packs/RootNamespaceIsPackName']
74
+ config.required_pack_level_cops = ['Packs/RootNamespaceIsPackName']
75
75
  end
76
76
  ```
77
77
 
data/config/default.yml CHANGED
@@ -8,13 +8,13 @@ Packs/ClassMethodsAsPublicApis:
8
8
  - Struct
9
9
  - OpenStruct
10
10
 
11
- Packs/NamespaceConvention:
11
+ Packs/RootNamespaceIsPackName:
12
12
  Enabled: true
13
13
 
14
- Packs/TypedPublicApi:
14
+ Packs/TypedPublicApis:
15
15
  Enabled: true
16
16
 
17
- Packs/RequireDocumentedPublicApis:
17
+ Packs/DocumentedPublicApis:
18
18
  Enabled: true
19
19
 
20
20
  PackwerkLite/Privacy:
@@ -55,7 +55,7 @@ module RuboCop
55
55
  add_offense(
56
56
  node.source_range,
57
57
  message: format(
58
- 'Top-level files in the public/ folder may only define class methods.'
58
+ "Public API method must be a class method (e.g. `self.#{node.method_name}(...)`)"
59
59
  )
60
60
  )
61
61
  end
@@ -21,7 +21,7 @@ module RuboCop
21
21
  # def bar; end
22
22
  # end
23
23
  #
24
- class RequireDocumentedPublicApis < Style::DocumentationMethod
24
+ class DocumentedPublicApis < Style::DocumentationMethod
25
25
  # This cop does two things:
26
26
  # 1) It only activates for things in the public folder
27
27
  # 2) It allows `Style/DocumentationMethod` to work with sigs as expected.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Packs
6
- class NamespaceConvention < Base
6
+ class RootNamespaceIsPackName < Base
7
7
  #
8
8
  # This is a private class that represents API that we would prefer to be available somehow in Zeitwerk.
9
9
  # However, the boundaries between systems (packwerk/zeitwerk, rubocop/zeitwerk) are poor in this class, so
@@ -2,7 +2,7 @@
2
2
 
3
3
  # For String#camelize
4
4
  require 'active_support/core_ext/string/inflections'
5
- require 'rubocop/cop/packs/namespace_convention/desired_zeitwerk_api'
5
+ require 'rubocop/cop/packs/root_namespace_is_pack_name/desired_zeitwerk_api'
6
6
 
7
7
  module RuboCop
8
8
  module Cop
@@ -23,7 +23,7 @@ module RuboCop
23
23
  # # packs/foo/app/services/foo/blah/bar.rb
24
24
  # class Foo::Blah::Bar; end
25
25
  #
26
- class NamespaceConvention < Base
26
+ class RootNamespaceIsPackName < Base
27
27
  extend T::Sig
28
28
 
29
29
  include RangeHelp
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # # typed: strict
20
20
  # module Foo; end
21
21
  #
22
- class TypedPublicApi < Sorbet::StrictSigil
22
+ class TypedPublicApis < Sorbet::StrictSigil
23
23
  #
24
24
  # This inherits from `Sorbet::StrictSigil` and doesn't change any behavior of it.
25
25
  # The only reason we do this is so that configuration for this cop can live under a different cop namespace.
data/lib/rubocop/packs.rb CHANGED
@@ -64,6 +64,31 @@ module RuboCop
64
64
  end
65
65
  end
66
66
 
67
+ #
68
+ # Ideally, this is API that is available to us via `rubocop` itself.
69
+ # That is: the ability to preserve the location of `.rubocop_todo.yml` files and associate
70
+ # exclusions with the closest ancestor `.rubocop_todo.yml`
71
+ #
72
+ sig { params(packs: T::Array[ParsePackwerk::Package]).void }
73
+ def self.set_default_rubocop_yml(packs:)
74
+ packs.each do |pack|
75
+ rubocop_yml = Pathname.new(pack.directory.join('.rubocop.yml'))
76
+ rubocop_yml_hash = {}
77
+ rubocop_yml_hash['inherit_from'] = '../../.base_rubocop.yml'
78
+ config.required_pack_level_cops.each do |cop|
79
+ rubocop_yml_hash[cop] = { 'Enabled' => true }
80
+ end
81
+
82
+ formatted_yml = YAML.dump(rubocop_yml_hash).
83
+ # Remove the `---` header at the top of the file
84
+ gsub("---\n", '').
85
+ # Find lines of the form \nCopDepartment/CopName: and add a new line before it.
86
+ gsub(%r{^(\w+/\w+:)}, "\n\\1")
87
+
88
+ rubocop_yml.write(formatted_yml)
89
+ end
90
+ end
91
+
67
92
  sig { params(root_pathname: String).returns(String) }
68
93
  # It would be great if rubocop (upstream) could take in a glob for `inherit_from`, which
69
94
  # would allow us to delete this method and this additional complexity.
data/lib/rubocop-packs.rb CHANGED
@@ -8,9 +8,9 @@ require_relative 'rubocop/packs'
8
8
  require_relative 'rubocop/packs/inject'
9
9
  require_relative 'rubocop/packwerk_lite'
10
10
 
11
- require 'rubocop/cop/packs/namespace_convention'
12
- require 'rubocop/cop/packs/typed_public_api'
11
+ require 'rubocop/cop/packs/root_namespace_is_pack_name'
12
+ require 'rubocop/cop/packs/typed_public_apis'
13
13
  require 'rubocop/cop/packs/class_methods_as_public_apis'
14
- require 'rubocop/cop/packs/require_documented_public_apis'
14
+ require 'rubocop/cop/packs/documented_public_apis'
15
15
 
16
16
  RuboCop::Packs::Inject.defaults!
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.16
4
+ version: 0.0.18
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-08 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -190,10 +190,10 @@ files:
190
190
  - config/pack_config.yml
191
191
  - lib/rubocop-packs.rb
192
192
  - lib/rubocop/cop/packs/class_methods_as_public_apis.rb
193
- - lib/rubocop/cop/packs/namespace_convention.rb
194
- - lib/rubocop/cop/packs/namespace_convention/desired_zeitwerk_api.rb
195
- - lib/rubocop/cop/packs/require_documented_public_apis.rb
196
- - lib/rubocop/cop/packs/typed_public_api.rb
193
+ - lib/rubocop/cop/packs/documented_public_apis.rb
194
+ - lib/rubocop/cop/packs/root_namespace_is_pack_name.rb
195
+ - lib/rubocop/cop/packs/root_namespace_is_pack_name/desired_zeitwerk_api.rb
196
+ - lib/rubocop/cop/packs/typed_public_apis.rb
197
197
  - lib/rubocop/cop/packwerk_lite/constant_resolver.rb
198
198
  - lib/rubocop/cop/packwerk_lite/dependency_checker.rb
199
199
  - lib/rubocop/cop/packwerk_lite/privacy_checker.rb