EoinDavey / tsPEG

PEG Parser Generator for TypeScript
Mozilla Public License 2.0
195 stars 7 forks source link

eslint error on strict / no-explicit-any #51

Closed dandubya closed 11 months ago

dandubya commented 11 months ago

Using:

The following line in the generated parser (almost at the bottom): public record(pos: PosInfo, result: any, att: MatchAttempt) {

...causes eslint to complain about the use of any.

A workaround is to add this right before that line: // eslint-disable-next-line @typescript-eslint/no-explicit-any

When I'm iterating on a grammar and doing a lot of testing, I have to manually fix this every time I compile a new grammar version into a parser. It would be nice to have an option to insert this line automatically.

I could add the file to .eslintignore, but it seems safer to keep it on because I've had some deployment issues (Next/Vercel) when I've ignored linting on whole files.

EoinDavey commented 11 months ago

Hi there,

Personally I think the best option is to exclude autogenerated files from linting, as philosophically linting is intended for humans. (You wouldn't expect a code minimiser to respect linting for example).

However, I wonder if it would be possible for you to use the header to include a comment at the top of the file disabling the no-explicit-any for this file?

Alternatively can you use eslint overrides in the .eslintrc.js to disable no-explicit-any for this file?

dandubya commented 11 months ago

All great points. Thank you.

Using the grammar header worked brilliantly. Here's what I did, for anyone else who might encounter this.

  1. Add the following to the top of the grammar:
    ---
    /* eslint-disable @typescript-eslint/no-explicit-any */
    ---
  2. Update the grammar build script to exclude adding the grammar as comments in the parser file:
    tspeg --include-grammar-comment false grammar.peg parser.ts

Thanks again!

EoinDavey commented 11 months ago

Great I'm glad to hear that the header approach worked!