Skip to content

feat: support globs in jsonTrailingCommaFiles - #65

Merged
dsherret merged 1 commit into
mainfrom
feat/trailing-comma-files-globs
Sep 13, 2026
Merged

dsherret merged 1 commit into
mainfrom
feat/trailing-comma-files-globs

Conversation

@dsherret

Copy link
Copy Markdown
Member

Closes #38

Allows glob patterns in jsonTrailingCommaFiles:

"jsonTrailingCommaFiles": ["{j,t}sconfig*.json", ".vscode/*.json"]

Supported syntax: *, ?, **, [abc] / [a-z] / [!abc], and {a,b}. Patterns match against the end of the file path at a path segment boundary, same as the existing literal entries (ex. tsconfig*.json matches at any depth and .vscode/*.json matches the last two segments).

Implementation

dprint uses the ignore crate (globset + regex) for its includes/excludes, but this plugin doesn't depend on regex, so pulling it in would bloat the Wasm file. Instead there's a small matcher in src/glob.rs:

  • Literal patterns (no *, ?, or [) do a single byte comparison against the end of the path without allocating, which is as cheap as the previous ends_with checks.
  • Globs without ** match trailing path segments without allocating. Globstar patterns use a linear backtracking match over segments, so repeated ** can't blow up.
  • Braces are expanded once when resolving the configuration, so expanded literal alternatives still take the fast path. Expansion is capped at 1000 patterns and 16 levels of nesting, reporting a diagnostic otherwise.
  • The path is only matched when trailingCommas is jsonc.

Behavior changes

  • The resolved Configuration.json_trailing_comma_files now holds normalized patterns (ex. "test.json") rather than the doubled "/test.json" and "\test.json" entries. The matcher still handles leading slashes and either separator for anyone constructing the configuration directly.
  • Entries containing glob characters are now interpreted as globs, so a literal [id].json would need to be written as [[]id].json.
  • Empty entries, entries containing .., and entries that expand to a ./ prefix (ex. .\a.json or {./a.json,b.json}) now report diagnostics.

@dsherret
dsherret merged commit 6346f29 into main Sep 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow globs in jsonTrailingCommaFiles

1 participant