Home > front end >  How to setup eslint to lint everything between master branch and HEAD
How to setup eslint to lint everything between master branch and HEAD

Time:11-03

I'm trying to setup GitHub action to check for lint errors and fail the pull request if any error/ warnings detected.

Currently my logic works locally but when I try to run it via GitHub action, I get an error:

fatal: ambiguous argument 'origin/master...HEAD': unknown revision or path not in the working tree.

I believe it's something to do with checkout@v2 not fetching the right amount of data, But I cant get my head around what

Code Sample

name: Initiate PR
on: push
jobs:
  STEPS:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 100
      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14.18.0
      - name: Install Node.js dependencies
        run: npm ci --ignore-scripts
      - name: lint-on-PR
        shell: bash
        run: |
          npx eslint --max-warnings 0 $(git diff origin/master...HEAD --name-only --relative --diff-filter=MATR '***.js' '***.jsx' '***.ts' '***.tsx' | xargs)

CodePudding user response:

You would probably need to do a checkout@v1 as in this example to get all the files.

- uses: actions/checkout@v1
...
- run: git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }}

v2 by default only fetches the sha that triggered the action.

  • Related