From 4a04763c53d160d29cd6acbdd30f96a02788ca55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claud=C3=A9ric=20Demers?= Date: Thu, 12 Nov 2026 11:19:04 -0500 Subject: [PATCH] Add Checker::ignore The files a run leaves out, as in `.theme-check.yml`'s `ignore`. agent-server checks the whole theme except `_drafts` folders, which is `.ignore(["_drafts/**"])`. Co-Authored-By: Claude Opus 5.5 --- .changeset/theme-check-rs-ignore.md | 5 ++++ crates/theme-check/README.md | 6 ++--- crates/theme-check/src/lib.rs | 36 +++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 .changeset/theme-check-rs-ignore.md diff --git a/.changeset/theme-check-rs-ignore.md b/.changeset/theme-check-rs-ignore.md new file mode 100644 index 000000000..68811d869 --- /dev/null +++ b/.changeset/theme-check-rs-ignore.md @@ -0,0 +1,5 @@ +--- +'theme-check-rs': patch +--- + +Add `Checker::ignore`, the files a run leaves out, as in `.theme-check.yml`'s `ignore` diff --git a/crates/theme-check/README.md b/crates/theme-check/README.md index 1520d435d..1139abfa6 100644 --- a/crates/theme-check/README.md +++ b/crates/theme-check/README.md @@ -45,9 +45,9 @@ let report = Checker::new() .run(&fs, "/theme")?; ``` -It also takes the docs, schemas and check settings. Without them, it runs the recommended checks, -with the docs and schemas downloaded from theme-liquid-docs. Checks of your own walk the AST, as -in the [crate docs](https://docs.rs/theme-check). +It also takes the docs, schemas, check settings and files to ignore. Without them, it runs the +recommended checks, with the docs and schemas downloaded from theme-liquid-docs. Checks of your +own walk the AST, as in the [crate docs](https://docs.rs/theme-check). ## The CLI diff --git a/crates/theme-check/src/lib.rs b/crates/theme-check/src/lib.rs index 9935baec5..751508c81 100644 --- a/crates/theme-check/src/lib.rs +++ b/crates/theme-check/src/lib.rs @@ -279,6 +279,7 @@ pub struct Checker { schemas: Option>, checks: Option>, settings: Map, + ignore: Vec, downloaded: docs::ThemeLiquidDocsManager, } @@ -295,6 +296,7 @@ impl Checker { schemas: None, checks: None, settings: Map::new(), + ignore: Vec::new(), downloaded: docs::ThemeLiquidDocsManager::new(Box::new(|_| {})), } } @@ -326,15 +328,40 @@ impl Checker { self } - /// Checks the theme at `root` in `fs`: its `.liquid` and `.json` files, but not dot files or - /// `node_modules`, which the recommended config ignores. It fails if `root` or a directory below - /// it can't be listed, or a file can't be read. + /// The files to leave out, as in `.theme-check.yml`'s `ignore`: `_drafts/**` leaves out every + /// `_drafts` folder, and a pattern that starts with `/` is from the root. They aren't read or + /// checked, so lookups like block schemas don't find them. + /// + /// ``` + /// # use theme_check::{Checker, Docs, MemoryFs}; + /// let fs: MemoryFs = [ + /// ("/theme/blocks/a.liquid", "{{ 'x' | nope }}"), + /// ("/theme/blocks/_drafts/a.liquid", "{{ 'x' | nope }}"), + /// ] + /// .into_iter() + /// .collect(); + /// let report = Checker::new() + /// # .docs(Docs::from_json("[]", "[]", "[]", "{}")?) + /// # .schemas(Vec::new()) + /// .ignore(["_drafts/**"]) + /// .run(&fs, "/theme")?; + /// assert_eq!(report.files, [std::path::PathBuf::from("/theme/blocks/a.liquid")]); + /// # Ok::<(), theme_check::Error>(()) + /// ``` + pub fn ignore(mut self, patterns: impl IntoIterator>) -> Self { + self.ignore = patterns.into_iter().map(Into::into).collect(); + self + } + + /// Checks the theme at `root` in `fs`: its `.liquid` and `.json` files, but not dot files, + /// `node_modules`, which the recommended config ignores, or [`Self::ignore`]'s. It fails if + /// `root` or a directory below it can't be listed, or a file can't be read. pub fn run(&self, fs: &dyn FileSystem, root: impl AsRef) -> Result { let root = resolve(root.as_ref()); let root_uri = path::file_uri(&root); let settings = node::config::resolve_check_settings(self.settings.clone())?; let recommended = node::config::recommended_with(settings.clone())?; - let config = match &self.checks { + let mut config = match &self.checks { None => recommended, Some(checks) => { let enabled = |c: &&Check| { @@ -350,6 +377,7 @@ impl Checker { ) } }; + config.ignore.extend(self.ignore.iter().cloned()); let mut paths = Vec::new(); fs::theme_files(fs, Path::new(&root), &mut paths).map_err(|e| Error(e.to_string()))?;