oxlint-vue-sfc-harness
oxlint-vue-sfc-harness
Shared template-AST harness for oxlint JS-plugin rules that need to read Vue SFC
templates. Extracted from oxlint-plugin-vue-sfc
and oxlint-plugin-vue-sfc-a11y, which
both consume it.
oxlint parses only the <script> block of an SFC, so a rule that needs the template has to
self-parse the file with @vue/compiler-sfc. This packages that escape hatch: a cached parseSfc,
a walkTemplate visitor, the NodeTypes constants, and reportAtFileOffset, which translates an
absolute file offset into the script-relative range oxlint expects.
import { NODE_ELEMENT, parseSfc, reportAtFileOffset, walkTemplate } from "oxlint-vue-sfc-harness";
Positions
A template offset in a template-first SFC is negative relative to the script block, and oxlint
rejects negative ranges. reportAtFileOffset handles that by clamping the range and prepending the
true location to the message ([template 12:5] …), so the CLI and editor problem lists still point
at the right place even though the squiggle lands on the script block.
oxc#26001 removes the need for this.
An SFC whose <script setup> is empty has no block offset at all (@vue/compiler-sfc reports
scriptSetup as null); that is treated as unrepresentable and takes the same prefixed path, rather
than silently reporting at an unadjusted offset.
./test-helpers
createLinter(rule, prefix) writes a real temp .vue file and parses its script with oxc-parser,
returning lintSource / lintTemplate / cleanup. Rules read the SFC off disk, so specs need a
real file rather than a string.
License
MIT
Related Packages
Vue SFC template rules for oxlint, as a JS plugin. Ports of eslint-plugin-vue ru...
Vue SFC accessibility rules for oxlint, as a JS plugin. Ports of eslint-plugin-v...
Vue SFC linting and formatting on the oxc toolchain. Rules reach inside , no esl...
Version History
| Version | Released | License |
|---|---|---|
| 0.1.0 | MIT |