# Contributing Guide

This project keeps the build/test tooling and documentation in lockstep. Use this guide as a checklist before opening a pull request.

## Environment & Tooling

- Install the .NET SDK pinned by `global.json` (currently 10.0.100 with latest-minor roll-forward).
- Install Python 3.10+ (CI uses 3.12) and restore the shared tooling dependencies once per clone:
  ```bash
  python -m pip install -r requirements.tooling.txt
  ```
- Restore local dotnet tools once per checkout:
  ```bash
  dotnet tool restore
  ```
- Enable the shared pre-commit hook so auto-fixes run before every commit:
  ```bash
  bash ./scripts/dev/install-hooks.sh
  ```

## Build & Test Commands

- Full solution build: `dotnet build src/NovaSharp.sln -c Release`
- Interpreter-only build: `dotnet build src/runtime/WallstopStudios.NovaSharp.Interpreter/WallstopStudios.NovaSharp.Interpreter.csproj`
- Interpreter tests (Release): `./scripts/test/quick.sh`

To inspect a built assembly, run `dotnet tool run ilspycmd -- path/to/assembly.dll`.
The manifest selects the managed ILSpy package so the command also runs on Debian 12.
The native Linux x64 package requires glibc 2.38 or later.

## Coverage

- PowerShell (Windows/Linux/macOS with PowerShell):
  ```powershell
  DOTNET_ROLL_FORWARD=Major pwsh ./scripts/coverage/coverage.ps1
  ```
- Bash fallback (macOS/Linux without PowerShell):
  ```bash
  DOTNET_ROLL_FORWARD=Major bash ./scripts/coverage/coverage.sh
  ```
- Coverage artefacts land in `artifacts/coverage/` and `docs/coverage/latest/`. Update the benchmark or coverage documentation when the baseline changes; retain a PLAN item only while follow-up is selected and active.

## Branding & Namespace Guards

- Reject accidental regressions to the legacy brand:
  ```bash
  ./scripts/branding/ensure-novasharp-branding.sh
  ```
- Keep namespaces aligned with the directory structure before pushing:
  ```bash
  python3 tools/NamespaceAudit/namespace_audit.py
  ```
  Fix mismatches (or update the allowlist intentionally) until the script passes.
- Confirm PascalCase naming (files/types) matches `.editorconfig` / C# style:
  ```bash
  python3 tools/NamingAudit/naming_audit.py
  ```
  The script flags non-conforming identifiers with file/line hints. Address the issues or update the allowlist when the names are intentionally generated.
- Keep comments, docs, and diagnostic strings in plain English:
  ```bash
  python3 tools/SpellingAudit/spelling_audit.py --write-log docs/audits/spelling_audit.log
  ```
  This wraps `codespell` with the repository allowlist so you can fix or intentionally document any new wording before CI runs the audit.

## Formatting & Pre-commit Hooks

- The shared pre-commit hook (`bash ./scripts/dev/pre-commit.sh`) runs automatically once `scripts/dev/install-hooks.sh` has been executed and the Python tooling requirements are installed. It performs the following before each commit:
  - `dotnet tool restore` and `dotnet tool run csharpier format .` (auto-fix all C# files).
  - `python scripts/ci/format_markdown.py --fix --files <staged markdown>` to keep Markdown deterministic.
  - `python scripts/ci/check_markdown_links.py --files <staged markdown>` to ensure links stay healthy.
  - `python scripts/lint/check-tooling-consistency.py` to keep the devcontainer, hooks, CI, `global.json`, and local .NET tool manifest aligned.
  - Restages the results so your commit includes the auto-fixes.
- Run the hook manually if you need to double-check formatting outside of a commit:
  ```bash
  bash ./scripts/dev/pre-commit.sh
  ```
- CI enforces the same rules via `scripts/ci/check-csharpier.sh` and `scripts/ci/check-markdown.sh`; when it fails on a repo-owned PR branch, the pipeline publishes an auto-fix PR (generated from `scripts/ci/apply-formatters.sh`) that you can merge into your branch.

## Updating Scripts & Docs

- New helper script? Place it under the appropriate `scripts/<area>/` folder, update `scripts/README.md` and the subfolder README, then mention it in `docs/README.md` if it affects contributors.
- New or updated documentation? Link it from `docs/README.md` and the repo `README.md` (Additional Documentation section). The PR template checks for this.

## Pull Request Checklist

Before opening a PR:

1. Run `dotnet build src/NovaSharp.sln -c Release`.
1. Run the interpreter tests (see above).
1. Run coverage if your change affects runtime/tooling behaviour.
1. Run the branding + namespace scripts.
1. Ensure formatting hooks have run (or run `dotnet tool restore` + `dotnet tool run csharpier format .` + `python scripts/ci/format_markdown.py --check --all` + `bash ./scripts/ci/check-markdown.sh` manually) so CI doesn't reject style issues.
1. Update relevant docs (`docs/README.md`, `docs/Testing.md`, feature-specific guides).
1. Record completed milestone evidence in the current `progress/` session and remove the finished PLAN item; update PLAN only when actionable follow-up remains.

Report each command you ran and whether it passed. If a check or PR CI was not run, mark it as `not run` and residual risk instead of describing the PR as green.
