Demo: repo-wide style enforcement (.editorconfig, Prettier, .gitattributes)#18
Open
joewiz wants to merge 3 commits into
Open
Demo: repo-wide style enforcement (.editorconfig, Prettier, .gitattributes)#18joewiz wants to merge 3 commits into
joewiz wants to merge 3 commits into
Conversation
Establishes baseline style enforcement without changing any source files: - .editorconfig — 2-space indent for JS/TS/CSS/JSON/YAML/Markdown (modern community convention); 4-space for XQuery/XML/HTML/template (per existing project style). LF, trim trailing whitespace, final newline. Picked up by VS Code, JetBrains, Vim, etc. - .gitattributes (text=auto eol=lf + binary list) — prevents CRLF churn from Windows contributors. - .prettierrc.json with overrides for XML, XQuery, Markdown, JSON, YAML; wires up @prettier/plugin-xml and prettier-plugin-xquery. Global tabWidth: 2; XML/XQuery overrides bump back to 4. XML parser uses xmlSelfClosingSpace: false so <br/> and <?xml ... ?> emit without the XHTML-compat leading space. - .prettierignore for generated bundles, REx-generated parsers, the vendored support/ tree, build output, lockfiles. - npm scripts: `format` (write) and `format:check` (read-only CI check). - .gitignore: allowlist the four new dotfiles past the `.*` rule. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Demonstrates the effect of adopting the style config in the prior commit. Files reformatted across JS, XQuery, XML, CSS, JSON, YAML, Markdown, SVG, HTML/template. All 179 unit tests pass. No semantic changes. JS lines comprise most of the diff because Prettier flips 4-space indent (and original mixed tabs) to 2-space — the dominant modern JS convention (Airbnb, Standard, Google style guide, npm packages). XQuery/XML/HTML stay at 4-space per existing project style. This commit is the "what would happen if we ran npm run format" demo and is meant to be inspected, not necessarily merged as-is. Options: - keep as a single mechanical sweep - split per directory / file type for easier review - drop and let prettier apply file-by-file as code is touched Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Leave the two commits, and add the prehook. As for churn now is a good time. 2 spaces is fine for js. Xq4 is not for this release, but I have faith in prettier support coming soon™ |
Per @duncdrum's review on #18: add a pre-commit hook so contributors don't need to remember `npm run format`. Staged files matching the prettier-managed patterns are auto-formatted before each commit; the commit is rejected if prettier can't parse the file (e.g. syntax errors). - Install `husky` and `lint-staged` as devDeps - `package.json`: add `"prepare": "husky"` so the hook is wired up on fresh `npm install`; add `lint-staged` config covering js/css/json/ yaml/md (2-space) and xq/xqm/xml/xsd/html/tmpl/xconf/svg (4-space) - `.husky/pre-commit`: runs `npx lint-staged` - `.gitignore`: allowlist `.husky/` past the `.*` rule (but keep `.husky/_` ignored — that's husky's runtime-generated dir) `package-lock.json` is also re-indented from tabs to 2 spaces by this install — npm's lockfile output now respects the project's .editorconfig. Net cosmetic; future `npm install` runs will keep it consistent.
Owner
Author
|
[This response was co-authored with Claude Code. -Joe] Pushed e12c2cb adding the pre-commit hook per your feedback, @duncdrum. Summary of how I'm reading your comment:
The diff is unfortunately noisy because the |
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.
Goals
After noticing eXist-db#796 silently flipped a few lines from spaces to tabs in
src/util.js, we wanted to look at what it would take to enforce a consistent style across the repo automatically — so reviewers don't have to spot indent flips by eye and so contributors get correct formatting from their editor with zero local setup.This PR explores three lightweight, complementary mechanisms plus a demonstration of the effect:
.editorconfig— picked up automatically by VS Code, JetBrains, Vim plugins, etc. Establishes baseline indentation and line-ending rules without requiring any tooling..gitattributes— pinseol=lfso Windows contributors can't introduce CRLF churn.prettier,@prettier/plugin-xml, andprettier-plugin-xquery(used internally by the editor's Format command). This PR exposes that same formatter as a repo-level check.What's in here
Commit 1 — config files only (no source changes)
.editorconfig.gitattributestext=auto eol=lf+ binary file list..prettierrc.jsonxmlSelfClosingSpace: falseso<br/>and<?xml ... ?>emit without the (long-obsolete) XHTML-compat leading space..prettierignorepackage.jsonnpm run formatandnpm run format:check..gitignore.*rule.Landing just commit 1 is essentially free — no source changes, just future safety.
Commit 2 — demo:
npm run formatapplied across the repoThis is the "what would happen if we hit the button" commit. 143 files changed, ~31.6k inserts / ~27.2k deletes.
All 179 unit tests pass after the sweep.
How to run the checks
A CI gate (
prettier --check .in GitHub Actions) is the natural follow-up — soft warning first, then hard fail.Options for landing this
Commits are organized so that we can land just commit 1 (config baseline, no source churn), or both. The big format sweep is optional and deliberately separable. A few plausible paths:
.git-blame-ignore-revssogit blameskips the format-only commit on GitHub.Open questions for discussion
prettier-plugin-xquery(DrRataplan) only supports XQuery 3.1. If we have any 4.0-specific syntax in.xq/.xqmfiles, they need an explicit ignore.lint-staged+ a pre-commit hook so contributors don't have to remember to runnpm run format? Or just rely on CI to nag them?Risk / verification
support/tree are excluded so we don't fight the build pipeline.Credits
Initiated after noticing eXist-db#796 flipped indentation in
src/util.jsfrom spaces to tabs. Cc @duncdrum, @line-o, @wolfgangmm, @dizzzz, @reinhapa for input.🤖 [This PR description was co-authored with Claude Code. -Joe]