Repository navigation
Conversation
|
Before this is reviewed, please read the AI-Assisted Contributions section of the contributing guide and make sure this change meets it: you can explain every line, the description is your own and brief, it fixes a bug you hit or a feature agreed in an issue, it does not touch undocumented options, and any substantial tool use is noted. |
|
The license agreement is signed. |
Author
|
I have read the CLA and I agree to it |
iainlane
force-pushed
the
fix-mapped-code-format-v3
branch
from
October 6, 2026 13:01
afbc284 to
7120cd6
Compare
Vale decides how to read a file from its extension. In a source file, it lints only the comments. To find the comments, it parses the file with a tree-sitter grammar for the file's language. Clojure and PowerShell have no grammar, so Vale finds their comments with regular-expression comment patterns instead. Files with unknown extensions are linted as prose. A user can tell Vale to read a file as another language, either with the `[formats]` section of `.vale.ini` or with the `--ext` flag. Users do this for languages that Vale does not support, such as Nix, by choosing a supported language with the same comment syntax. With `nix = pl` in `[formats]`, Vale should lint the comments in `default.nix` and skip the Nix code. Today, this only works when Vale finds the target language's comments with patterns. When the target language has a grammar, Vale skips every comment in the file. This limited coverage is a regression: before 3.5.0, every code language had comment patterns, and reading a file as any of them worked. Vale removed each language's patterns when the language moved to tree-sitter: Python, Rust, Ruby, Go, JavaScript, TypeScript, C++ and Protocol Buffers in 3.5.0, and the rest apart from Clojure and PowerShell in 3.18.0 (e82432d). `lintCode` looks up the grammar by the file's real extension, not by the target language's extension. `.nix` has no grammar, so `lintCode` falls back to `lintCodeOld`, which looks up comment patterns by the target language's extension. Perl has no patterns, so `lintCodeOld` returns without linting any comments. The same lookup means that the target language has no effect when the real extension has a grammar: under `--ext=.c`, Vale still parses a `.ts` file as TypeScript. For markup, and for the comment patterns, the target language decides how Vale reads the file. The lookup by real extension dates from 172714d. At that time, Go, JavaScript, TypeScript and several other languages shared the normalized extension `.c`, so a lookup by the normalized extension would have parsed them all as C. Each of these languages now has its own normalized extension, so the two lookups give the same grammar unless the user has chosen a target language. Look up the grammar by the target language's extension in `lintCode`. Do the same in `lintDataComments`, which checks for a grammar before it calls `lintCode` to lint a data file's comments. Files without a `[formats]` entry or `--ext` are parsed as before. A user who maps one language with a grammar to another, such as `ts = js`, now gets the target language's grammar. Assisted-by: Claude Code
iainlane
force-pushed
the
fix-mapped-code-format-v3
branch
from
October 6, 2026 16:17
7120cd6 to
f4bd301
Compare
[formats] or --ext language
iainlane
marked this pull request as ready for review
October 6, 2026 17:04
iainlane
added a commit
to iainlane/dotfiles
that referenced
this pull request
Oct 7, 2026
nixpkgs has Vale 3.17.1, which places some alerts on the wrong text. An alert in a paragraph with a `TokenIgnores` match can be reported a second time at the ignored token, and an alert for a word before a code span can be misplaced. prose-lint needs both placements right before it can skip identifier-shaped tokens. Vale 3.18.0 to 3.24.0 fix the placements but skip every comment in a file that `[formats]` maps onto Perl. Perl's comments moved to tree-sitter, and Vale looks up the grammar by the real extension only. prose-lint maps Nix, shell and INI files onto Perl, so with those releases alone, Vale run by an editor or by the Nix fixture skips the comments in those files. The patch uses the grammar of the mapped format when the real extension has none. It is proposed upstream as vale-cli/vale#1200. By default buildGoModule builds from a `vendor` directory that `go mod vendor` makes, and `go mod vendor` copies only the directories of imported Go packages. The tree-sitter grammars that Vale 3.18.0 added compile C sources that include headers from directories with no Go files. go-tree-sitter's `php/parser.c` includes `tree_sitter/parser.h`, for example, and `php/tree_sitter` contains only headers. The vendored build therefore fails in the C compiler. Setting proxyVendor makes the fixed-output derivation run `go mod download` and keep Go's download cache. The build reads modules from that cache through a `file://` GOPROXY, and Go extracts each module from its archive in full, headers included. Evaluation fails once nixpkgs has 3.24.0, so the patch is checked against that release.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vale decides how to read a file from its extension. In a source file, it lints only the comments. To find the comments, it parses the file with a tree-sitter grammar for the file's language. Clojure and PowerShell have no grammar, so Vale finds their comments with regular-expression comment patterns instead. Files with unknown extensions are linted as prose.
A user can tell Vale to read a file as another language, either with the
[formats]section of.vale.inior with the--extflag. Users do this for languages that Vale does not support, such as Nix, by choosing a supported language with the same comment syntax. Withnix = plin[formats], Vale should lint the comments indefault.nixand skip the Nix code.Today, this only works when Vale finds the target language's comments with patterns. When the target language has a grammar, Vale skips every comment in the file. This limited coverage is a regression: before 3.5.0, every code language had comment patterns, and reading a file as any of them worked. Vale removed each language's patterns when the language moved to tree-sitter: Python, Rust, Ruby, Go, JavaScript, TypeScript, C++ and Protocol Buffers in 3.5.0, and the rest apart from Clojure and PowerShell in 3.18.0 (e82432d, "extract Lua, PHP, Haskell, R, and Perl comments with tree-sitter").
lintCodelooks up the grammar by the file's real extension, not by the target language's extension..nixhas no grammar, solintCodefalls back tolintCodeOld, which looks up comment patterns by the target language's extension. Perl has no patterns, solintCodeOldreturns without linting any comments. The same lookup means that the target language has no effect when the real extension has a grammar: under--ext=.c, Vale still parses a.tsfile as TypeScript. For markup, and for the comment patterns, the target language decides how Vale reads the file.The lookup by real extension dates from 172714d ("deprecate regex-based comment parsing"). At that time, Go, JavaScript, TypeScript and several other languages shared the normalized extension
.c, so a lookup by the normalized extension would have parsed them all as C. Each of these languages now has its own normalized extension, so the two lookups give the same grammar unless the user has chosen a target language.This PR makes
lintCodelook up the grammar by the target language's extension.lintDataComments, which checks for a grammar before it callslintCodeto lint a data file's comments, does the same. Files without a[formats]entry or--extare parsed as before. A user who maps one language with a grammar to another, such asts = js, now gets the target language's grammar.The new e2e cases
lint/perl-format-mapping,lint/perl-ext-flag,lint/ext-flag-overrides-grammarandviews/data-comments-format-mappingfail onv3and pass with this change.I wrote this change with Claude Code.