eslint / eslint/rewrite

Change Request: Provide a `definePlugin` function in `@eslint/plugin-kit`

Open
#176 6 comments 8 reactions 1 assignee Claimed by @crimsonjay0 View on GitHub
accepted enhancement
Dominant language
JavaScript
Stars
348
Forks
51
Avg merge
2d 10h
Merged PRs (30d)
11

Description

### Which packages would you like to change?

- [ ] `@eslint/compat`
- [ ] `@eslint/config-array`
- [ ] `@eslint/config-helpers`
- [ ] `@eslint/core`
- [ ] `@eslint/migrate-config`
- [ ] `@eslint/object-schema`
- [x] `@eslint/plugin-kit`

### What problem do you want to solve?

Right now, there's no standard factory function for writing ESLint plugins. https://eslint.org/docs/latest/extend/plugins provides suggested starting objects but:

* It's easy to mistype, forget fields, etc. in plain objects
* Having a factory function makes it easier to give types-directed suggestions in editors and type checking
* The function could abstract away the -IMO confusing- computed `get()`er and/or `Object.assign` folks have to do to get circular references working in the objects
* It could also apply common patterns and/or optimizations for users so they don't have to:
* Common pattern: generating configs based on `meta.docs.recommended` or other properties
* Optimizations: https://github.com/typescript-eslint/typescript-eslint/issues/11029

### What do you think is the correct solution?

How about an `@eslint/plugin-utils` package with a `definePlugin` export?

```ts
import { definePlugin } from "@eslint/plugin-utils";

export default definePlugin({
meta: {
name: "eslint-plugin-example",
version: "1.2.3",
},
rules: {
"dollar-sign": {
meta: {
docs: {
recommended: true,
}
},
create(context) {
// rule implementation ...
},
},
},
});
```

That `meta.docs.recommended` could be used to generate a `configs.recommended` in the standard format(s) preferred by flat config.

### Participation

- [x] I am willing to submit a pull request for this change.

### Additional comments

[`@eslint/plugin-kit`](https://www.npmjs.com/package/@eslint/plugin-kit) exists but it's really more of a "languages" kit. I separately tried searching `plugin-kit`, `plugin-utils`, and similar terms on ESLint's issue trackers. The closest mention I could find was https://github.com/eslint/eslint/issues/4301#issuecomment-171732074. I have a vague memory of this being discussed somewhere previously, but can't remember where...?

I'd be happy to write up an RFC if it's a direction the project would be interested in.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.