Skip to content

Latest commit

 

History

History
283 lines (245 loc) · 18.4 KB

CONTRIBUTING.md

File metadata and controls

283 lines (245 loc) · 18.4 KB

Contributing

To report a bug or ask for a feature, open an issue. Say what you did, what you expected, what happened, and the jsonvet version (jsonvet --version). Report a vulnerability as SECURITY.md says, not in an issue.

Set up

Clone with --recurse-submodules and install the tools in mise.toml (mise install), plus Rust from rustup. Then run just setup once. It fetches the json5-tests submodule and installs the git hooks with prek, including a commit-msg hook that checks each commit's sign-off, so commit with git commit -s (why). just --list shows every task.

Some checks need tools that mise.toml does not install:

Tool For
valgrind and gungraun-runner just counts and just scaling (Linux only)
samply, perf just profile and just counters (perf: Linux only)
wasm-bindgen-cli and wasm-opt just playground
docker just matrix
pnpm (Node comes from mise.toml) just vsix, just playground and the vscode job
cargo-release releasing

Checks

Run just check before you open a pull request. It runs CI's lint and test jobs on your OS: formatting, clippy, rustdoc, cargo deny, ruff, zizmor, the version check, the conformance page check, and the tests with doctests. The page check fails while README.md, docs/conformance.md or docs/conformance.json has unstaged edits, so stage them first. zizmor runs its online audits only when GH_TOKEN is set, so without it just lint can pass where CI fails.

just check leaves out these jobs in ci.yml:

  • test on the other two OSes, with clippy there too, since code behind cfg(unix) or cfg(windows) warns only on its own OS. On macOS it also runs scripts/test-action.sh, the Action script's tests, under bash 3.2. Run bash scripts/test-action.sh yourself when you change scripts/action.sh.
  • msrv, scaling, bench and differential: just msrv, just scaling, just counts and just differential.
  • vscode, the extension in editors/vscode: cd editors/vscode && pnpm install --frozen-lockfile && pnpm run check && pnpm test && pnpm run build. The job also runs the docs pages' tests (pnpm --dir scripts/docs-site test), which build the site and check its links, anchors, old addresses and Content-Security-Policy.
  • hook, action and packaging, which build the wheels and run the hook and the Action as users do.

