Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

ESLint Plugins

Custom plugins that support TypeScript code and typed linting look very similar to any other ESLint plugin.Follow the same general steps asESLint's plugins guide >Creating a plugin to set up your plugin.The required differences are noted on this page.

tip

Seeeslint-plugin-example-typed-linting for an example plugin that supports typed linting.

Package Dependencies

Your plugin should have the followingpackage.json entries.

For all@typescript-eslint andtypescript-eslint packages, keep them at the same semver versions.As an example, you might set each of them to^8.1.2 or^7.12.0 || ^8.0.0.

dependencies

@typescript-eslint/utils is required for theRuleCreator factory to create rules.

devDependencies

@typescript-eslint/rule-tester is strongly recommended to be able totest rules with ourRuleTester.

peerDependencies

Include the following to enforce the version range allowed without making users' package managers install them:

  • @typescript-eslint/parser and any other parsers users are expected to be using
  • eslint
  • typescript

Those are all packages consumers are expected to be using already.

You don't need to declare any dependencies ontypescript-eslint or@typescript-eslint/eslint-plugin.Our setup guide ensures that the parser is automatically registered when configuring ESLint.

RuleCreator Usage

We recommend including at least the following three properties in your plugin'sRuleCreator extra rule docs types:

  • description: string: a succinct description of what the rule does
  • recommended?: boolean: whether the rule exists in your plugin's shared"recommended" config
  • requiresTypeChecking?: boolean: whether the rule will use type information, for documentation generators such aseslint-doc-generator

For example, fromeslint-plugin-example-typed-linting'sutils.ts:

import{ ESLintUtils}from'@typescript-eslint/utils';

exportinterfaceExamplePluginDocs{
description:string;
recommended?:boolean;
requiresTypeChecking?:boolean;
}

exportconst createRule= ESLintUtils.RuleCreator<ExamplePluginDocs>(
name=>
`https://github.com/your/eslint-plugin-example/tree/main/docs/${name}.md`,
);

Type Checking and Configs

Most ESLint plugins export a"recommended"ESLint shared config.Many ESLint users assume enabling a plugin'srecommended config is enough to enable all its relevant rules.

However, at the same time, not all users want to or are able to enabled typed linting.If your plugin's rules heavily use type information, it might be difficult to enable those in arecommended config.

You have roughly two options:

  • Have your plugin'srecommended config require enabling type information
  • Have a separate config with a name likerecommendedTypeChecked

Either way, explicitly mention the strategy taken in your docs.

info

PerCustom Rules >Conditional Type Information, we recommend not changing rule logic based on whether type information is available.

tip

Seeeslint-plugin-example-typed-linting for an example plugin that supports typed linting.


[8]ページ先頭

©2009-2025 Movatter.jp