Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the ESLint annotations? #96

Open
Couto opened this issue Dec 18, 2019 · 7 comments
Open

How to use the ESLint annotations? #96

Couto opened this issue Dec 18, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@Couto
Copy link

Couto commented Dec 18, 2019

It's my first time using the annotations feature, so please forgive me if this issue is irrelevant.

I'm trying to have annotations in the PR, however all I can get is a simple annotation in the actions screen with irrelevant information. I'm guessing that's a problem of mine, and since there's not a lot documentation (that I could find) about this might as well ask.

Screenshot 2019-12-18 at 09 39 49

That's the output of a failing eslint job. The current configuration is:

  quality:
    needs: [build]

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1

      - uses: actions/setup-node@v1
        with:
          node-version: "12.x"

      - name: Cache node modules
        id: cache
        uses: actions/cache@v1
        with:
          path: node_modules # npm cache files are stored in `~/.npm` on Linux/macOS
          key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install Dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: npm ci

      - name: Prettier
        run: npm run fmt:check

      - name: ESlint
        run: npm run eslint:github-action

where my package.json looks like:

  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.12.0",
    "@typescript-eslint/parser": "^2.12.0",
    "eslint": "^6.7.2",
    "eslint-config-prettier": "^6.7.0",
    "prettier": "^1.19.1",
    "serverless-dynamodb-local": "^0.2.38",
    "serverless-offline": "^5.12.1",
    "serverless-plugin-typescript": "^1.1.9",
    "typescript": "^3.7.3"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "lint": "eslint functions/**.ts",
    "eslint:github-action": "eslint functions/**",
    "fmt": "prettier --write ./**.{json,js,ts,yml,md}",
    "fmt:check": "prettier --check ./**.{json,js,ts,yml,md}"
  },

I expected that the following error would actually appear in the annotation, and hopefully in the PR too.

 /home/runner/work/utom.is/utom.is/functions/a.ts
  1:0  error  Parsing error: Declaration or statement expected

but as you can get the from screenshot, all I have is that the process completed with error 1.

Is my expectation wrong? Or do I have something misconfigured?

Thanks

@Couto
Copy link
Author

Couto commented Dec 21, 2019

Just as a FYI, I've also tried with the eslint --format=compact and eslint --format=stylish with no luck.

@Couto
Copy link
Author

Couto commented Dec 22, 2019

After some investigation:

Currently the error matchers require that ESLint errors have an error code in them:

{
  "regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
  "file": 1,
  "line": 2,
  "column": 3,
  "severity": 4,
  "message": 5,
  "code": 6
}

However, not all ESLint error messages have associated codes, specially if it's invalid JavaScript like:

const a = (a: number, b: number): number => a + b;

export const handler = () => {
  make javascript fail again
  async function foo(things) {
    const results = [];
    for (const thing of things) {
      // Bad: each loop iteration is delayed until the entire asynchronous operation completes
      results.push(await bar(thing));
    }
    return baz(results);
  }
};

The script above will result in the following error message:

> @1.0.0 eslint /home/runner/work/
> eslint --format=compact functions/**.ts

/home/runner/work/functions/a.ts: line 4, col 7, Error - Parsing error: ';' expected.

1 problem
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] eslint: `eslint --format=compact functions/**.ts`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] eslint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2019-12-22T21_43_16_956Z-debug.log
##[error]Process completed with exit code 1.

While it has line and column, it has no error code associated.

@bryanmacfarlane
Copy link
Member

The action could potential only register the problem matcher is it detects an eslint config file ...

@jsg2021
Copy link

jsg2021 commented Jul 6, 2020

Could the code capture group be made optional? so it still matches?

@Couto
Copy link
Author

Couto commented Aug 5, 2021

I might be wrong, but as a consequence of this, this action doesn't create annotations for typescript/* and react-hooks/* ESLint warning/errors.

Which means that it doesn't annotate around 80% of real-world linting messages.

@zomars
Copy link

zomars commented Mar 9, 2022

Yeah, I'd had to use the ataylorme/eslint-annotate-action and generate my own reports since I've thought that setup-node just didn't support it. I'm using a monorepo BTW which make the console output non-standard. So there's that as well...

@domdomegg
Copy link
Contributor

A regex such as:

(?:^|\s)([^\s].+):\sline\s(\d+),\scol\s(\d+),\s(Error|Warning|Info)\s-\s(.+)(?:\s\((.+)\))?

Would likely fix this. I can raise a PR if people are happy with this.

krzyk pushed a commit to krzyk/setup-node that referenced this issue Apr 11, 2023
…ash-4.17.21

Bump lodash from 4.17.20 to 4.17.21
deining pushed a commit to deining/setup-node that referenced this issue Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants
@Couto @jsg2021 @bryanmacfarlane @zomars @domdomegg and others