Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: export plugin metadata#8331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 3 commits intomainfromexport-rule-meta
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletionpackages/eslint-plugin-internal/src/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
import type { Linter } from '@typescript-eslint/utils/ts-eslint';

import rules from './rules';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
const { name, version } = require('../package.json') as {
name: string;
version: string;
};

export = {
rules,
};
meta: {
name,
version,
},
} satisfies Linter.Plugin;
4 changes: 3 additions & 1 deletionpackages/eslint-plugin-internal/src/rules/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
import type { Linter } from '@typescript-eslint/utils/ts-eslint';

import noPoorlyTypedTsProps from './no-poorly-typed-ts-props';
import noTypescriptDefaultImport from './no-typescript-default-import';
import noTypescriptEstreeImport from './no-typescript-estree-import';
Expand All@@ -10,4 +12,4 @@ export default {
'no-typescript-estree-import': noTypescriptEstreeImport,
'plugin-test-formatting': pluginTestFormatting,
'prefer-ast-types-enum': preferASTTypesEnum,
};
} satisfies Linter.PluginRules;
15 changes: 14 additions & 1 deletionpackages/eslint-plugin-tslint/src/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
import type { Linter } from '@typescript-eslint/utils/ts-eslint';

import configRule from './rules/config';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
const { name, version } = require('../package.json') as {
name: string;
version: string;
};

export const meta: Linter.PluginMeta = {
name,
version,
};

/**
* Expose a single rule called "config", which will be accessed in the user's eslint config files
* via "tslint/config"
*/
export const rules = {
export const rules: Linter.PluginRules = {
config: configRule,
};
4 changes: 3 additions & 1 deletionpackages/eslint-plugin/src/configs/all.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand DownExpand Up@@ -151,4 +153,4 @@ export = {
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'error',
},
};
} satisfies ClassicConfig.Config;
4 changes: 3 additions & 1 deletionpackages/eslint-plugin/src/configs/base.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,8 +5,10 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
parser: '@typescript-eslint/parser',
parserOptions: { sourceType: 'module' },
plugins: ['@typescript-eslint'],
};
} satisfies ClassicConfig.Config;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
parserOptions: { project: null, program: null },
rules: {
Expand DownExpand Up@@ -59,4 +61,4 @@ export = {
'@typescript-eslint/switch-exhaustiveness-check': 'off',
'@typescript-eslint/unbound-method': 'off',
},
};
} satisfies ClassicConfig.Config;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@
* - disables rules from eslint:recommended which are already handled by TypeScript.
* - enables rules that make sense due to TS's typechecking / transpilation.
*/
import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
overrides: [
{
Expand DownExpand Up@@ -31,4 +33,4 @@ export = {
},
},
],
};
} satisfies ClassicConfig.Config;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand DownExpand Up@@ -50,4 +52,4 @@ export = {
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/unbound-method': 'error',
},
};
} satisfies ClassicConfig.Config;
4 changes: 3 additions & 1 deletionpackages/eslint-plugin/src/configs/recommended.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand All@@ -29,4 +31,4 @@ export = {
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
},
};
} satisfies ClassicConfig.Config;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand DownExpand Up@@ -75,4 +77,4 @@ export = {
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'error',
},
};
} satisfies ClassicConfig.Config;
4 changes: 3 additions & 1 deletionpackages/eslint-plugin/src/configs/strict.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand DownExpand Up@@ -39,4 +41,4 @@ export = {
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/unified-signatures': 'error',
},
};
} satisfies ClassicConfig.Config;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand All@@ -31,4 +33,4 @@ export = {
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
},
};
} satisfies ClassicConfig.Config;
4 changes: 3 additions & 1 deletionpackages/eslint-plugin/src/configs/stylistic.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@
// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';

export = {
extends: ['./configs/base', './configs/eslint-recommended'],
rules: {
Expand All@@ -25,4 +27,4 @@ export = {
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
},
};
} satisfies ClassicConfig.Config;
14 changes: 13 additions & 1 deletionpackages/eslint-plugin/src/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
import type { Linter } from '@typescript-eslint/utils/ts-eslint';

import all from './configs/all';
import base from './configs/base';
import disableTypeChecked from './configs/disable-type-checked';
Expand All@@ -10,6 +12,12 @@ import stylistic from './configs/stylistic';
import stylisticTypeChecked from './configs/stylistic-type-checked';
import rules from './rules';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
const { name, version } = require('../package.json') as {
name: string;
version: string;
};

export = {
configs: {
all,
Expand All@@ -25,5 +33,9 @@ export = {
stylistic,
'stylistic-type-checked': stylisticTypeChecked,
},
meta: {
name,
version,
},
rules,
};
} satisfies Linter.Plugin;
4 changes: 3 additions & 1 deletionpackages/eslint-plugin/src/rules/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
import type { Linter } from '@typescript-eslint/utils/ts-eslint';

