Aan de slag
Configurable Phrase Scanner — File Findings

Configurable Phrase Scanner — File Findings

Send: files or a directory, plus a JSON list of phrases and severities. Get back: matching phrases with file, line, column, severity, and optional context. #Techniek

Beoordeling
Meer beoordelingen nodig
Verkocht
0
Gebruikswijze
Downloaden

Configurable Phrase Scanner

Find phrases in Markdown, text, source files, or directories. Provide your own JSON vocabulary so the same scanner can serve editorial checks, release reviews, or repository hygiene. The tool reads local UTF-8 files and never edits them.

What you get

  • Case-insensitive Unicode-normalized phrase matching, with optional exact case and whole-word boundaries.
  • Deterministic recursive file discovery, extension filters, and repeatable exclusions.
  • One-based line and column locations, severity labels, and configurable context excerpts.
  • Text or JSON reports, per-file size limits, and optional severity-based exit codes for CI.
  • 21 independent tests and synthetic examples.

Requirements

Python 3.10 or newer. The scanner uses only the Python standard library. Tests use pytest.

Quick start

python3 scripts/phrase_scanner.py examples/draft.md --terms examples/terms.json

Exact output:

examples/draft.md:2:1: info: TODO: TODO
examples/draft.md:3:22: error: temporary password: temporary password
examples/draft.md:4:19: warning: needs review: needs review

Scan a directory and fail a CI step on errors:

python3 scripts/phrase_scanner.py ./docs --terms ./review-terms.json --extensions md,txt --whole-word --fail-on error --format json

Term file

Use a JSON array. A string defaults to warning; objects can select info, warning, or error.

[
  "FIXME",
  {"phrase": "needs approval", "severity": "error"}
]

Duplicate phrases after Unicode and case normalization are collapsed. Terms are treated as literal text, never as regular expressions.

Options

Option Purpose
--terms FILE Required UTF-8 JSON vocabulary
--extensions LIST Comma-separated suffix allowlist such as md,txt
--exclude PATH Skip a path; repeat for multiple exclusions
--case-sensitive Match letter case exactly
--whole-word Require non-word characters at phrase edges
--context N Include N surrounding characters in each excerpt
--max-bytes N Per-file byte limit; default 2,000,000
--format text|json Choose readable lines or structured JSON
--fail-on never|warning|error Return 1 when a finding meets the selected severity

Malformed vocabularies return status 2. File read/encoding/size problems appear in the report as errors; they do not silently count as a clean scan. A phrase scanner is a review aid: it does not interpret context, make policy decisions, or modify files.