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

Experimental eslint integration #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

scinos
Copy link

@scinos scinos commented Feb 17, 2021

EXPERIMENT FOR #323 - NOT TO MERGE

Description of change

This is a proof of concept on how this tool can integrate with ESlint.

How it works

  • Define a parser for ESLint. This parser is used to parse package.json files. It works by returning an empty AST tree to ESLint (so eslint pretty much ignores it) but also providing "parser services" that rules can use. Those services are used to expose the content of package.json and its path
  • Define a new package eslint-plugin-package-json that is an ESlint plugin. AFAIK this has to be a package prefixed with eslint-plugin.
  • This package defines a single rule called package-json. This rule uses the "parser services" to load the content of package.json, calls npm-package-json-lint API to lint it, and re-shapes the error report in the format that eslint expects.

Caveats

  • The way ESLint rules (or parser) work is file by file. It means that options like rule overrides won't work. Instead, the user should rely on ESLint's override system to implement the same logic.
  • ESLint really wants to have plugins as isolated packages with a specific name. Given that implementing ESLint support doesn't really change any in the core of npm-package-json-lint, this may be best implemented as a separate package.

Please let me know what you think. I'm happy to implement this "for good" in this package, or create a separate package for it.

@scinos
Copy link
Author

scinos commented May 23, 2022

For anyone interested, I've started the development of an eslint integration in https://github.com/scinos/eslint-plugin-package-json

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

Successfully merging this pull request may close these issues.

None yet

1 participant