Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add config option to ignore files based on Unix shell-style wildcard pattern matching #23

Merged
merged 4 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
nfelt14 marked this conversation as resolved.
Show resolved Hide resolved
.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=[])),
nfelt14 marked this conversation as resolved.
Show resolved Hide resolved
("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"]}
nfelt14 marked this conversation as resolved.
Show resolved Hide resolved
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