@@ -14,33 +14,30 @@ import data.regal.util
1414notices contains result.notice (rego.metadata.chain ()) if " no_filename" in config.capabilities.special
1515
1616report contains violation if {
17+ parts := split (input .regal.file.abs, input .regal.environment.path_separator)
18+ file_path_values := array.slice (parts, 0 , count (parts) - 1 )
19+
1720 # get the last n components from file path, where n == count(_pkg_path_values)
1821 file_path_length_matched := array.slice (
19- _file_path_values ,
20- count (_file_path_values ) - count (_pkg_path_values),
21- count (_file_path_values ),
22+ file_path_values ,
23+ count (file_path_values ) - count (_pkg_path_values),
24+ count (file_path_values ),
2225 )
2326
2427 file_path_length_matched != _pkg_path_values
2528
26- violation := result.fail (
27- rego.metadata.chain (),
28- # skip the "data" part of the path, as it has no location
29- result.ranged_from_ref (util.rest (input [" package" ].path)),
30- )
29+ # skip the "data" part of the path, as it has no location
30+ violation := result.fail (rego.metadata.chain (), result.ranged_from_ref (util.rest (input [" package" ].path)))
3131}
3232
33- _pkg_path_values := ast.package_path if not config.rules.idiomatic[" directory-package-mismatch" ][" exclude-test-suffix" ]
34-
3533_pkg_path_values := without_test_suffix if {
3634 config.rules.idiomatic[" directory-package-mismatch" ][" exclude-test-suffix" ] == true
3735
36+ name := regal.last (ast.package_path)
37+ endswith (name, " _test" )
38+
3839 without_test_suffix := array.concat (
3940 array.slice (ast.package_path, 0 , count (ast.package_path) - 1 ),
40- [trim_suffix (regal. last (ast.package_path) , " _test" )],
41+ [trim_suffix (name , " _test" )],
4142 )
42- }
43-
44- _file_path_values := array.slice (parts, 0 , count (parts) - 1 ) if {
45- parts := split (input .regal.file.abs, input .regal.environment.path_separator)
46- }
43+ } else := ast.package_path
0 commit comments