Running ESLint only on staged files

is there any way I can run eslint only the files that appear in my PR? At present this is my job and it runs lint on all the files. However I want to run eslint only on the changed files.

      name: node/default
      - checkout
      - node/install:
          node-version: "14.19.1"
      - run: node --version
      - node/install-packages:
          pkg-manager: npm
      - run:
          command: npm run lint
          name: Run linter
          no_output_timeout: 30m
    # The resource_class feature allows configuring CPU and RAM resources for each job. Different resource classes are available for different executors.
    resource_class: large

Hi @devcer,

There are a couple of ways to do this. You could use the git diff command to identify the modified files and pass them to your linter. It may look something like this

“lint:script”: “eslint -c eslintrc.js $(git diff --name-only --diff-filter=ACMRTUXB master | grep -E "(.js$|.ts$|.tsx$)")”

You could also try installing a package that will do a similar thing for you. More details here

1 Like