You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, publint is a slightly opinionated linting tool that comes with a built-in set of rules for support in environments like Vite, Node, workers, etc, and suggestions to keep your package clean and correct.
The next logical step is to allow expanding what publint is today. In comparison to ESLint where it lints your source code, publint lints your built/publish code, which is an area I've not seen explored.
I'd like to work on a plugin API to enable this, and below are drafts of the idea:
Plugins have access to utilities that core uses to validate or process things
Installing publint alone should still be all that's needed to lint the basic/standard things
Non-goals
Pushing rules as external packages. Core should be opened to additional rules that help everyone, as long as they don't bloat the package. This helps prevent plugin hell.
Disabling specific rules. All rules in core cannot be disabled, but plugins may add options to disable their rules. (Could be persuaded but we'll see)
interfacePlugin{name: string// Runs in parallellint?: (api: LintApi)=>void|Promise<void>}exportinterfaceLintApi{root: stringpkg: PackageJson// Better-typed `package.json` objectoriginalPkg: PackageJson// Better-typed `package.json` objectfiles: string[]// All files packed in the tarball. Use `vfs` to load them.vfs: Vfs// Same as the current `vfs` option object// Resolve the `id` to a specific pathresolve: Resolve// Report an issuereport: (issue: Issue)=>void}typeResolvePreset=|'esm'|'cjs'|'types'|'package-json-main'|'package-json-exports'interfaceResolve{(id: string,importer?: string,options?: {preset?: ResolvePreset}): Promise<ResolveResult|undefined>}typeResolveResult=|{type: 'dependency';name: string;subpath: string}|{type: 'dev-dependency';name: string;subpath: string}|{type: 'protocol';path: string}|{type: 'file';path: string}/** Path to the file only */typeLocationPath=string/** Path to file with line and column */typeLocationFileWithLineColumn={path: stringstart: number|{line: number;column: number}end?: number|{line: number;column: number}}/** Path to JSON file with specific keys */typeLocationJsonWithKeys={path: string;keys: string[]}interfaceIssue{type: 'suggestion'|'warning'|'error'rule: stringmessage: stringlocation: LocationPath|LocationFileWithLineColumn|LocationJsonWithKeys}
How to write a good plugin:
If you intend your plugin to work in browsers:
Use api.vfs.* for any filesystem related operations.
Use api.resolve to resolve paths instead of manual resolution, which is possible but only for non-standard cases.
Notes:
As plugins' lint hook run in parallel, the order of api.report between plugins may be non-deterministic. Internally, we can sort this by file, rule name, and issue message.
Examples
Suggest specifying a description:
exportfunctiondescriptionPlugin(): Plugin{return{name: 'description',lint(api){if(!api.pkg.description){api.report({type: 'suggestion'rule: 'add-description'message: 'A description is recommended',location: 'package.json',})}}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Today, publint is a slightly opinionated linting tool that comes with a built-in set of rules for support in environments like Vite, Node, workers, etc, and suggestions to keep your package clean and correct.
The next logical step is to allow expanding what publint is today. In comparison to ESLint where it lints your source code, publint lints your built/publish code, which is an area I've not seen explored.
I'd like to work on a plugin API to enable this, and below are drafts of the idea:
Goals
.svelte
or.ts
filespackage.json
publint
alone should still be all that's needed to lint the basic/standard thingsNon-goals
Design
How to write a good plugin:
api.vfs.*
for any filesystem related operations.api.resolve
to resolve paths instead of manual resolution, which is possible but only for non-standard cases.Notes:
lint
hook run in parallel, the order ofapi.report
between plugins may be non-deterministic. Internally, we can sort this by file, rule name, and issue message.Examples
Suggest specifying a
description
:Beta Was this translation helpful? Give feedback.
All reactions