tj-actions/eslint-changed-files

[BUG] Reading Wrong Eslint Config File For Mono Repo.

Closed this issue · 1 comments

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

I get the following error message when my action is executed because action is reading service/lambda/bsp/.eslintrc.json file. It should read the eslint file present in the base directory. As i have 200 plus micro services so we can't create seperate eslint config for all of them. but some of the services have eslint config file and when change is made in those services that eslint file is read by action.

Action Config:

name: ESLint Changed Files

on:
  pull_request:
    types: [opened, synchronize, ready_for_review]
    branches:
      - 'sprint/**'

jobs:
  eslint-check:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x] # Define the Node.js version(s) you want the check to run on.
    
    steps:
    - name: Check out code
      uses: actions/checkout@v4
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        fetch-depth: 0
      
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}

    - name: Install dependencies
      run: npm install eslint jest eslint-plugin-jest eslint-plugin-node

    - name: Action Configuration
      uses: tj-actions/eslint-changed-files@v21
      with:
        extra_args: "--fix"
        config_path: ".eslintrc.json"
        skip_annotations: true
        token: ${{ secrets.GITHUB_TOKEN }} # GitHub automatically creates a `GITHUB_TOKEN` secret to use in your workflow.
        file_extensions: |
          **/*.js
          **/*.jsx
          **/*.ts
          **/*.tsx

    - name: Verify Changed files
      if: ${{ ! cancelled() }}
      uses: tj-actions/verify-changed-files@v16
      id: verify-changed-files
      with:
        files: |
          **/*.{js,jsx,ts,tsx}

    - name: Commit outstanding changes
      if: ${{ ! cancelled() && steps.verify-changed-files.outputs.files_changed == 'true' }}
      run: |
        git config --local user.email "github-actions[bot]@users.noreply.github.com"
        git config --local user.name "github-actions[bot]"
        git add ${{ steps.verify-changed-files.outputs.changed_files }}
        git commit -m "refactor: lint fixes"

    - name: Push changes
      if: ${{ ! cancelled() && steps.verify-changed-files.outputs.files_changed == 'true' }}
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.head_ref }}

Action Error

Resolving repository path: /home/runner/work/respond-io/respond-io/.
  Running ESlint on changed files...
  
  Oops! Something went wrong! :(
  
  ESLint: 8.55.0
  
  Error: service/lambda/bsp/.eslintrc.json:
  	Environment key "jest/globals" is unknown
  
      at /home/runner/work/respond-io/respond-io/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23

To Reproduce

Create a microservice and add eslint config file in that as well, but point the eslint file present in base directory. then you will see that eslint is reading service config file.

What OS are you seeing the problem on?

ubuntu-latest or ubuntu-22.04

Expected behavior?

It should read base directory eslint not the service level eslint config and should not crash.

Relevant log output

Resolving repository path: /home/runner/work/respond-io/respond-io/.
  Running ESlint on changed files...
  
  Oops! Something went wrong! :(
  
  ESLint: 8.55.0
  
  Error: service/lambda/bsp/.eslintrc.json:
  	Environment key "jest/globals" is unknown
  
      at /home/runner/work/respond-io/respond-io/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23

Has all relevant logs been included?

  • I've included all relevant logs

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Hi @Huzaifa-Asif, this appears to be a bug with eslint configuration system. I’ll suggest creating a bug ticket here.

Helpful Resources

If you are using one configuration file and want ESLint to ignore any .eslintrc.* files, make sure to use --no-eslintrc along with the --config flag.