Skip to content

Commit

Permalink
run-spellcheck/pyproject: Run both codespell and typos.
Browse files Browse the repository at this point in the history
`typos` supports a toml file, but not pyproject.toml yet (see
crate-ci/typos#361). To avoid yet-another-config-file, this adds a list of
files to exclude in run-spellcheck, passed to typos on the command-line.

`codespell` excludes are already configured in pyproject.toml.

Since file excludes and reasons are added to run-spellcheck, explicitly
exclude it from being checked for both tools.
  • Loading branch information
neiljp committed Mar 13, 2023
1 parent 7a5fc0b commit 4bbc07d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target-version = ['py37']
# test_themes: uses wrong words as part of a theme syntax test
# test_boxes: uses word prefixes as part of an autocomplete test
# test_messages: uses IST as Indian time zone, which is confused for IS/IT/ITS/IT'S/etc
skip = "zulipterminal/unicode_emojis.py,tests/config/test_themes.py,tests/ui_tools/test_boxes.py,tests/ui_tools/test_messages.py"
skip = "zulipterminal/unicode_emojis.py,tests/config/test_themes.py,tests/ui_tools/test_boxes.py,tests/ui_tools/test_messages.py,tools/run-spellcheck"

[tool.coverage.run]
branch = true
Expand Down
46 changes: 41 additions & 5 deletions tools/run-spellcheck
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,36 @@

import subprocess
import sys
from typing import List


cmds = ["codespell"]
files = [
TOOLS: List[List[str]] = [
[
"codespell",
"--toml",
"pyproject.toml",
],
[
"typos",
"--format",
"brief",
"--exclude",
"zulipterminal/unicode_emojis.py", # Words are defined externally
"--exclude",
"tests/ui_tools/test_messages.py", # IST as Indian timezone
"--exclude",
"tests/ui_tools/test_boxes.py", # Word prefixes as part of autocomplete test
"--exclude",
"tests/config/test_themes.py", # Wrong words as part of theme syntax test
"--exclude",
"tests/model/test_model.py", # 2nd not recognized crate-ci/typos#466
"--exclude",
"docs/FAQ.md", # iterm2 is proper noun [term, item, interm]
"--exclude",
"tools/run-spellcheck", # Exclude ourself due to notes
],
]
SOURCE = [
"zulipterminal",
"tests",
"tools",
Expand All @@ -16,12 +42,22 @@ files = [
"CHANGELOG.md",
]

result = subprocess.call(cmds + ["--toml pyproject.toml"] + files)
failed_commands = []
result = 0
for command in TOOLS:
result = subprocess.call(command + SOURCE)
if result == 0:
print(f"Spellchecker {command[0]} passed with no errors.")
else:
failed_commands.append(command[0])

if result == 0:
print("All files appear to have correct spelling.")
else:
print("Some files have incorrect spelling according to codespell.")
print("Try 'codespell -i3 -w <path>' to fix a path recursively.")
print(
f"Some files have incorrect spelling according to spellcheckers ({', '.join(failed_commands)})."
)
if "codespell" in failed_commands:
print("Try 'codespell -i3 -w <path>' to fix a path recursively.")

sys.exit(result)

0 comments on commit 4bbc07d

Please sign in to comment.