GitHub Actions: Linting and Typechecking
Linting checks code for mistakes without running it. A lint step runs before the tests, so a simple mistake fails fast.
The lint command
This step runs the lint command from package.json.
- run: npm run lintLint before test
Lint runs first. Tests run only if lint passes.
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm run lint
- run: npm testWhat a lint failure looks like
A file with a missing closing brace fails the check.
function add(a, b) {
return a + b;Example
name: Lint
on: push
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm run lint
- run: npm testKey points
- Linting: checking code for mistakes without running it.
- Lint first, then test. A lint failure stops the run early.
- The demo lint command is npm run lint.
- npm run lint runs node --check on the app and test files.
- node --check reads a file and reports syntax errors.
- Typechecking checks types in typed code. It is the same fail-fast pattern.
- The demo app has no TypeScript, so this lesson shows lint only.
- Linting catches cheap mistakes early. Tests then check what the code does.
In this example, the workflow runs on every push. Checkout downloads the repo. Setup-node installs Node 24. The lint step checks both JavaScript files for syntax errors. The test step runs last, and both tests pass.
Note
A failing lint step turns the run red, just like a failing test.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Why does the lint step run before the test step?