|
| 1 | +typst_preview := replace(cache_directory(), '\', '/') + "/typst/packages/preview" |
| 2 | + |
| 3 | +# List available recipes |
| 4 | +@list: |
| 5 | + just --list |
| 6 | + |
| 7 | +# Scan code by rules, e.g., `just scan headcount`, `just scan i-figured/0.2.4 --off=hard-coded-str`, `just scan tidy/0.3.0 --filter=eval` |
| 8 | +scan PREVIEW_PACKAGE_PATH *OPTIONS: |
| 9 | + ast-grep scan {{ OPTIONS }} {{ typst_preview }}/{{ PREVIEW_PACKAGE_PATH }} |
| 10 | + |
| 11 | +# Normal procedure after adding new tests; see also https://ast-grep.github.io/guide/test-rule.html |
| 12 | +add-test: |
| 13 | + ast-grep test --skip-snapshot-tests |
| 14 | + ast-grep test --interactive |
| 15 | + ast-grep test |
| 16 | + |
| 17 | +# Check rule files match their IDs and tests |
| 18 | +check: |
| 19 | + #!/usr/bin/env -S uv run --script |
| 20 | + # /// script |
| 21 | + # requires-python = ">=3.12" |
| 22 | + # dependencies = [ |
| 23 | + # "ruamel-yaml", |
| 24 | + # ] |
| 25 | + # /// |
| 26 | + from pathlib import Path |
| 27 | + |
| 28 | + from ruamel.yaml import YAML |
| 29 | + |
| 30 | + yaml = YAML(typ="safe") |
| 31 | + root = Path.cwd() |
| 32 | + |
| 33 | + |
| 34 | + def load_id(file: Path) -> str: |
| 35 | + return yaml.load(file.read_text(encoding="utf-8"))["id"] |
| 36 | + |
| 37 | + |
| 38 | + def human(file: Path) -> str: |
| 39 | + return file.relative_to(root).as_posix() |
| 40 | + |
| 41 | + |
| 42 | + for rule in (root / "rules").iterdir(): |
| 43 | + if not rule.is_file(): |
| 44 | + continue |
| 45 | + |
| 46 | + assert rule.suffix == ".yml", f"Rule file {human(rule)} must be a .yml file" |
| 47 | + assert rule.stem == load_id(rule), f"Rule file {human(rule)} stem must match its ID" |
| 48 | + |
| 49 | + test = root / "rules-tests" / f"{rule.stem}-test.yml" |
| 50 | + assert test.exists() and test.is_file(), f"Test file {human(test)} must exist" |
| 51 | + assert rule.stem == load_id(test), f"Test file {human(test)} stem must match its ID" |
0 commit comments