Skip to content

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

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Which packages would you like to change?

  • @eslint/compat
  • @eslint/config-array
  • @eslint/config-helpers
  • @eslint/core
  • @eslint/migrate-config
  • @eslint/object-schema
  • @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:

What do you think is the correct solution?

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

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

  • I am willing to submit a pull request for this change.

Additional comments

@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 eslint/eslint#4301 (comment). 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.

Metadata

Metadata

Labels

No fields configured for Enhancement.

Projects

Status

RFC Opened

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions