Skip to content

chore: adopt oxfmt and oxlint with a pre-commit hook - #19

Merged
paustint merged 8 commits into
mainfrom
chore/oxc-toolchain
Oct 10, 2026
Merged

paustint merged 8 commits into
mainfrom
chore/oxc-toolchain

Conversation

@paustint

@paustint paustint commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Brings simple-xml onto the oxc toolchain already used by sf-formula-parser, soql-parser-js and simple-excel.

Changes

  • Formatter: Prettier is replaced by oxfmt. .prettierrc becomes .oxfmtrc.json with the settings the other libraries share.
  • Linter: oxlint is new; the repo had no linter before. It runs correctness, suspicious and perf as errors, with style and pedantic off. The only overrides are __dirname in the parse tests and the polling loop in the shared release script. It is locked at 1.85.0 to match the other three repos.
  • Scripts: format, format:check, lint, lint:fix, and a prepare script that sets core.hooksPath to .githooks on npm install.
  • Pre-commit hook: .githooks/pre-commit is the copy shared with the other libraries. It runs the format check and oxlint on staged files and blocks the commit if either fails.
  • CI: gates on format:check and lint, since the hook can be bypassed with --no-verify.
  • Parser cleanup (src/parse.ts), with no behaviour change:
    • addChild moves to module scope, so it isn't recreated on every parse() call.
    • parseAttributes drops a coerce parameter, unused since 1.1.0.
    • One .reverse() keeps an inline disable. The suggested toReversed() is ES2023, and esbuild doesn't polyfill it for the ES2022 target.
  • Reformat: cosmetic only: README table padding and a few test lines.
  • Docs: AGENTS.md gains formatting, linting and commit-hook sections. CHANGELOG has an entry under ### Changed, so the next release is a patch.

Verification

  • format:check, lint, typecheck, build and all 117 tests pass.
  • A probe commit that was both unformatted and had a lint error was blocked, and both problems were reported in the same attempt.
  • All four commits on this branch went through the hook.

After merging, run npm install once in an existing checkout to turn the hook on.

Adopt the oxc toolchain already used by sf-formula-parser, soql-parser-js
and simple-excel. .prettierrc becomes .oxfmtrc.json with the same settings
those repositories share, and .oxlintrc.json adds a linter, which the
repository did not have. Both are exposed as format, format:check, lint
and lint:fix.

oxlint runs correctness, suspicious and perf as errors; style and pedantic
stay off because oxfmt owns layout. The only overrides are the ones this
codebase needs: __dirname in the parse tests and the sequential polling
loop in the shared release script.

oxlint is locked at 1.85.0 to match the sibling repositories, so all four
lint with the same rule set.

The reformat touches only lines Prettier had also left unformatted: README
table padding and a few test assertions that fit within 140 columns.
.claude/settings.json now matches the copy the sibling repositories share.
No behaviour change.

- addChild captures nothing from parse(), so it moves to module scope
  rather than being recreated on every call.
- parseAttributes drops its coerce parameter, unused since 1.1.0 stopped
  coercing attribute values.
- The reverse() that orders the unclosed-tag error is kept and the rule
  silenced on that line: it reverses the fresh array from map(), so
  nothing shared is mutated, and the suggested toReversed() is ES2023,
  which esbuild does not polyfill for the ES2022 build target.
A pre-commit hook blocks commits whose staged files are unformatted or
fail lint, running both so one attempt reports everything to fix. The
prepare script wires it up on npm install via core.hooksPath. The hook is
the copy shared with sf-formula-parser, soql-parser-js and simple-excel.

CI gates on format:check and lint ahead of typecheck, because the hook can
be bypassed with --no-verify.
AGENTS.md gains formatting, linting and commit hook sections, and lists
the hook and oxfmt config among the files shared with the sibling
repositories. The changelog records the change under Changed.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 18:52
@socket-security

socket-security Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedoxfmt@​0.70.0861008896100
Addedoxlint@​1.85.0991009196100

View full report

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The hook checks working-tree content instead of staged content, lint exceptions are overly broad, and Claude can invoke release scripts without approval.

Review effort: Balanced
Findings: 1 High severity · 3 Medium severity

Open (4)
What changed in this PR

Adopts the oxc formatting and linting toolchain with local and CI enforcement.

Changes:

  • Replaces Prettier with oxfmt and adds oxlint.
  • Adds CI checks and a pre-commit hook.
  • Refactors parser internals and reformats existing files.
File Description
src/​parse.ts Applies lint-driven parser cleanup.
src/​__tests__/​parse.test.ts Reformats parser tests.
src/​__tests__/​build.test.ts Reformats builder tests.
README.md Reformats option tables.
package.json Adds tooling scripts and dependencies.
package-lock.json Locks new tooling dependencies.
CHANGELOG.md Documents the tooling migration.
AGENTS.md Documents formatting, linting, and hooks.
.oxlintrc.json Defines lint policy and overrides.
.oxfmtrc.json Configures oxfmt.
.github/​workflows/​ci.yml Adds formatting and linting gates.
.githooks/​pre-commit Adds local staged-file checks.
.claude/​settings.json Expands permitted development commands.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .claude/settings.json Outdated
Comment thread .githooks/pre-commit Outdated
Comment thread .oxlintrc.json Outdated
Comment thread .oxlintrc.json Outdated
The project allow list auto-approved every npm script, including the release scripts. Drop it so each contributor's own settings apply.
Rename the parse test's local __dirname to fixturesDir so no-underscore-dangle needs no repo-wide exception, and limit the no-await-in-loop override to scripts/release.mjs, the only file with a polling loop.
The hook passed staged paths to oxfmt and oxlint, which read the working tree. A file formatted on disk but never re-staged could slip through, and unstaged edits could block a clean commit. It now exports the index to a temporary directory and checks every tracked file there, so it sees exactly what the commit will contain.
Copilot AI balanced review requested due to automatic review settings October 10, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The hook is documented as shared verbatim but remains inconsistent with all three named repositories.

1 open finding
4 resolved since last review

🧠 Review effort: Balanced

Comment thread .githooks/pre-commit Outdated
Each copy named only the other repos, so the four files could never be byte-identical. The header now lists all four, so every copy matches exactly.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The Vitest lint override omits the existing scripts test suite.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Extend Vitest ESLint override to scripts test directory

.oxlintrc.json:29

This override misses scripts/__tests__/derive-increment.test.mjs, which also imports Vitest, so Vitest-specific correctness rules are not applied to that test suite. Include the scripts test directory in the override so all repository tests receive the intended plugin checks.

🧠 Review effort: Balanced

@paustint
paustint merged commit 03397a1 into main Oct 10, 2026
9 checks passed
@paustint
paustint deleted the chore/oxc-toolchain branch October 10, 2026 17:09
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.

2 participants