npm-package-json-lint icon indicating copy to clipboard operation
npm-package-json-lint copied to clipboard

Experimental eslint integration

Open scinos opened this issue 4 years ago • 1 comments

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 avatar Feb 17 '21 15:02 scinos

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

scinos avatar May 23 '22 06:05 scinos