GitHub Action
Action ESLint
GitHub Action that runs ESLint on files changed in a Pull Request.
.github/workflows/lint.yml
:
name: Lint
on:
pull_request:
push:
branches:
- master
jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci # or yarn install
- uses: sibiraj-s/action-eslint@v3
with:
token: ${{ secrets.GITHUB_TOKEN }} # optional
eslint-args: '--ignore-path=.gitignore --quiet'
extensions: 'js,jsx,ts,tsx'
annotations: true
Ignore files changed in a PR.
steps:
- uses: sibiraj-s/action-eslint@v3
with:
ignore-path: .eslintignore
ignore-patterns: |
dist/
lib/
The files that are being filtered based on these options are excluded from the set of changed files before being sent to eslint. This feature proves useful in situations where a pull request or commit contains files that should not be linted, thus avoiding the occurrence of ignored file warnings.
You can use this in addition to ignore-path
/ignore-patterns
in eslint-args
.
steps:
- uses: sibiraj-s/action-eslint@v3
with:
eslint-args: '--ignore-path=.gitignore --quiet'
ignore-path: .eslintignore
ignore-patterns: |
dist/
lib/
The working-dir
option can be especially useful when the eslint installation is not located in the root directory.
steps:
- uses: sibiraj-s/action-eslint@v3
with:
working-dir: apps/website
Note: When using this option, options such as ignore-path
will be resolved based on the specified directory and files
outside this folder will be skipped too.
Typically, if you only want to run eslint on all files, this action is unnecessary. However, there are specific situations,
such as when a change is made to the .eslintrc
file, where you may want to lint all files.
steps:
- uses: sibiraj-s/action-eslint@v3
with:
all-files: true
Note: When using this input, if the eslint-args
has the ignore-path
option the input ingore-path
will be ignored
steps:
- uses: sibiraj-s/action-eslint@v3
with:
all-files: true
eslint-args: '--ignore-path=.gitignore --quiet'
ignore-path: .eslintignore # will be ignored since ignore-path is already given in eslint-args
Example to Run lint on all files when .eslintrc
changes
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
eslintrc:
- '.eslintrc*'
# run eslint on all files if eslintrc changes
- name: Run eslint on changed files
if: steps.filter.outputs.eslintrc == 'false'
uses: sibiraj-s/action-eslint@v3
with:
all-files: ${{ steps.filter.outputs.eslintrc == 'true' }}
For better security it is recommended to pin actions to a full length commit SHA.
Read more on using third-party actions
- Yarn 2+ is not supported
To enable debug logs, set secret ACTIONS_STEP_DEBUG
to true
. Refer docs more details
https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging