Skip to content

Change Request: export a type to simplify language-specific rule definitions #177

@fasttime

Description

@fasttime

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?

The types JSONRuleDefinitionTypeOptions, MarkdownRuleDefinitionTypeOptions and (after eslint/eslint#19604 is merged) JSRuleDefinitionTypeOptions, are identical for all of our languages.

What do you think is the correct solution?

Export a new type for customizable RuleDefinition options, for example:

type CustomRuleDefinitionTypeOptions = {
	RuleOptions: unknown[];
	MessageIds: string;
	ExtRuleDocs: Record<string, unknown>;
};

This could replace the above mentioned types.

refs eslint/eslint#19604 (comment)

Participation

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

Additional comments

Additionally to the above, we could export a helper type to simplify the definition of a language-specific rule definition. For example:

export type JSRuleDefinition<
	Options extends Partial<JSRuleDefinitionTypeOptions> = {},
> = RuleDefinition<
	// Language specific type options (non-configurable)
	{
		LangOptions: Linter.LanguageOptions;
		Code: SourceCode;
		Visitor: Rule.NodeListener;
		Node: ESTree.Node;
	} & Required<
		// Rule specific type options (custom)
		Options &
			// Rule specific type options (defaults)
			Omit<JSRuleDefinitionTypeOptions, keyof Options>
	>
>;

could be simplified with a helper type to:

export type JSRuleDefinition<
	Options extends Partial<CustomRuleDefinitionTypeOptions> = {},
> = RuleDefinitionHelper<
	// Language specific type options (non-configurable)
	{
		LangOptions: Linter.LanguageOptions;
		Code: SourceCode;
		Visitor: Rule.NodeListener;
		Node: ESTree.Node;
	},
	// Rule specific type options
	Options
>;

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions