PromptTesting and QAOpen

.gitignore pattern tester prompt

Gitignore Pattern Tester and Reviewer is a prompt for developers who are not sure what their .gitignore actually matches. It explains each line, tests it against paths that must be ignored or must stay committed, and names the rule that decides every path.

What it does

It catches negations blocked by an excluded parent folder, inline comments, leading spaces, backslashes, stray ** patterns, secrets that are not covered and an ignored .env.example. It returns a corrected file whose tests pass rather than advice alone.

How to use it

Share your .gitignore with "+ path" lines for files that must be ignored and "- path" lines for files that must be kept. The checker scripts/gitignore_check.py reports HIGH, MEDIUM, LOW and INFO findings.

Requirements and limits

The checker uses the Python standard library and has been matched against real git behaviour.

More in Testing and QA and the Business prompt library.

Full text

Front matter
name: Gitignore Pattern Tester and Reviewer
description: - name: gitignore-pattern-tester-and-reviewer description: Explains every line of a .gitignore, tests it against paths that must be ignored or must stay committable, names the rule that decides each path, and flags mistakes such as negations blocked by an excluded parent folder, inline comments, l
kind: Prompt

Gitignore Pattern Tester and Reviewer


name: gitignore-pattern-tester-and-reviewer description: Explains every line of a .gitignore, tests it against paths that must be ignored or must stay committable, names the rule that decides each path, and flags mistakes such as negations blocked by an excluded parent folder, inline comments, leading spaces, backslashes, stray **, secrets not covered and .env.example ignored. Returns a fixed file. Includes a stdlib Python checker with --self-test, matched against real git. ---

Gitignore Pattern Tester and Reviewer

You help developers understand and fix .gitignore files. You explain what each pattern really matches, prove it with path tests, and find the mistakes that make git ignore source files or commit secrets and build output. You return a corrected file with tests that pass, not just advice.

Files in this skill

  • scripts/gitignore_check.py - explains each rule, runs "+ path" (must be ignored) and "- path" (must be kept) tests, names the deciding line for each path, and reports HIGH, MEDIUM, LOW and INFO findings (Python 3 standard library only)
  • references/gitignore-rules.md - how git reads ignore files: sources and priority, line syntax, anchoring, wildcards, the parent-directory rule, tracked files and commands to confirm
  • references/common-pitfalls.md - every finding code with its fix, pitfalls the script cannot see (broad names, tracked files, nested files, case sensitivity, lock files, .dockerignore differences) and good starting blocks
  • templates/gitignore-review.md - the review to hand back
  • examples/webapp.gitignore - a web app ignore file with six real bugs
  • examples/webapp-fixed.gitignore - the corrected file (all tests pass)
  • examples/webapp-paths.txt - 19 path tests used with both files

Workflow

1. Collect the inputs

Ask for the .gitignore (and any nested ones), the stack, and the paths that matter: what must be ignored (build output, dependencies, logs, secrets) and what must stay committable (source folders with common names like build/ or lib/, .gitkeep files, .env.example, lock files). If the user only asks "why is X ignored?" ask for the path and use git check-ignore -v X output if they have it.

2. Run the checker

python3 scripts/gitignore_check.py examples/webapp.gitignore --test examples/webapp-paths.txt
python3 scripts/gitignore_check.py .gitignore --test paths.txt --json
python3 scripts/gitignore_check.py --self-test

Paths file: + path must be ignored, - path must be kept, end directories with /. Exit 1 means a HIGH finding or a failed test, 2 means unreadable input. The checker models one ignore file at the repo root; for a nested file, give paths relative to its folder.

3. Explain and fix

  • Walk through the Rules table in plain words, especially anchoring (slash at start or middle = relative to the .gitignore folder) and the parent-directory rule (see references/gitignore-rules.md).
  • For each FAIL, quote the deciding line from the "Decided by" column and give the smallest change that fixes it.
  • Fix every HIGH and MEDIUM finding; explain any INFO you leave in place.
  • Add - path tests for source folders with common names so over-broad rules show up.
  • Re-run the checker on the fixed file until all tests pass, and show the diff.

4. Deliver

Fill templates/gitignore-review.md: what the current file does, the test table, findings, the full fixed file, a diff, and the commands to confirm (git check-ignore -v, git status --ignored) and to untrack files that were already committed (git rm --cached).

Example result

For examples/webapp.gitignore with examples/webapp-paths.txt: 13/19 tests pass, 1 HIGH, 4 MEDIUM, 2 LOW, 1 INFO. HIGH NEGATION_BLOCKED: logs/ excludes the folder, so !logs/.gitkeep can never apply (fix: logs/). MEDIUM: config/secrets.yml # never commit is one pattern, so the secrets file would be committed; Thumbs.db has a leading space; src\generated is read as srcgenerated; and .key, .pem and id_rsa files are not covered. LOW: .env hides .env.example; *.log is listed twice. The unanchored build also hides src/build/README.md (fix: /build/). examples/webapp-fixed.gitignore passes 19/19 with no HIGH, MEDIUM or LOW findings.

Rules

  • Last matching line wins; a file inside an excluded folder can never be re-included. Say this whenever a ! line is involved.
  • Never suggest ignoring lock files (package-lock.json, poetry.lock, go.sum, app Cargo.lock) or shared config the team commits on purpose.
  • If a secret was already committed, say that ignoring it is not enough: rotate it and consider rewriting history.
  • Prefer anchored root patterns (/dist/, /build/) for output folders, and put personal editor and OS files in the global ignore file when the team agrees.
  • Confirm on the real repository with git check-ignore -v: the script follows git's documented rules for one file, but nested files, .git/info/exclude, the global file and core.ignorecase can change the result.

FILE:references/gitignore-rules.md

How git reads .gitignore

Source: the gitignore(5) manual (git help gitignore). The checker implements these rules and was compared with real git 2.47 on 6,956 path checks with no differences.

Where rules come from (highest priority first)

  1. Command-line --exclude options (rare; used by some tools).
  2. .gitignore files: the one in the same folder as the path wins over the ones above it. Patterns are relative to the folder that holds that .gitignore.
  3. .git/info/exclude - local to one clone, never committed. Good for personal scratch files.
  4. The global file in core.excludesFile (default ~/.config/git/ignore) - good for editor and OS files such as .DS_Store and *.swp.

Inside one file, the LAST matching line decides.

Line syntax

LineMeaning
emptyignored, use as a separator
# textcomment; only at the very start of a line. foo # bar is the pattern foo # bar
\#filea name that starts with #
!patternre-include something an earlier line excluded
\!filea name that starts with !
name trailing spaces are dropped unless escaped (name\ )
nameleading spaces are KEPT and become part of the name
\escapes the next character; it is never a path separator

Slashes decide where a pattern matches

PatternMatchesDoes not match
buildbuild, src/build, a/b/build/x.js (any file or folder named build)build.sh
build/folders named build at any deptha FILE named build
/buildbuild next to the .gitignore onlysrc/build
doc/frotzdoc/frotz next to the .gitignore (a slash in the middle anchors like a leading slash)a/doc/frotz
**/doc/frotzdoc/frotz at any depth

Rule of thumb: no slash (or only a trailing one) = any depth; a slash at the start or middle = relative to the .gitignore folder.

Wildcards

WildcardMeaning
*any characters except / (.log, /az does not match ab/cz)
?exactly one character except /
[abc], [a-z], [!0-9], [^0-9]one character from (or not from) the set; [[:digit:]] style classes work
**/namename in any folder, including the top
dir/**everything inside dir, but not dir itself
a/**/ba/b, a/x/b, a/x/y/b
foo, bar** not next to slashes acts like a single *

The parent-directory rule (the most common surprise)

"It is not possible to re-include a file if a parent directory of that file is excluded." Git does not even list the contents of an excluded folder, so a later ! line never gets a chance.

# does NOT work: logs/ is excluded as a folder
logs/
!logs/.gitkeep

# works: exclude the folder's contents, keep the folder visible
logs/*
!logs/.gitkeep

# works for deeper files: re-include each folder level
/assets/*
!/assets/icons/
/assets/icons/*
!/assets/icons/app.svg

Whitelist style

Ignore everything, then allow what you want:

*
!*/
!*.md
!src/**

!*/ re-includes every folder so the later ! lines can reach files inside them.

Already tracked files

.gitignore only affects untracked files. A file that is already committed stays tracked:

git rm --cached path/to/file        # keep it on disk, stop tracking it
git rm -r --cached build/           # same for a folder

If it was a secret, removing it from tracking is not enough: rotate the secret, because it is still in history.

Commands to confirm

git check-ignore -v path/to/file          # prints the file, line and pattern that ignores it (nothing = not ignored)
git check-ignore -v --no-index path       # also for files that are tracked
git status --ignored --short              # lists ignored files as "!!"
git ls-files --others --ignored --exclude-standard   # every ignored untracked file

FILE:references/common-pitfalls.md

Common .gitignore pitfalls and the checker's codes

CodeSeverityWhat goes wrongFix
NEGATION_BLOCKEDHIGH!path/file after a rule that excludes a parent folder (logs/, dist, a/* for a/b/c) never takes effect, so the file you meant to commit stays ignoredExclude contents (logs/ or logs/*) instead of the folder, or re-include each folder level (!a/b/)
SECRETS_NOT_COVEREDMEDIUMtypical secret files (.env, .pem, .key, id_rsa) would be committed by git add .Add .env, .env., .pem, .key, id_rsa; also use a secret scanner in CI
INLINE_COMMENTMEDIUMsecrets.yml # never commit is one pattern including the comment text, so secrets.yml is NOT ignoredPut comments on their own line
LEADING_SPACEMEDIUM Thumbs.db matches only a name that starts with a spaceRemove the space
BACKSLASH_SEPARATORMEDIUMsrc\generated means "src" + escaped "g" + "enerated" = srcgeneratedAlways use /, also on Windows
ENV_EXAMPLE_IGNOREDLOW.env* also hides .env.example, the template other developers needAdd !.env.example after it
DUPLICATELOWthe same line twice; harmless but a sign of copy-paste mergesDelete one
DOUBLE_STARLOWfoo** is just foo; the author probably meant foo/*Use only as /x, x/ or a//b
TRAILING_SPACELOWtrailing spaces are silently dropped; if they were meant, the file will not matchRemove or escape them
CRLFLOWWindows line endings in .gitignoreSave as LF; add * text=auto to .gitattributes
ANCHORED_BY_SLASHINFOsrc/gen only matches next to the .gitignore, not packages/a/src/genAdd / to show intent or **/ to match at any depth

Pitfalls the script cannot see (check them by hand)

  • Unanchored names that are too broad. build also hides src/build/ and docs/build/; lib hides every lib folder including source code. Use /build/ for the root output folder. Write a - path test for any source folder with a common name.
  • Tracked files. Adding a rule does not untrack files already committed. Run git ls-files -ci --exclude-standard to list tracked files that match the ignore rules, then git rm --cached.
  • Nested .gitignore files. A .gitignore in a subfolder adds rules relative to that subfolder and can re-include what the root file excluded (unless a parent folder is excluded). Run the checker on each file with paths relative to its folder, or confirm with git check-ignore -v.
  • Case sensitivity. On macOS and Windows core.ignorecase=true makes .JPG match photo.jpg; on Linux CI it does not. Write both cases or use .[jJ][pP][gG].
  • Personal files in the shared file. .idea/, .vscode/, *.swp, .DS_Store belong in the global ignore file (core.excludesFile), though many teams keep them in the repo file for convenience. Do not ignore .vscode/settings.json if the team shares it on purpose.
  • Lock files. Do not ignore package-lock.json, yarn.lock, pnpm-lock.yaml, poetry.lock, Cargo.lock (for applications) or go.sum: they make builds reproducible.
  • Ignoring then committing anyway. git add -f overrides ignore rules; reviewers should check for force-added build output or secrets.
  • Other ignore files use different rules. .dockerignore uses Go filepath.Match plus ** and is always anchored at the build context root (no "any depth" for plain names). .npmignore, .eslintignore and .prettierignore follow gitignore-like rules but not always every detail. Test them with their own tools.

Good starting blocks

# Node
node_modules/
/dist/
/build/
npm-debug.log*
.npm/

# Python
__pycache__/
*.py[cod]
.venv/
.pytest_cache/
/dist/
*.egg-info/

# Secrets
.env
.env.*
!.env.example
*.pem
*.key
id_rsa*

# Logs that keep their folder
logs/*
!logs/.gitkeep

FILE:templates/gitignore-review.md

.gitignore review: <repository or folder>

Stack: <Node 20 + Vite / Python 3.12 / monorepo with pnpm workspaces> Files reviewed: <.gitignore at root, packages/api/.gitignore> Summary: <one sentence: the most important problem and what the fix changes>

What the current file does

LinePatternMeaning
<9><logs/><ignores every folder named logs, at any depth, and everything in it>

Path tests

ResultPathExpectedActualDecided by
<FAIL><logs/.gitkeep><kept><ignored><parent logs/ excluded by L9; L10 cannot re-include it>

Findings

#SeverityCodeLineProblemFix
1<HIGH><NEGATION_BLOCKED><10><...><use logs/* instead of logs/>

Proposed .gitignore

<full fixed file, with comments on their own lines>

Changes

- logs/
+ logs/*

Apply and confirm

  1. Replace the file, then run: git check-ignore -v <each path from the tests>
  2. git status --ignored --short and check nothing important shows as !!
  3. Untrack files that are now ignored but were committed: git rm --cached <path> (rotate any secret that was committed)
  4. Commit: chore: fix .gitignore (<short reason>)

Follow-ups

  • <move editor files to the global ignore file>
  • <add a secret scanner (gitleaks, trufflehog) to CI>

FILE:examples/webapp.gitignore

Dependencies

node_modules /vendor/

Build output

dist/ build *.log logs/ !logs/.gitkeep

Environment

.env* config/secrets.yml # never commit

OS and editor files

.DS_Store .idea/ *.swp Thumbs.db

Test coverage

coverage/** !coverage/README.md

Generated code

src\generated *.log FILE:examples/webapp-fixed.gitignore

Dependencies

node_modules/ /vendor/

Build output (root only, so src/build/ stays tracked)

/dist/ /build/ *.log

ignore the contents of logs/, not the folder, so the negation can work

logs/* !logs/.gitkeep

Environment and secrets

.env .env. !.env.example .pem .key id_rsa

never commit

config/secrets.yml

OS and editor files

.DS_Store Thumbs.db .idea/ *.swp

Test coverage

coverage/** !coverage/README.md

Generated code

/src/generated/ FILE:examples/webapp-paths.txt

Paths for examples/webapp.gitignore and webapp-fixed.gitignore

"+ path" = must be ignored, "- path" = must stay committable

+ node_modules/react/index.js + packages/api/node_modules/lodash/lodash.js + vendor/autoload.php

  • packages/vendor/README.md

+ dist/app.js + build/output.js

  • src/build/README.md

+ logs/app.log

  • logs/.gitkeep

+ .env + .env.local

  • .env.example

+ config/secrets.yml + .DS_Store + Thumbs.db + coverage/lcov.info

  • coverage/README.md

+ src/generated/types.ts

  • src/index.ts

FILE:scripts/gitignore_check.py #!/usr/bin/env python3 """Gitignore pattern tester and reviewer (Python 3 standard library only).

Explains every rule in a .gitignore file, tests the file against paths that must be ignored ("+ path") or must stay committable ("- path"), names the rule that decides each path, and flags common mistakes: negations that cannot work because a parent directory is excluded, inline comments, leading spaces, Windows backslashes, stray "**", duplicates, secrets that are not covered and .env.example being ignored.

Matching follows git's documented gitignore rules for a single .gitignore at the repository root: last matching rule wins, "!" re-includes, a trailing "/" matches directories only, a "/" at the start or in the middle anchors the pattern to the .gitignore's directory, "" "?" "[...]" never match "/", "*" spans directories, and a file can never be re-included if a parent directory is excluded.

Usage: python3 gitignore_check.py .gitignore [--test paths.txt] [--json] python3 gitignore_check.py --self-test Paths file: one path per line, "+ path" = must be ignored, "- path" = must NOT be ignored, end a path with "/" if it is a directory, "#" starts a comment. Exit codes: 0 = no HIGH findings and all tests pass, 1 = HIGH finding or failed test, 2 = unreadable input. """ import argparse, json, re, sys

SEV_ORDER = {"HIGH": 0, "MEDIUM": 1, "LOW": 2, "INFO": 3} SECRET_PROBES = [".env", "config/.env.production", "certs/server.key", "deploy/id_rsa", "secrets/service-account.pem"] POSIX_CLASSES = {"alnum": "a-zA-Z0-9", "alpha": "a-zA-Z", "digit": "0-9", "lower": "a-z", "upper": "A-Z", "space": " \\t\\n\\r\\f\\v", "xdigit": "0-9A-Fa-f", "punct": re.escape("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"), "blank": " \\t"}

class Rule: def __init__(self, line_no, raw, negate, dir_only, anchored, body, regex): self.line_no, self.raw, self.negate, self.dir_only = line_no, raw, negate, dir_only self.anchored, self.body, self.regex = anchored, body, regex

def matches(self, rel_path, is_dir): if self.dir_only and not is_dir: return False target = rel_path if self.anchored else rel_path.rsplit("/", 1)[-1] return self.regex.fullmatch(target) is not None

def label(self): return f"L{self.line_no} {self.raw}"

def strip_trailing_spaces(s): """git drops trailing spaces unless the last one is escaped with a backslash.""" end = len(s) while end > 0 and s[end - 1] == " ": bs, k = 0, end - 2 while k >= 0 and s[k] == "\\": bs += 1; k -= 1 if bs % 2 == 1: break end -= 1 return s[:end]

def class_to_regex(body): out, m = "", 0 while m < len(body): ch = body[m] if ch == "[" and body.startswith("[:", m): end = body.find(":]", m + 2) if end != -1 and body[m + 2:end] in POSIX_CLASSES: out += POSIX_CLASSES[body[m + 2:end]]; m = end + 2; continue if ch == "\\" and m + 1 < len(body): out += re.escape(body[m + 1]); m += 2; continue if ch == "-" and 0 < m < len(body) - 1: out += "-"; m += 1; continue out += re.escape(ch); m += 1 return out

def glob_to_regex(p): out, i, n = "", 0, len(p) while i < n: c = p[i] if c == "\\": if i + 1 < n: out += re.escape(p[i + 1]); i += 2 else: i += 1 # a lone trailing backslash matches nothing extra continue if c == "": j = i while j < n and p[j] == "": j += 1 if j - i >= 2 and (i == 0 or p[i - 1] == "/") and (j == n or p[j] == "/"): if j == n: out += "."; i = j else: out += "(?:./)?"; i = j + 1 continue out += "[^/]*"; i = j; continue if c == "?": out += "[^/]"; i += 1; continue if c == "[": j = i + 1 neg = j < n and p[j] in "!^" if neg: j += 1 k = j + 1 if j < n and p[j] == "]" else j while k < n and p[k] != "]": if p[k] == "[" and p.startswith("[:", k): end = p.find(":]", k + 2) if end != -1: k = end + 2; continue k += 2 if p[k] == "\\" else 1 if k >= n: out += re.escape("["); i += 1; continue cls = class_to_regex(p[j:k]) out += ("[^/" + cls + "]") if neg else ("(?!/)[" + cls + "]") i = k + 1; continue out += re.escape(c); i += 1 return out

def parse_rules(text): rules, findings, seen = [], [], {} for no, raw in enumerate(text.split("\n"), 1): if raw.endswith("\r"): findings.append(("LOW", "CRLF", no, "line ends with CR (Windows line ending)", "Save the file with LF line endings; set text=auto in .gitattributes.")) raw = raw[:-1] if not raw.strip() or raw.startswith("#"): continue line = strip_trailing_spaces(raw) if line != raw: findings.append(("LOW", "TRAILING_SPACE", no, f"{raw} has trailing spaces, which git drops", "Delete them; escape a real trailing space as \\ .")) if raw[0] in " \t": findings.append(("MEDIUM", "LEADING_SPACE", no, f"{raw} starts with whitespace, which git keeps as part of the name, so it matches nothing useful", "Remove the leading whitespace.")) m = re.search(r"\s#", line) if m: findings.append(("MEDIUM", "INLINE_COMMENT", no, f"{line}: git has no inline comments, so {line[m.start():].strip()} becomes part of the pattern", "Move the comment to its own line starting with #.")) if re.search(r"\\[A-Za-z0-9_]", line): findings.append(("MEDIUM", "BACKSLASH_SEPARATOR", no, f"{line} uses a backslash, which escapes the next character instead of separating directories", "Use forward slashes: " + line.replace("\\", "/") + ".")) key = line.strip() if key in seen: findings.append(("LOW", "DUPLICATE", no, f"{key} repeats line {seen[key]}", "Delete the duplicate.")) else: seen[key] = no negate = line.startswith("!") body = line[1:] if negate else line if body.startswith("\\!") or body.startswith("\\#"): body = body[1:] if negate and not body: findings.append(("LOW", "EMPTY_NEGATION", no, "! alone does nothing", "Delete the line.")) continue dir_only = body.endswith("/") and not body.endswith("\\/") if dir_only: body = body.rstrip("/") if not body: continue anchored = "/" in body if body.startswith("/"): body = body[1:] if any((m.start() > 0 and body[m.start() - 1] != "/") or (m.end() < len(body) and body[m.end()] != "/") for m in re.finditer(r"\{2,}", body)): findings.append(("LOW", "DOUBLE_STAR", no, f"{line}: ** not between slashes acts like a single ", "Use /name, dir/ or a/*/b, or a single *.")) rules.append(Rule(no, line, negate, dir_only, anchored, body, re.compile(glob_to_regex(body), re.S))) return rules, findings

def last_match(rules, rel_path, is_dir): hit = None for r in rules: if r.matches(rel_path, is_dir): hit = r return hit

def check_path(rules, path): """Return (ignored, reason, blocked_rule) following git's parent-directory rule.""" is_dir = path.endswith("/") parts = [p for p in path.strip("/").split("/") if p] for k in range(1, len(parts) + 1): sub = "/".join(parts[:k]) sub_is_dir = k < len(parts) or is_dir hit = last_match(rules, sub, sub_is_dir) if k < len(parts): if hit and not hit.negate: own = last_match(rules, "/".join(parts), is_dir) blocked = own if own and own.negate else None return True, f"parent {sub}/ excluded by {hit.label()}", blocked else: if hit is None: return False, "no rule matches", None if hit.negate: return False, f"re-included by {hit.label()}", None return True, f"ignored by {hit.label()}", None return False, "empty path", None

def literal_dirs(body): parts = body.split("/")[:-1] out = [] for p in parts: if any(ch in p for ch in "*?[\\"): break out.append(p) return out

def lint_negations(rules): findings = [] for idx, r in enumerate(rules): if not r.negate or not r.anchored: continue before = rules[:idx] dirs = literal_dirs(r.body) for k in range(1, len(dirs) + 1): sub = "/".join(dirs[:k]) hit = last_match(before, sub, True) if hit and not hit.negate: findings.append(("HIGH", "NEGATION_BLOCKED", r.line_no, f"{r.raw.strip()} can never apply: its parent directory {sub}/ is excluded by {hit.label()} and git does not look inside excluded directories", f"Exclude the contents instead of the directory ({sub}/ or {sub}/*), then keep the ! rule; or re-include !{sub}/ first.")) break return findings

def lint_secrets(rules): findings = [] missing = [p for p in SECRET_PROBES if not check_path(rules, p)[0]] if missing: findings.append(("MEDIUM", "SECRETS_NOT_COVERED", 0, "these typical secret files would NOT be ignored: " + ", ".join(missing), "Add .env, .env. (with !.env.example), .pem, .key, id_rsa if the project could ever contain them.")) if check_path(rules, ".env.example")[0]: findings.append(("LOW", "ENV_EXAMPLE_IGNORED", 0, ".env.example is ignored, so the documented template cannot be committed", "Add !.env.example after the .env rule.")) return findings

def explain(rule): body = rule.body kind = "directories" if rule.dir_only else "files or directories" verb = "Re-includes" if rule.negate else "Ignores" wild = any(ch in body for ch in "?[") if rule.anchored and body.endswith("/*") and "*" not in body[:-3]: text = f"{verb} everything inside {body[:-3]}/ (but not the folder itself), relative to the .gitignore folder" elif rule.anchored and body.startswith("/") and "/" not in body[3:]: text = f"{verb} {kind} {'matching' if wild else 'named'} {body[3:]} at any depth" elif rule.anchored: text = f"{verb} {kind} {'matching' if wild else 'at'} {body} relative to the .gitignore folder only" else: text = f"{verb} {kind} {'matching' if wild else 'named'} {body} at any depth" if not rule.negate and not body.endswith("/"): text += "; a matched directory hides everything inside it" if rule.negate: text += " (only works if no parent directory is excluded)" return text + "."

def read_tests(text): tests = [] for no, line in enumerate(text.splitlines(), 1): s = line.strip() if not s or s.startswith("#"): continue if s[0] not in "+-" or len(s) < 3: raise ValueError(f"paths file line {no}: expected '+ path' or '- path', got {line!r}") tests.append((s[0] == "+", s[1:].strip())) return tests

def review(gi_text, tests_text=None): rules, findings = parse_rules(gi_text) findings += lint_negations(rules) findings += lint_secrets(rules) anchored = [r.line_no for r in rules if r.anchored and not r.negate and "/" in r.body and not r.raw.startswith(("/", "/")) and not r.body.endswith("/")] if anchored: findings.append(("INFO", "ANCHORED_BY_SLASH", anchored[0], "lines " + ", ".join(map(str, anchored)) + " contain a slash, so they only match relative to the .gitignore folder, not deeper copies", "Fine if intended; add a leading / to make that explicit, or prefix **/ to match at any depth.")) results = [] if tests_text: for want, path in read_tests(tests_text): got, reason, blocked = check_path(rules, path) note = reason if blocked: note += f"; {blocked.label()} cannot re-include it" results.append({"path": path, "expect": "ignored" if want else "kept", "actual": "ignored" if got else "kept", "pass": got == want, "why": note}) findings.sort(key=lambda f: (SEV_ORDER[f[0]], f[2])) return {"rules": [{"line": r.line_no, "pattern": r.raw, "meaning": explain(r)} for r in rules], "findings": [dict(zip(("severity", "code", "line", "problem", "fix"), f)) for f in findings], "tests": results}

The text continues at the source. Read the rest.

Source and license

Source: https://github.com/f/prompts.chat/blob/main/prompts/02671.md

Author: f, prompts.chat prompt library. License: CC0-1.0.

Shown here with formatting for the web. Keep the author and license notice when you reuse it.

Related entries

There are more like this in the members library

The Business prompt library holds 3,008 entries. Members can search all of them by meaning and read every one in full.