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

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

Closed
dandubya opened this issue Nov 29, 2023 · 3 comments
Closed

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

dandubya opened this issue Nov 29, 2023 · 3 comments

Comments

@dandubya
Copy link

Using:

  • Typescript 5.2.2
  • tsPEG 3.3.0
  • next: 14.0.3
  • vscode 1.84.2
  • eslint 2.4.2

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants