Skip to content

Commit

Permalink
feat: Add config option to ignore files based on Unix shell-style wil…
Browse files Browse the repository at this point in the history
…dcard pattern matching

Also updates `skip_files` to treat file paths as OS-agnostic.

Issue pawamoy#21: pawamoy#21
Issue pawamoy#20: pawamoy#20
  • Loading branch information
nfelt14 committed Apr 30, 2024
1 parent bd529b5 commit e5b8c80
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# python
*.egg-info/
*.py[cod]
pdm.lock
.venv/
.venvs/
/build/
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ plugins:
- credits.md
- coverage.md

# skip files matching Unix shell-style wildcards
skip_file_globs:
- reference/*

# whether to only check in strict mode
strict_only: yes
```
Expand Down
5 changes: 4 additions & 1 deletion docs/known_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ dataclass
ahrens
dev
fr
uv
uv
codespell
mkdocs_spellcheck
symspellpy
12 changes: 10 additions & 2 deletions src/mkdocs_spellcheck/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import fnmatch
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -66,6 +67,7 @@ class SpellCheckPlugin(BasePlugin):
("backends", MkType(list, default=["symspellpy"])),
("known_words", MkType((str, list), default=[])),
("skip_files", MkType(list, default=[])),
("skip_file_globs", MkType(list, default=[])),
("min_length", MkType(int, default=2)),
("max_capital", MkType(int, default=1)),
("ignore_code", MkType(bool, default=True)),
Expand All @@ -89,7 +91,10 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
"""
self.strict_only = self.config["strict_only"]
self.backends_config = self.config["backends"]
self.skip_files = self.config["skip_files"]
# Convert the skip files into a set of Path objects to make it
# OS-agnostic and increase lookup efficiency
self.skip_files = {Path(x) for x in self.config["skip_files"]}
self.skip_file_globs = self.config["skip_file_globs"]
self.min_length = self.config["min_length"]
self.max_capital = self.config["max_capital"]
self.ignore_code = self.config["ignore_code"]
Expand Down Expand Up @@ -129,7 +134,10 @@ def on_page_content(self, html: str, page: Page, **kwargs: Any) -> None: # noqa
page: The page instance.
**kwargs: Additional arguments passed by MkDocs.
"""
if self.run and page.file.src_path not in self.skip_files:
if self.run and not (
Path(page.file.src_path) in self.skip_files
or any(fnmatch.fnmatch(page.file.src_path, pattern) for pattern in self.skip_file_globs)
):
words = get_words(
html,
known_words=self.known_words,
Expand Down

0 comments on commit e5b8c80

Please sign in to comment.