npm-package-json-lint
npm-package-json-lint copied to clipboard
Experimental eslint integration
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.jsonfiles. 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 ofpackage.jsonand its path - Define a new package
eslint-plugin-package-jsonthat is an ESlint plugin. AFAIK this has to be a package prefixed witheslint-plugin. - This package defines a single rule called
package-json. This rule uses the "parser services" to load the content ofpackage.json, callsnpm-package-json-lintAPI 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.
For anyone interested, I've started the development of an eslint integration in https://github.com/scinos/eslint-plugin-package-json