This document defines the repository-wide quality and security checks used by GitHub Actions and local Git hooks. It is the source of truth for what is scanned, when a check passes or fails, how to reproduce it, and how developers should handle findings.
The workflow is .github/workflows/code-quality.yml. It runs on:
- Every pull request targeting
main. - Every push to
main. - Manual execution through Actions → Code Quality → Run workflow.
The scanners inspect the project or the configured source/lockfile scope, not only the files changed in a pull request. This is intentional: unused code, duplicated code, secrets, and vulnerable transitive dependencies may be outside the PR diff.
The Node-based jobs use Node.js 22, matching this repository's engines requirement and runtime baseline.
The workflow has seven independent jobs:
- ESLint — lint and framework rules.
- Knip — unused files, exports, and dependencies.
- jscpd — duplicated source code.
- Semgrep — static security analysis.
- Production build — production compilation using an isolated mock API.
- Gitleaks — secrets in repository files and Git history.
- OSV-Scanner — known dependency vulnerabilities in
package-lock.json.
There are no needs dependencies between these jobs. A failed scanner must not prevent the other scanners from running and reporting their results.
The workflow passes only when every job passes. Any failed job makes the overall workflow fail. The workflow does not use continue-on-error to hide findings, does not turn scanners into warning-only checks, and does not silently ignore existing project debt.
A failed job has one of two broad meanings:
- Finding/policy failure: the tool ran and reported something that violates its configured policy.
- Execution failure: the tool could not complete because of installation, configuration, permissions, network, runner, or environment problems.
Open the job log to distinguish these. A red workflow does not by itself mean that the application is broken, and a static-analysis finding is not automatically proof of an exploitable vulnerability.
Command: npm run lint (runs eslint .).
Configuration: eslint.config.mjs, using the native ESLint flat-config exports from eslint-config-next/core-web-vitals and eslint-config-next/typescript.
Why this is configured this way: This repository uses Next.js 16. Next.js 16 removed the next lint command, and next build no longer runs lint automatically. The supported setup is the ESLint CLI with a flat config.
Scope: JavaScript, JSX, TypeScript, and TSX files covered by the Next.js ESLint configuration. Generated output, dependency folders, and test/build artifacts listed in the flat config are ignored.
What it checks:
- Common JavaScript/TypeScript mistakes and suspicious patterns.
- React and React Hooks rules.
- Next.js rules, including Core Web Vitals-related rules.
- TypeScript-specific lint rules from the Next.js configuration.
Pass: ESLint completes and exits with code 0.
Fail: ESLint reports errors, or the CLI/configuration cannot execute. Warnings fail only if the active configuration or command treats them as errors.
How to fix: Read the rule ID and file/line in the log, then fix the underlying code. Do not disable a rule globally to make CI green. Any suppression must be narrow, justified, and documented.
Command: npx --yes knip --no-progress.
Scope: The project, based on Knip's detected entry points and configuration.
What it checks:
- Unused files.
- Unused exports.
- Unused production dependencies.
- Unused development dependencies.
- Dependencies used in code but not declared in the appropriate manifest.
Pass: Knip completes without findings that cause a non-zero exit code.
Fail: Knip reports items that violate its configured checks, or it cannot analyze the repository.
How to review findings safely:
- Verify whether the file, export, or package is genuinely unused.
- Check dynamic imports, framework conventions, route discovery, scripts, build configuration, runtime registration, and deployment usage that static analysis may not infer.
- Remove genuinely dead code or dependencies only after confirming they are not used indirectly.
- Add a genuinely used but unlisted dependency to the correct dependency section.
- For intentionally retained items, use a narrow and documented Knip configuration exception where appropriate.
A Knip result is a review candidate, not an instruction to delete every reported item automatically.
Command:
npx --yes jscpd src --min-lines 5 --min-tokens 50 --threshold 5 --reporters consoleScope: The complete src/ directory.
Configured criteria:
- Minimum duplicate fragment: 5 lines.
- Minimum duplicate fragment: 50 tokens.
- Maximum allowed duplication: 5%.
- CI output: console reporter.
What it checks: Repeated source fragments that may indicate copy/paste implementation, inconsistent fixes, or an opportunity to share a component, hook, utility, or module.
Pass: Detected duplication is at or below 5%, and jscpd exits successfully.
Fail: Duplication exceeds 5%, or the scanner cannot complete.
How to fix: Review the reported fragments in context. Extract shared behavior only when the abstraction improves clarity and does not introduce inappropriate coupling. Similar-looking code may intentionally implement different behavior. Generated or intentionally repetitive files should be excluded only through a narrow, documented rule.
Command:
semgrep scan --config p/react --config p/security-audit --error srcScope: The complete src/ directory.
Rule packs: Semgrep p/react and p/security-audit.
What it checks: Static patterns associated with React-specific security risks and broader security-sensitive code, such as unsafe HTML rendering, injection risks, and suspicious data flows covered by the selected rule packs.
Pass: Semgrep completes and reports no findings that cause a non-zero exit code.
Fail: A configured rule matches code and Semgrep exits non-zero, or Semgrep cannot install/run/load the rules.
The --error option is intentional. Findings are blocking; this is not a warning-only scan.
How to investigate:
- Read the rule ID, severity, message, and exact source location.
- Trace the value from its origin to the reported sink.
- Determine whether the data is trusted, user-controlled, validated, encoded, or sanitized.
- Verify that any sanitizer is appropriate for the exact output context and is applied to the exact value reaching the sink.
- Prefer a safe API or a correct context-specific sanitization/encoding fix.
- Add tests for security-sensitive behavior when appropriate.
A finding is a security signal that needs triage, not automatic proof of exploitability. A clean scan is also not proof that the application has no security vulnerabilities.
If a match is demonstrably a false positive, document the evidence and use only a narrowly scoped inline suppression or specific exception. Do not disable an entire rule pack or source directory to obtain a green check.
Command: npm run build (runs next build --webpack).
Scope: The complete Next.js production build.
Environment: The CI job uses disposable mock values and starts scripts/mock-api-server.mjs on localhost. It copies .env.example to .env.local and points the configured API/Supabase endpoints to the local mock service. No production credentials should be used by this job.
What it checks:
- Next.js production compilation and bundling.
- Route and module compilation.
- Build-time configuration and import errors.
- Build-time code paths that execute during the production build.
Pass: The production build completes and exits with code 0.
Fail: Compilation, bundling, or build-time execution fails, or the isolated mock environment cannot start.
How to fix: Reproduce the build using the documented isolated environment, inspect the first meaningful error, and correct the underlying source/configuration issue. A successful build does not replace linting, tests, security analysis, or runtime/browser validation.
CLI: Gitleaks v8.30.1, installed from the official GitHub release. The workflow verifies the downloaded Linux x64 archive against its published SHA-256 digest before installing it.
Command: gitleaks git --redact --verbose ..
Scope: Repository Git history. CI checks out the full history with fetch-depth: 0.
What it checks: Secret-like patterns such as API tokens, passwords, private keys, and other credentials accidentally committed to the repository.
Pass: Gitleaks completes without an unaccepted secret finding.
Fail: A potential secret is detected, or the CLI cannot be downloaded, checksum-verified, installed, or executed.
Required repository configuration: No Gitleaks license secret is required because CI runs the official open-source CLI directly. The pinned release archive is checksum-verified before execution.
How to handle findings:
- Treat a detected credential as potentially exposed until verified.
- Identify the service/account and determine whether the credential is real and active.
- Revoke or rotate a real credential immediately. Deleting it from the latest commit is not sufficient.
- Remove it from source and store replacement credentials in an approved secret manager or GitHub Actions secret.
- Follow the repository's history-cleanup and incident process if a secret was committed.
- For a confirmed false positive, use a narrow documented allowlist entry.
Removing a credential from Git history does not replace revoking it.
Workflow: Google's reusable OSV-Scanner workflow pinned to google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@v2.7.1.
Input: package-lock.json, including the resolved dependency graph.
Configuration:
fail-on-vuln: trueupload-sarif: true
What it checks: Known vulnerabilities in dependency versions recorded in the npm lockfile, including transitive dependencies.
Pass: The scanner completes and no vulnerability triggers the configured failure policy.
Fail: A vulnerability is reported under the current policy, or the scanner cannot complete/upload its configured results.
How to remediate:
- Identify the package, resolved version, advisory ID, and affected version range.
- Check whether a fixed release exists.
- Update the direct dependency or the parent package responsible for a vulnerable transitive dependency.
- Regenerate and commit
package-lock.json. - Run relevant tests and the production build, then rerun OSV-Scanner.
- If no safe fix is available, document the exposure, owner, mitigation, and review date. Do not turn off
fail-on-vulnto hide the finding.
An OSV finding identifies a known vulnerable dependency version; assess reachability and application impact, but do not silently ignore the advisory.
Use Node.js 22 and npm, matching the CI environment.
npm cinpm run lint
npx --yes knip --no-progress
npx --yes jscpd src --min-lines 5 --min-tokens 50 --threshold 5 --reporters console
npm run buildFor the production build, use the isolated environment and mock API described in Phase 1 environment and execution. Do not use production secrets in a local test environment.
Install Semgrep using the official installation instructions: https://semgrep.dev/docs/getting-started/.
For example, with pipx:
python -m pip install --user pipx
python -m pipx ensurepath
python -m pipx install semgrep
semgrep scan --config p/react --config p/security-audit --error srcRestart the terminal if needed so the pipx executable directory is on PATH.
Install Gitleaks v8.30.1 using the official instructions: https://github.com/gitleaks/gitleaks.
From the repository root:
gitleaks git --redact .CI downloads the official Linux x64 release and verifies its SHA-256 digest before scanning. No organization license secret is required for this CLI-based job.
Install OSV-Scanner using its official instructions: https://github.com/google/osv-scanner.
From the repository root:
osv-scanner scan --lockfile=./package-lock.jsonInstall the Lefthook CLI using the official instructions: https://lefthook.dev/installation/.
Then, from the repository root, run once per clone:
lefthook installThe repository's lefthook.yml defines:
- pre-commit: ESLint on staged JavaScript/TypeScript files.
- pre-push: ESLint, Knip, jscpd, Semgrep, Gitleaks, and OSV-Scanner.
The pre-push hook requires the corresponding CLIs to be installed and available on PATH. Lefthook is a local developer safeguard; GitHub Actions remains the authoritative shared CI result.
For reliable CI operation:
- Gitleaks uses the pinned official CLI release and does not require an organization license secret.
- Keep the workflow's
security-events: writepermission so OSV SARIF upload can work. - After the first successful workflow run, inspect the exact check names shown in GitHub and configure the desired jobs as required checks for
main. - Do not require a check name that GitHub has not actually reported.
The Code Quality workflow is separate from the existing unit, integration, Playwright, SEO, and isolated-test workflow. Those existing test workflows are not replaced by these scans.
- Open the PR's Checks tab and allow all independent jobs to finish.
- Inspect every failed job; do not stop at the first failure.
- Classify each result as a finding or an execution/infrastructure failure.
- Review the evidence and fix the underlying issue.
- Do not assume every static-analysis match is a confirmed vulnerability, but do not suppress it without evidence.
- Push the correction to the same PR; the workflow will run again.
- Confirm that all required checks pass and request the required code reviews.
The first run may reveal pre-existing technical debt unrelated to the current PR. Record and assign those findings so they can be addressed. Do not hide them by disabling scanners or weakening thresholds without a reviewed policy change.
- Do not add
continue-on-errorto scanner jobs to make the workflow green. - Do not set OSV
fail-on-vulntofalse. - Do not disable Semgrep rule packs or exclude broad source directories without a documented technical reason.
- Do not broadly ignore Gitleaks findings.
- Do not raise the jscpd threshold merely to conceal existing duplication.
- Keep the jobs independent so one failure does not hide the results of other checks.
- Keep this document synchronized with workflow commands, scopes, thresholds, action versions, and pass/fail behavior.
Passing these checks means only that the configured checks passed for that commit. It is not a guarantee that the application is defect-free and does not replace code review, functional tests, threat modeling, or runtime monitoring.