Other workflows:

  • On a pull request: semver.yml (cargo semver-checks), fuzz.yml (30 seconds a target), coverage.yml (Codecov) and codspeed.yml (benchmarks, only when the crates, Cargo files or SchemaStore fixtures change), and wheels-check.yml (the release wheels, built without an upload, only when Cargo.lock, a Cargo.toml, .cargo/config.toml, the maturin config or the wheel matrix in wheels.yml changes).
  • Every week: fuzz.yml and mutants.yml in full. Every Monday: advisories.yml, so a new RustSec advisory against Cargo.lock fails a run without waiting for a pull request.
  • pages.yml builds and tests the playground on a pull request that touches it or docs/, and deploys it from main. It builds docs/*.md into the site's docs/ pages with Starlight in scripts/docs-site (pnpm test there checks every link, every anchor and every inline script's hash in the page's policy). On a pull request it also keeps screenshots of the page and three docs pages (playground/screenshots.sh: desktop and phone, light and dark) as the playground-screenshots artifact for 14 days, and a comment on the pull request links the newest one. just playground [PORT] does the same build and tests, and serves it at http://127.0.0.1:8000/jsonvet/, or at the PORT you pass.
  • A pull request that touches the playground, is open, not a draft and not from a bot or a fork, also gets a preview at its own jsonvet-playground-pr-<number> Worker on workers.dev (the preview job in pages.yml). preview-retire.yml deletes that Worker when the pull request closes or turns draft, and sweeps daily for strays. It needs the CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID secrets in the preview environment, and skips quietly without them.
  • scorecard.yml rates the repository for the OpenSSF Scorecard badge.

Put each detail of the docs in one place and link to it: the README to get started, docs/usage.md for the reference, docs/design.md for why, and docs/decisions/ for the choices behind it.

Pull requests

main takes changes only through pull requests. Write commit subjects as Conventional Commits, such as fix(parser): reject a lone CR in a JWCC comment. A change in behaviour comes with a test that fails without it, and a bug fix with a test that reproduces the bug. A change that reopens a choice in docs/decisions/ brings the evidence its "Revisit if" asks for. A pull request over 500 changed lines (generated files excluded) gets a CI warning: split a refactor into its own pull request.

Choosing dependencies

Prefer the standard library or a crate the workspace already uses. A new dependency in jsonvet or jsonvet-cli needs a reason in the pull request: what it saves, that it is maintained, and for a speed-up, the measurement 0004 asks for. cargo deny checks that every crate in Cargo.lock comes from crates.io, has a permissive licence and has no RustSec advisory or unmaintained notice. Renovate bumps the pins (schedule); do not bump a pin by hand.

Tests

  • Snapshots. CLI output is tested with insta. Review a .snap diff with cargo insta review, or accept everything with INSTA_UPDATE=always cargo test, then read the diff before you commit.
  • Corpus. tests/corpus/<dialect>/ has one file per case. Its bytes are part of the test, so .gitattributes and the hooks leave it alone. Do not let an editor reformat those files, or those with \uXXXX escapes in tests and snapshots.
  • SchemaStore. tests/schemastore/ holds real schemas with the files SchemaStore's own tests accept and reject, and crates/jsonvet-cli/tests/schemastore.rs checks that jsonvet agrees. Refresh them with uv run scripts/schemastore-fixtures.py <a SchemaStore clone>, and add jsonvet's own cases under a schema's extra/.
  • File lists. A new default extension or file name in the library (Dialect::EXTENSIONS, Dialect::FILE_NAMES) goes into both hooks in .pre-commit-hooks.yaml, scripts/action.sh, and the README's file list and dialect table, or crates/jsonvet-cli/tests/file_lists.rs fails.
  • New rules and dialects. A rule goes in Rule::ALL (crates/jsonvet/src/rule.rs), with a rule.<id>.explanation in crates/jsonvet-cli/src/messages.rs and the same words in a ### <id> section of docs/usage.md, or every_rule_has_help_that_its_docs_section_holds fails. The --help text must name it, or help_names_every_rule_and_dialect fails. A dialect goes in Dialect::ALL (crates/jsonvet/src/dialect.rs) and the --help text. Add either to the README's table.
  • Conformance matrix. just matrix runs one set of inputs through 18 other parsers in docker containers, then renders docs/conformance.md and docs/conformance.json. Commit conformance/results/ and the rendered files. CI fails when the report is stale, or when conformance/results/versions.json disagrees with the pinned parsers. After a pin change, run just matrix-lock first (details).
  • Fuzzing. just fuzz check (or diff_serde_json, diff_json5, parse, fix, config, config_file) runs a target for 20 minutes on a nightly toolchain. A new json5 version in fuzz/ can need new skips in diff_json5: read its skip list before you call a divergence a jsonvet bug.
  • Language server. cargo nextest run -p jsonvet-cli lsp runs the in-process tests. The stdio test is lsp_checks_a_document_over_stdio_and_exits_0_after_shutdown in crates/jsonvet-cli/tests/cli.rs.
  • Mutation testing. just mutants takes over an hour on one CI runner, so mutants.yml runs it weekly in 64 shards, 15 at a time; its shards input reruns only the ones you list. It fails when a mutant survives that .cargo/mutants.toml does not list. List one there only when it changes no behaviour, and say why. On a pull request, mutants-diff.yml runs it on the changed lines only, in eight shards; locally, git diff origin/main... > pr.diff && cargo mutants --in-diff pr.diff does the same.
  • Differential. just differential compares jsonvet with check-json5 1.4.1 on generated files. CI runs 5,000 cases with a new seed each run.
  • Speed claims. Measure with just bench on a quiet machine, and report the median. For a release's speed table, the bench workflow runs it on a GitHub runner instead. To compare two builds, write the fixtures with just profile-files and run hyperfine -N -r 40 on both. Time a change that touches every file on the 10,000-small-file walk too.
  • Instruction counts. just counts counts the instructions of the parser (crates/jsonvet/benches/check.rs) and of whole --schema runs (crates/jsonvet-cli/benches/schema.rs) under callgrind, and prints each case's change since the last run. A change under 0.3% is noise. CI fails a pull request when a case rises by more than 1% over the base branch. Compare two commits with just counts --save-baseline=base on one and just counts --baseline=base on the other. In a Docker container, set GUNGRAUN_ALLOW_ASLR=yes. gungraun-runner must be the gungraun version in Cargo.lock.
  • CodSpeed. CodSpeed comments each pull request's change in time, peak memory and allocations on the divan benchmarks in each crate's benches/codspeed.rs. Its check fails on a slowdown, but it is not a required check, because its path filter would leave docs-only pull requests waiting on it: the bench job is the gate. Neither sees wall time, so time a scanner change with hyperfine -N as well (decision 0004).
  • Profiling. just profile-files writes the bench files and 13 large cases to target/profile-files: one per scanner path (pretty and minified objects, rows, strings, numbers, deep nesting, JSONC, JSON5, JSON Lines) and canada, citm_catalog and twitter from serde-rs/json-benchmark. just profile FILE records call stacks with samply, just counters FILE reads the CPU's counters with perf stat (instructions per cycle, branch and cache misses) on one CPU, and just threads times the small files on 1 to 8 CPUs. just core=2 compare main builds main in a temporary worktree and prints a table of instructions on the 13 cases, main against your working tree; a change under 0.1% is noise. All four use the profiling build: release code with line tables and frame pointers. The counters need perf access to the hardware, which CI runners and most containers lack, so they guide a change; just counts still decides it.
  • Scaling. just scaling runs crates/jsonvet-cli/tests/scaling.rs under valgrind, on Linux only. Each test counts the instructions on an input of size n and 10n. Most fail when the ratio reaches 15 (linear gives about 10): duplicate keys on many lines and on one long line, --schema on keys with lone surrogates and on many $refs by $id, json5's hex numbers in the diff_json5 target, and a walk with many exclude and dialects patterns. Two fail unless the count stays within twice: schema errors past the first 100, and keys too costly for a pattern past the first 100.

Translations

Messages people read live in two tables of ids and English text: MESSAGES in crates/jsonvet/src/messages.rs for problem messages, and ENGLISH in crates/jsonvet-cli/src/messages.rs for everything else the command says, plus rule.<id>.description for each rule. To add a language, write crates/jsonvet-cli/locales/<locale>.toml, such as de.toml or pt_BR.toml, with a "id" = "text" line for each id you translate, keeping every {name} in it. A count has two ids, such as summary.files.one for 1 and summary.files.other for any other number; the .one text may leave out {count}. build.rs bundles every file there, so nothing else changes.

  • Format. Each text is a TOML string: \n is a line break, \" a quote, and """ starts a text over several lines. Quote every id: rule.syntax.explanation = "..." without quotes is a TOML table, and the file is not used. # starts a comment. help is the whole --help text, layout included.
  • Check. cargo nextest run -p jsonvet-cli messages fails on a file that does not parse, an unknown id, or a text with other {name}s than its English one. At run time a broken file gives English, with no warning.
  • Try it. LC_ALL=de cargo run -q -p jsonvet-cli -- file.json shows the text output in German. jsonvet reads LC_ALL, then LC_MESSAGES, then LANG, and pt_BR.UTF-8 takes pt_BR.toml, else pt.toml. It does not read LANGUAGE or the Windows language setting.
  • What stays English. The JSON and SARIF documents, rule ids, severities, JSONPaths and exit codes, and the text of other crates: jsonschema's validation messages, TOML syntax errors, argument errors and operating system errors (0013).

A new message gets an id in one of the tables, never a string in the code.

Releasing

A release changes the version in these places, in one commit on a branch:

  1. version in the root Cargo.toml, and Cargo.lock with it
  2. the =x.y.z pin on jsonvet in crates/jsonvet-cli/Cargo.toml
  3. the pin in setup.py
  4. version and the jsonvet== pin in compat/check-json5/pyproject.toml
  5. version in editors/vscode/package.json
  6. rev: vX.Y.Z in the hook examples in README.md, docs/usage.md and docs/format.md
  7. in CHANGELOG.md, the Unreleased entries moved under a new ## [X.Y.Z] - date heading, and the compare links at the bottom

cargo-release makes all of them. It only bumps and commits, and refuses to run on main (0011). Write the Unreleased entries first; the release commit only moves them. Every figure in a release's CHANGELOG section compares with the last release.

git fetch && git switch -c release/X.Y.Z origin/main
cargo release X.Y.Z                       # dry run: shows every change
SKIP=dco-signoff,check-versions cargo release X.Y.Z --execute   # commits "chore: release X.Y.Z"
git commit --amend -s --no-edit           # cargo-release cannot sign off
git push -u origin release/X.Y.Z          # a new minor only: the speed table, from bench.yml
gh workflow run bench.yml --ref release/X.Y.Z
gh run download <run-id> -n speed-table && git apply speed-table.patch
git commit -s -m "docs: speed figures for X.Y" -- docs/design.md README.md
just matrix                               # records the new version in the matrix
git commit -s -m "docs: re-run the conformance matrix for X.Y.Z" -- docs/conformance.md docs/conformance.json README.md conformance/results
uv run scripts/check-versions.py
git push -u origin release/X.Y.Z          # then open the pull request
gh pr checks                              # the `wheels / wheels (...)` rows must be green
                                          # then squash-merge it
git switch main && git pull --ff-only
git log -1 --oneline                      # must be "chore: release X.Y.Z (#NN)"
git tag -s vX.Y.Z -m vX.Y.Z               # signed with your git signing key
git verify-tag vX.Y.Z && git push origin vX.Y.Z

The tag is signed, so GitHub shows it as verified and anyone can check it with git verify-tag. cargo-release prints a "Publishing" line, but it publishes nothing.

Do not create the GitHub release by hand. The tag runs release.yml, which builds, attests and publishes everything (design.md). Each publish job waits for an approval: the pypi environment twice (the wheels, then check-json5) and crates-io once. If a publish job fails, use "Re-run failed jobs", never "Re-run all jobs". A full re-run builds the wheels again, so PyPI and the GitHub release could hold different builds.

"Re-run failed jobs" uses the workflow file at the tagged commit, so a fix to a workflow needs a new commit and a moved tag. Which way depends on how far the release got:

  • Nothing is on PyPI yet (a wheels row, smoke or github-release failed). Fix main through a pull request. Delete the remote tag with git push origin :refs/tags/vX.Y.Z, then sign and push the tag again on the new release commit, as above. github-release replaces a leftover draft for the same tag and refuses a published release, so the old draft needs no cleanup.
  • PyPI already has a file. Never move the tag. Ship a patch version.

The release pull request changes Cargo.toml and Cargo.lock, so wheels-check.yml builds the wheels on it. Look at its wheels / wheels (...) checks before you tag. They cannot be required checks, because the workflow only runs for some paths.

A pre-release has a - in its tag (v3.1.0-rc.1). cargo-release bumps only the crates for one. Edit the other places by hand, with the PEP 440 form (3.2.0rc1) in setup.py and the compatibility package.

Once the release is published, run just major. It moves the major tag (v3), which uses: simonvanlierde/jsonvet@v3 follows, to the newest vX.Y.Z, so a pre-release or a patch to an older minor leaves it alone. The workflow's token cannot move a tag past changes to .github/workflows/, and one that could would give CI write access to the workflows.

Sign off your commits

Every commit in a pull request carries a Signed-off-by: line, which says you wrote the change or have the right to submit it under the MIT and Apache-2.0 licenses: the Developer Certificate of Origin 1.1. git commit -s adds it. git rebase --signoff upstream/main adds it to commits you already made. The DCO sign-off check fails any pull request with a commit that lacks it, the maintainer's and Renovate's included.

Who maintains this

GOVERNANCE.md names the maintainer, who can publish each package, and what happens if the maintainer is unavailable. docs/roadmap.md says what is planned.