danger-packwerk 0.1.2 → 0.3.0

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: 6300323ecd2a3738dff019fa9d13477c01c4ef9f0c750780d25c22dea7087e56
4
- data.tar.gz: b4d97e21514bc854ccea2117ca0b63a751a632a2ad4558fe2f5e7e64c382c11e
3
+ metadata.gz: 16735a1a43375efdebd16bc519ffbd0a1ddd5067f1f970ae7efd4d3f8f5f0de4
4
+ data.tar.gz: 294b6e674282672231041190fdfa1127ff1ce5011b9a7ae08dc650757862724d
5
5
  SHA512:
6
- metadata.gz: dbfa1eaea903b7ae2fed28832bb8797c9a594886baf4bad4e951ebf95d6859d19776a8affccb20623189987230a33046eac23ff2eb3a659f454f37c1fc30cdff
7
- data.tar.gz: 0f0e32051b0f970eeac82fa5ba0e677441ffdbc8b9a2e9c1f94d6dcdbea5937df4ccfce69eea946a52ea7af54b7ff646d3d8b1c7356d55c488c1eb35f8224404
6
+ metadata.gz: d6f6e5b5b414a8a411b414f161a4b0f1378ee0e872f3f666398bf345a4246f9910c92b0360f763378339f3603594a87fa0a5c605ddcaee5f93a764d99d954e44
7
+ data.tar.gz: 4b76ae659c1b03d7f6cb7ffba6804f45c14ba64dc62ba79147bd6eda6ceb7930293ad692986baf83fcf5f6235bf3b9eb988aebe9cada3af354e6b1fcddc5d329
@@ -81,10 +81,11 @@ module DangerPackwerk
81
81
  _line, class_name_line_number = deprecated_references_yml_pathname.readlines.each_with_index.find do |line, _index|
82
82
  # If you have a class `::MyClass`, then you can get a false match if another constant in the file
83
83
  # is named `MyOtherClass::MyClassThing`. Therefore we include quotes in our match to ensure that we match
84
- # the constant and only the constant. Right now `packwerk` `deprecated_references.yml` files always use
85
- # double quotes, so we check for that only. If the public API ever changes, this may need to change.
86
- class_name_with_quote_boundaries = "\"#{violation.class_name}\":"
87
- line.include?(class_name_with_quote_boundaries)
84
+ # the constant and only the constant.
85
+ # Right now `packwerk` `deprecated_references.yml` files typically use double quotes, but sometimes folks linters change this to single quotes.
86
+ # To be defensive, we match against either.
87
+ class_name_with_quote_boundaries = /["|']#{violation.class_name}["|']:/
88
+ line.match?(class_name_with_quote_boundaries)
88
89
  end
89
90
 
90
91
  if class_name_line_number.nil?
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'danger'
5
5
  require 'packwerk'
6
+ require 'parse_packwerk'
6
7
  require 'sorbet-runtime'
7
8
  require 'danger-packwerk/packwerk_wrapper'
8
9
 
@@ -23,13 +24,23 @@ module DangerPackwerk
23
24
  DEFAULT_FAIL = false
24
25
  DEFAULT_FAILURE_MESSAGE = 'Packwerk violations were detected! Please resolve them to unblock the build.'
25
26
 
27
+ class CommentGroupingStrategy < ::T::Enum
28
+ enums do
29
+ PerConstantPerLocation = new
30
+ PerConstantPerPack = new
31
+ end
32
+ end
33
+
34
+ PerConstantPerPackGrouping = CommentGroupingStrategy::PerConstantPerPack
35
+
26
36
  sig do
27
37
  params(
28
38
  max_comments: Integer,
29
39
  offenses_formatter: OffensesFormatter,
30
40
  fail_build: T::Boolean,
31
41
  failure_message: String,
32
- on_failure: OnFailure
42
+ on_failure: OnFailure,
43
+ grouping_strategy: CommentGroupingStrategy
33
44
  ).void
34
45
  end
35
46
  def check(
@@ -37,7 +48,8 @@ module DangerPackwerk
37
48
  offenses_formatter: DEFAULT_OFFENSES_FORMATTER,
38
49
  fail_build: DEFAULT_FAIL,
39
50
  failure_message: DEFAULT_FAILURE_MESSAGE,
40
- on_failure: DEFAULT_ON_FAILURE
51
+ on_failure: DEFAULT_ON_FAILURE,
52
+ grouping_strategy: CommentGroupingStrategy::PerConstantPerLocation
41
53
  )
42
54
  # This is important because by default, Danger will leave a concantenated list of all its messages if it can't find a commentable place in the
43
55
  # diff to leave its message. This is an especially bad UX because it will be a huge wall of text not connected to the source of the issue.
@@ -75,11 +87,21 @@ module DangerPackwerk
75
87
  # We group by the constant name, line number, and reference path. Any offenses with these same values should only differ on what type of violation
76
88
  # they are (privacy or dependency). We put privacy and dependency violation messages in the same comment since they would occur on the same line.
77
89
  packwerk_reference_offenses.group_by do |packwerk_reference_offense|
78
- [
79
- packwerk_reference_offense.reference.constant.name,
80
- packwerk_reference_offense.location.line,
81
- packwerk_reference_offense.reference.relative_path
82
- ]
90
+ case grouping_strategy
91
+ when CommentGroupingStrategy::PerConstantPerLocation
92
+ [
93
+ packwerk_reference_offense.reference.constant.name,
94
+ packwerk_reference_offense.location.line,
95
+ packwerk_reference_offense.reference.relative_path
96
+ ]
97
+ when CommentGroupingStrategy::PerConstantPerPack
98
+ [
99
+ packwerk_reference_offense.reference.constant.name,
100
+ ParsePackwerk.package_from_path(packwerk_reference_offense.reference.relative_path)
101
+ ]
102
+ else
103
+ T.absurd(grouping_strategy)
104
+ end
83
105
  end.each do |_group, unique_packwerk_reference_offenses|
84
106
  break if current_comment_count >= max_comments
85
107
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DangerPackwerk
5
- VERSION = '0.1.2'
5
+ VERSION = '0.3.0'
6
6
  end
@@ -0,0 +1,146 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `parse_packwerk` gem.
5
+ # Please instead update this file by running `bin/tapioca gem parse_packwerk`.
6
+
7
+ module ParsePackwerk
8
+ class << self
9
+ sig { returns(T::Array[::ParsePackwerk::Package]) }
10
+ def all; end
11
+
12
+ sig { void }
13
+ def bust_cache!; end
14
+
15
+ sig { params(name: ::String).returns(T.nilable(::ParsePackwerk::Package)) }
16
+ def find(name); end
17
+
18
+ sig { params(file_path: T.any(::Pathname, ::String)).returns(T.nilable(::ParsePackwerk::Package)) }
19
+ def package_from_path(file_path); end
20
+
21
+ sig { params(package: ::ParsePackwerk::Package).void }
22
+ def write_package_yml!(package); end
23
+
24
+ sig { returns(::ParsePackwerk::Configuration) }
25
+ def yml; end
26
+
27
+ private
28
+
29
+ sig { returns(T::Hash[::String, ::ParsePackwerk::Package]) }
30
+ def packages_by_name; end
31
+ end
32
+ end
33
+
34
+ class ParsePackwerk::Configuration < ::T::Struct
35
+ const :exclude, T::Array[::String]
36
+ const :package_paths, T::Array[::String]
37
+
38
+ class << self
39
+ sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) }
40
+ def excludes(config_hash); end
41
+
42
+ sig { returns(::ParsePackwerk::Configuration) }
43
+ def fetch; end
44
+
45
+ def inherited(s); end
46
+
47
+ sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) }
48
+ def package_paths(config_hash); end
49
+ end
50
+ end
51
+
52
+ ParsePackwerk::DEFAULT_EXCLUDE_GLOBS = T.let(T.unsafe(nil), Array)
53
+ ParsePackwerk::DEFAULT_PACKAGE_PATHS = T.let(T.unsafe(nil), Array)
54
+ ParsePackwerk::DEPENDENCIES = T.let(T.unsafe(nil), String)
55
+ ParsePackwerk::DEPRECATED_REFERENCES_YML_NAME = T.let(T.unsafe(nil), String)
56
+
57
+ class ParsePackwerk::DeprecatedReferences < ::T::Struct
58
+ const :pathname, ::Pathname
59
+ const :violations, T::Array[::ParsePackwerk::Violation]
60
+
61
+ class << self
62
+ sig { params(package: ::ParsePackwerk::Package).returns(::ParsePackwerk::DeprecatedReferences) }
63
+ def for(package); end
64
+
65
+ sig { params(pathname: ::Pathname).returns(::ParsePackwerk::DeprecatedReferences) }
66
+ def from(pathname); end
67
+
68
+ def inherited(s); end
69
+ end
70
+ end
71
+
72
+ ParsePackwerk::ENFORCE_DEPENDENCIES = T.let(T.unsafe(nil), String)
73
+ ParsePackwerk::ENFORCE_PRIVACY = T.let(T.unsafe(nil), String)
74
+ ParsePackwerk::METADATA = T.let(T.unsafe(nil), String)
75
+ ParsePackwerk::MetadataYmlType = T.type_alias { T::Hash[T.untyped, T.untyped] }
76
+
77
+ class ParsePackwerk::MissingConfiguration < ::StandardError
78
+ sig { params(packwerk_file_name: ::Pathname).void }
79
+ def initialize(packwerk_file_name); end
80
+ end
81
+
82
+ ParsePackwerk::PACKAGE_YML_NAME = T.let(T.unsafe(nil), String)
83
+ ParsePackwerk::PACKWERK_YML_NAME = T.let(T.unsafe(nil), String)
84
+
85
+ class ParsePackwerk::Package < ::T::Struct
86
+ const :dependencies, T::Array[::String]
87
+ const :enforce_dependencies, T::Boolean
88
+ const :enforce_privacy, T::Boolean
89
+ const :metadata, T::Hash[T.untyped, T.untyped]
90
+ const :name, ::String
91
+
92
+ sig { returns(::Pathname) }
93
+ def directory; end
94
+
95
+ sig { returns(T::Boolean) }
96
+ def enforces_dependencies?; end
97
+
98
+ sig { returns(T::Boolean) }
99
+ def enforces_privacy?; end
100
+
101
+ sig { returns(::Pathname) }
102
+ def yml; end
103
+
104
+ class << self
105
+ sig { params(pathname: ::Pathname).returns(::ParsePackwerk::Package) }
106
+ def from(pathname); end
107
+
108
+ def inherited(s); end
109
+ end
110
+ end
111
+
112
+ class ParsePackwerk::PackageSet
113
+ class << self
114
+ sig do
115
+ params(
116
+ package_pathspec: T::Array[::String],
117
+ exclude_pathspec: T::Array[::String]
118
+ ).returns(T::Array[::ParsePackwerk::Package])
119
+ end
120
+ def from(package_pathspec:, exclude_pathspec:); end
121
+
122
+ private
123
+
124
+ sig { params(globs: T::Array[::String], path: ::Pathname).returns(T::Boolean) }
125
+ def exclude_path?(globs, path); end
126
+ end
127
+ end
128
+
129
+ ParsePackwerk::ROOT_PACKAGE_NAME = T.let(T.unsafe(nil), String)
130
+
131
+ class ParsePackwerk::Violation < ::T::Struct
132
+ const :class_name, ::String
133
+ const :files, T::Array[::String]
134
+ const :to_package_name, ::String
135
+ const :type, ::String
136
+
137
+ sig { returns(T::Boolean) }
138
+ def dependency?; end
139
+
140
+ sig { returns(T::Boolean) }
141
+ def privacy?; end
142
+
143
+ class << self
144
+ def inherited(s); end
145
+ end
146
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.0
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-04-20 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parse_packwerk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sorbet-runtime
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -186,15 +200,16 @@ files:
186
200
  - sorbet/config
187
201
  - sorbet/rbi/gems/danger@8.5.0.rbi
188
202
  - sorbet/rbi/gems/packwerk@1.3.2.rbi
203
+ - sorbet/rbi/gems/parse_packwerk@0.12.0.rbi
189
204
  - sorbet/rbi/todo.rbi
190
205
  - sorbet/tapioca/require.rb
191
- homepage: https://github.com/bigrails/danger-packwerk
206
+ homepage: https://github.com/rubyatscale/danger-packwerk
192
207
  licenses:
193
208
  - MIT
194
209
  metadata:
195
- homepage_uri: https://github.com/bigrails/danger-packwerk
196
- source_code_uri: https://github.com/bigrails/danger-packwerk
197
- changelog_uri: https://github.com/bigrails/danger-packwerk/releases
210
+ homepage_uri: https://github.com/rubyatscale/danger-packwerk
211
+ source_code_uri: https://github.com/rubyatscale/danger-packwerk
212
+ changelog_uri: https://github.com/rubyatscale/danger-packwerk/releases
198
213
  allowed_push_host: https://rubygems.org
199
214
  post_install_message:
200
215
  rdoc_options: []