import adjacentOverloadSignatures from './adjacent-overload-signatures';
import arrayType from './array-type';
import awaitThenable from './await-thenable';
Expand DownExpand Up@@ -278,4 +280,4 @@ export default {
typedef: typedef,
'unbound-method': unboundMethod,
'unified-signatures': unifiedSignatures,
};
} satisfies Linter.PluginRules;
6 changes: 5 additions & 1 deletionpackages/repo-tools/src/generate-configs.mts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,11 @@ async function main(): Promise<void> {
console.log(chalk.blueBright(`\n${hyphens} ${name}.ts ${hyphens}`));

// note: we use `export =` because ESLint will import these configs via a commonjs import
const code = `export = ${JSON.stringify(getConfig())};`;
const code = [
"import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';",
'',
`export = ${JSON.stringify(getConfig())} satisfies ClassicConfig.Config;`,
].join('\n');
const configStr = await prettier.format(addAutoGeneratedComment(code), {
parser: 'typescript',
...prettierConfig,
Expand Down
22 changes: 12 additions & 10 deletionspackages/utils/src/ts-eslint/Config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,17 @@ export namespace SharedConfig {
}

export type ParserOptions = ParserOptionsTypes.ParserOptions;

export interface PluginMeta {
/**
* The meta.name property should match the npm package name for your plugin.
*/
name: string;
/**
* The meta.version property should match the npm package version for your plugin.
*/
version: string;
}
}

export namespace ClassicConfig {
Expand DownExpand Up@@ -121,6 +132,7 @@ export namespace FlatConfig {
export type GlobalsConfig = SharedConfig.GlobalsConfig;
export type Parser = ParserType.LooseParserModule;
export type ParserOptions = SharedConfig.ParserOptions;
export type PluginMeta = SharedConfig.PluginMeta;
export type Processor = ProcessorType.ProcessorModule;
export type RuleEntry = SharedConfig.RuleEntry;
export type RuleLevel = SharedConfig.RuleLevel;
Expand All@@ -134,16 +146,6 @@ export namespace FlatConfig {
export interface SharedConfigs {
[key: string]: Config;
}
export interface PluginMeta {
/**
* The meta.name property should match the npm package name for your plugin.
*/
name: string;
/**
* The meta.version property should match the npm package version for your plugin.
*/
version: string;
}
export interface Plugin {
/**
* Shared configurations bundled with the plugin.
Expand Down
22 changes: 20 additions & 2 deletionspackages/utils/src/ts-eslint/Linter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,13 @@ import { Linter as ESLintLinter } from 'eslint';
import type { ClassicConfig, FlatConfig, SharedConfig } from './Config';
import type { Parser } from './Parser';
import type { Processor as ProcessorType } from './Processor';
import type { RuleCreateFunction, RuleFix, RuleModule } from './Rule';
import type {
AnyRuleCreateFunction,
AnyRuleModule,
RuleCreateFunction,
RuleFix,
RuleModule,
} from './Rule';
import type { SourceCode } from './SourceCode';

export type MinimalRuleModule<
Expand DownExpand Up@@ -118,6 +124,7 @@ namespace Linter {
export type GlobalVariableOption = SharedConfig.GlobalVariableOption;
export type GlobalVariableOptionBase = SharedConfig.GlobalVariableOptionBase;
export type ParserOptions = SharedConfig.ParserOptions;
export type PluginMeta = SharedConfig.PluginMeta;
export type RuleEntry = SharedConfig.RuleEntry;
export type RuleLevel = SharedConfig.RuleLevel;
export type RuleLevelAndOptions = SharedConfig.RuleLevelAndOptions;
Expand DownExpand Up@@ -262,6 +269,13 @@ namespace Linter {
parserOptions?: ParserOptions;
}

// TODO - RuleCreateFunction is no longer supported in ESLint v9
export type LegacyPluginRules = Record<
string,
AnyRuleCreateFunction | AnyRuleModule
>;
export type PluginRules = Record<string, AnyRuleModule>;

export interface Plugin {
/**
* The definition of plugin configs.
Expand All@@ -271,14 +285,18 @@ namespace Linter {
* The definition of plugin environments.
*/
environments?: Record<string, Environment>;
/**
* Metadata about your plugin for easier debugging and more effective caching of plugins.
*/
meta?: PluginMeta;
/**
* The definition of plugin processors.
*/
processors?: Record<string, ProcessorType.ProcessorModule>;
/**
* The definition of plugin rules.
*/
rules?:Record<string, RuleCreateFunction | RuleModule<string, unknown[]>>;
rules?:LegacyPluginRules;
}
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp