Skip to content

Commit b143008

Browse files
authored
Allow violations to be set on a package (#30)
* Allow violations to be set on a package * Remove the need for oddly named `stored_violations`
1 parent df5013d commit b143008

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

lib/parse_packwerk/package.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Package < T::Struct
1111
const :metadata, MetadataYmlType
1212
const :dependencies, T::Array[String]
1313
const :config, T::Hash[T.untyped, T.untyped]
14+
const :violations, T.nilable(T::Array[Violation])
1415

1516
sig { params(pathname: Pathname).returns(Package) }
1617
def self.from(pathname)
@@ -29,17 +30,23 @@ def self.from(pathname)
2930
metadata: package_loaded_yml[METADATA] || {},
3031
dependencies: package_loaded_yml[DEPENDENCIES] || [],
3132
config: package_loaded_yml,
33+
violations: PackageTodo.from(PackageTodo.yml(directory(package_name))).violations
3234
)
3335
end
3436

37+
sig { params(package_name: String).returns(::Pathname) }
38+
def self.directory(package_name)
39+
Pathname.new(package_name).cleanpath
40+
end
41+
3542
sig { returns(Pathname) }
3643
def yml
3744
Pathname.new(name).join(PACKAGE_YML_NAME).cleanpath
3845
end
3946

4047
sig { returns(Pathname) }
4148
def directory
42-
Pathname.new(name).cleanpath
49+
self.class.directory(self.name)
4350
end
4451

4552
sig { returns(Pathname) }
@@ -56,10 +63,5 @@ def enforces_dependencies?
5663
def enforces_privacy?
5764
enforce_privacy
5865
end
59-
60-
sig { returns(T::Array[Violation]) }
61-
def violations
62-
PackageTodo.for(self).violations
63-
end
6466
end
6567
end

lib/parse_packwerk/package_todo.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class PackageTodo < T::Struct
99

1010
sig { params(package: Package).returns(PackageTodo) }
1111
def self.for(package)
12-
package_todo_yml_pathname = package.directory.join(PACKAGE_TODO_YML_NAME)
13-
PackageTodo.from(package_todo_yml_pathname)
12+
PackageTodo.from(self.yml(package.directory))
1413
end
1514

1615
sig { params(pathname: Pathname).returns(PackageTodo) }
@@ -42,5 +41,10 @@ def self.from(pathname)
4241
)
4342
end
4443
end
44+
45+
sig { params(dirname: Pathname).returns(Pathname) }
46+
def self.yml(dirname)
47+
dirname.join(PACKAGE_TODO_YML_NAME).cleanpath
48+
end
4549
end
4650
end

0 commit comments

Comments
 (0)