3

We are building a bitbucket pipeline for a React Project. We have pre-commit hooks setup which does linting only on staged files. How can I achieve the same in bitbucket pipelines, when a pull request is raised it get the diff files, and check the linting for those files only.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 01 '22 at 08:36

1 Answers1

2

As described in this thread, as long as you are using a Docker node image, in which you can install and run ESLint, you should be able to add it to your BitBucket pipeline.

Make sure your pipeline is set to run only on PR:

pipelines:
  pull-requests:
    '**': #this runs as default for any branch not elsewhere defined
      - step:

Example: bitbucket-pipelines.yml (to be tweaked to your specific project)

pipelines:
  pull-requests:
    '**':
      - step:
          name: Eslint for pull-request
          image: node:12.14
          condition:
            changesets:
              includePaths:
                - resources/assets/js/**
          script:
            - printenv
            - CAN_RUN_PIPELINE=$(test -f code_review/eslint/index.js && echo true || echo false)
            - if [ "$CAN_RUN_PIPELINE" != true ]; then exit; fi
            - git checkout origin/$BITBUCKET_PR_DESTINATION_BRANCH
            - git merge origin/$BITBUCKET_BRANCH --no-edit
            - git reset $BITBUCKET_PR_DESTINATION_COMMIT
            - git add .
            - git status
            - npm i -g eslint
            - npm install --only=dev
            - npm install axios dotenv --save-dev
            - eslint --format json -c code_review/eslint/rules.js -o ./code_review/eslint/output/output.json --ext .js,.jsx,.vue ./resources || true
            - node ./code_review/eslint/index.js $REVIEW_AUTH_STRING
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250