Lint Gates That Block Merge
Take one task-board application from local tests to a real delivery pipeline: continuous integration fundamentals, push and pull-request quality gates, lint, type-check, unit, component and end-to-end gates, dependency caching, matrix builds, artifacts and checksums, secrets and supply-chain security, release promotion, staging and production, rollback and observability.
What you will be able to do
#- Explain what linting proves and what it does not.
- Recognize commands that swallow failures and disable a gate.
- Introduce a lint gate to a legacy codebase with a ratchet.
Overview
#Lint as a gate
Linting is static analysis of source text. It catches unused variables, unreachable code, forbidden patterns and formatting drift without running the program. In CI it is the fastest gate, so it belongs first: a lint failure should stop the pipeline before slower stages run.
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: corepack enable && pnpm install --frozen-lockfile
- run: pnpm lint
Exit codes are the contract
A step passes when its command exits with status 0 and fails on any non-zero status. Two mistakes break the gate. First, swallowing the failure with || true, which turns a failing lint into a passing step. Second, running the linter in fix mode, which rewrites files on the runner and hides the problem instead of reporting it.
Formatting versus linting
A formatter answers "is the code shaped the way we agreed". A linter answers "is the code free of suspicious constructs". Both belong in CI. Run them in check mode, not write mode, so the pipeline reports a diff instead of silently changing files.
Introducing a gate to a messy codebase
A legacy repository may have thousands of existing violations. Turning the gate on immediately blocks all work. Instead, ratchet: start in warn-only mode, then fail only on changed files, then fail on the whole tree once the baseline is clean. Record the ratchet so the tightening is intentional.
The browser sandbox boundary
The playground can run a JavaScript linter over a small string in the browser. It cannot run the project's full native lint toolchain across a repository. An exercise that shows pnpm lint is authored configuration; the sandbox does not execute it.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Implement
Add a lint job that installs dependencies and runs pnpm lint, and make the job fail when lint reports errors.
starter.yamljobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4Reveal the reference answer
reference.yamljobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: corepack enable && pnpm install --frozen-lockfile - run: pnpm lintAuthored expected output: A lint job with checkout, Node setup, install and a pnpm lint step.
The lint step fails the job on a non-zero exit code. No || true appears, so failures are not swallowed.
Exercise 2Debug
This lint step passes even when linting fails. Fix it.
starter.yaml- run: pnpm lint || trueReveal the reference answer
reference.yaml- run: pnpm lintAuthored expected output: The step runs pnpm lint with no fallback, so a non-zero exit fails the job.
The || true made the shell exit 0 regardless of the linter result, turning the gate into a no-op.
Exercise 3Explain
Explain why a formatting check belongs in CI and not only in an editor.
Reveal the reference answer
reference.textAn editor formatter only affects people who have it configured and who remember to run it. A CI check runs the same rule for every contributor on every change, so drift is caught before merge instead of being corrected later in review.Authored expected output: A correct answer notes that CI enforces the rule uniformly regardless of local setup.
CI is the shared, automated enforcement point. Editor configuration is a local convenience that cannot guarantee consistency.
Exercise 4Interview
How would you introduce a lint gate to a legacy codebase with thousands of existing violations without blocking all work?
Reveal the reference answer
reference.textStart in warn-only mode so violations are visible but non-blocking. Then fail only on files changed in the pull request, using a diff-aware lint step. Track the remaining violation count and tighten to a full-tree gate once the baseline reaches zero. Document the ratchet so the tightening is deliberate.Authored expected output: A staged ratchet from warn-only to changed-files to full-tree.
A big-bang gate on a messy codebase blocks everyone. A ratchet makes the gate real while keeping the team moving.
Common misconceptions
#- A linter proves the program is correct.
- Running the linter in fix mode in CI is the same as checking it.
- || true is harmless.
Follow-up practice
#- cicd-04-typecheck-gates
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.