ataylorme / eslint-annotate-action

A GitHub action that takes ESLint results from a JSON file and adds them as annotated pull request comments
MIT License
88 stars 32 forks source link

Support --report-unused-disable-directives #61

Closed nathan-knight closed 1 year ago

nathan-knight commented 1 year ago

--report-unused-disable-directives doesn't seem to get picked up by the action. I have confirmed that ESLint is detecting and warning about unused disable directives. This is the lint script in my package.json:

"lint": "eslint --cache --report-unused-disable-directives",

Here is how I'm running it in the workflow:

      - name: Lint
        run: yarn lint --output-file eslint_report.json --format json packages
        continue-on-error: true
      - name: Annotate linting results
        uses: ataylorme/eslint-annotate-action@v2
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          report-json: "eslint_report.json"
          fail-on-warning: true

Here is a sample output from linting locally:

{
  "filePath": "<removed>",
  "messages": [
    {
      "ruleId": null,
      "message": "Unused eslint-disable directive (no problems were reported from '@typescript-eslint/no-unused-vars').",
      "line": 10,
      "column": 3,
      "severity": 2,
      "nodeType": null,
      "fix": {
        "range": [
          319,
          380
        ],
        "text": " "
      }
    }
  ],
  "suppressedMessages": [],
  "errorCount": 1,
  "fatalErrorCount": 0,
  "warningCount": 0,
  "fixableErrorCount": 1,
  "fixableWarningCount": 0,
  "source": "<removed>",
  "usedDeprecatedRules": []
}

My guess is that the absence of a ruleId isn't playing well with this: https://github.com/ataylorme/eslint-annotate-action/blob/2450c2aa1460446829f338b254cf49247cb45449/src/getAnalyzedReport.ts#L50

Having support for this would be very helpful since this check lets us catch when a linting directive is no longer needed so we can keep them clean.

ataylorme commented 1 year ago

I'm not familiar with --report-unused-disable-directive but I'm not opposed to supporting it. Feel free to open a pull request

nathan-knight commented 1 year ago

I'm not familiar with --report-unused-disable-directive but I'm not opposed to supporting it. Feel free to open a pull request

Ok I took a stab at it, here's the PR: https://github.com/ataylorme/eslint-annotate-action/pull/62