diff --git a/Cargo.lock b/Cargo.lock index a35fac2..2a1b6c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4006,7 +4006,7 @@ dependencies = [ [[package]] name = "typst-package-check" -version = "0.6.0" +version = "0.7.0" dependencies = [ "casbab", "clap", diff --git a/src/check/files.rs b/src/check/files.rs index dca4878..cb7827c 100644 --- a/src/check/files.rs +++ b/src/check/files.rs @@ -60,7 +60,7 @@ pub fn check( warn_ignored_files(diags, file_path, excluded, ignored); forbid_font_files(diags, file_path); exclude_large_files(diags, file_path, excluded, metadata.len()); - exclude_examples_and_tests(diags, file_path, excluded); + exclude_examples_and_tests(diags, manifest, file_path, excluded); link_manuals(diags, readme, file_path, excluded); } } @@ -167,8 +167,19 @@ fn exclude_large_files( ) } -fn exclude_examples_and_tests(diags: &mut Diagnostics, path: PackagePath<&Path>, excluded: bool) { - if excluded { +fn exclude_examples_and_tests( + diags: &mut Diagnostics, + manifest: &Manifest, + path: PackagePath<&Path>, + excluded: bool, +) { + // Don't exclude template files, even if they contain "example" or "test" in their name. + let in_template_dir = || { + manifest + .template_path() + .is_some_and(|dir| path.full().starts_with(dir.full())) + }; + if excluded || in_template_dir() { return; } diff --git a/src/check/manifest.rs b/src/check/manifest.rs index 0ab0b71..0bb3c16 100644 --- a/src/check/manifest.rs +++ b/src/check/manifest.rs @@ -32,6 +32,12 @@ pub struct Manifest { pub template: Option>, } +impl Manifest { + pub fn template_path(&self) -> Option<&PackagePath> { + Some(&self.template.as_ref()?.path.as_ref()?.val) + } +} + #[derive(Debug, Clone)] pub struct Package { pub entrypoint: Spanned, diff --git a/tests/local/sixth/0.1.0/LICENSE b/tests/local/sixth/0.1.0/LICENSE new file mode 100644 index 0000000..9f1362e --- /dev/null +++ b/tests/local/sixth/0.1.0/LICENSE @@ -0,0 +1 @@ +totally an MIT license diff --git a/tests/local/sixth/0.1.0/README.md b/tests/local/sixth/0.1.0/README.md new file mode 100644 index 0000000..ea52c34 --- /dev/null +++ b/tests/local/sixth/0.1.0/README.md @@ -0,0 +1,3 @@ +# sixth + +:) diff --git a/tests/local/sixth/0.1.0/lib.typ b/tests/local/sixth/0.1.0/lib.typ new file mode 100644 index 0000000..e69de29 diff --git a/tests/local/sixth/0.1.0/template/example.typ b/tests/local/sixth/0.1.0/template/example.typ new file mode 100644 index 0000000..e69de29 diff --git a/tests/local/sixth/0.1.0/typst.toml b/tests/local/sixth/0.1.0/typst.toml new file mode 100644 index 0000000..d05f699 --- /dev/null +++ b/tests/local/sixth/0.1.0/typst.toml @@ -0,0 +1,12 @@ +[package] +name = "sixth" +version = "0.1.0" +description = "Useless package" +authors = ["Some Person"] +entrypoint = "lib.typ" +license = "MIT" + +[template] +thumbnail = "missing.png" +path = "template" +entrypoint = "example.typ" diff --git a/tests/ref/local+sixth+0.1.0.txt b/tests/ref/local+sixth+0.1.0.txt new file mode 100644 index 0000000..fc6f96b --- /dev/null +++ b/tests/ref/local+sixth+0.1.0.txt @@ -0,0 +1,6 @@ +error[manifest/template/thumbnail/not-found]: This file does not exist. + ┌─ typst.toml:10:12 + │ +10 │ thumbnail = "missing.png" + │ ^^^^^^^^^^^^^ +