← github actions
Views:
Linting check for Pull Requests
We can write a workflow to automate and check for linting issues in a pull request. This is a very common and widely used workflow. To get this setup, we need linter in our project, and in this example we'll see how to make it work in a javascript project with ESLint.
- Install ESLint (if not already) in your project.
- Add/Update your eslint config file as per you want.
- Add lint script in your package.json to check for linting issues.
{
// ...
"scripts": {
// ...
"lint": "eslint src/ --quiet"
}
}
Workflow for Linting check for Pull Requests
name: Code Linting Check
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
jobs:
lint-check:
runs-on: ubuntu-latest
name: Check PR's Linting
steps:
- uses: actions/checkout@v1
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install deps (with cache)
uses: bahmutov/npm-install@v1.7.10
with:
working-directory: "./"
useLockFile: false
- name: eslint check
run: npm run lint
Result
Here's the result for above workflow, you can also view it on 5f7cc85 commit.
