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(eslint-plugin): expose rule name via RuleModule interface#11719

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

Open
y-hsgw wants to merge13 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromy-hsgw:feat/add-name-to-rulemodule
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
88bfd8d
feat: expose rule name via RuleModule interface
y-hsgwOct 25, 2025
d919392
test: update tests
y-hsgwOct 25, 2025
428521f
Merge branch 'main' into feat/add-name-to-rulemodule
JoshuaKGoldbergNov 3, 2025
91e97bc
test: add test
y-hsgwNov 3, 2025
e6e499f
Merge branch 'feat/add-name-to-rulemodule' of https://github.com/y-hs…
y-hsgwNov 3, 2025
213983b
fix: add optional
y-hsgwNov 18, 2025
7e2f8e8
Merge branch 'main' into feat/add-name-to-rulemodule
kirkwaiblingerNov 21, 2025
c2d2e38
fix up test
kirkwaiblingerNov 21, 2025
4326e27
tweaks
kirkwaiblingerDec 6, 2025
19d2393
ensure name is forwarded
kirkwaiblingerDec 6, 2025
e3029d8
Merge branch 'typescript-eslint:main' into feat/add-name-to-rulemodule
y-hsgwDec 7, 2025
083f6b5
feat: Ensure RuleCreator returns named rules with string name
y-hsgwDec 7, 2025
28af1c9
refactor: use type assertion
y-hsgwDec 9, 2025
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
1 change: 1 addition & 0 deletionspackages/rule-tester/src/RuleTester.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -427,6 +427,7 @@ export class RuleTester extends TestFramework {
defineRule(name: string, rule: AnyRuleModule): void {
this.#rules[name] = {
...rule,
name,
// Create a wrapper rule that freezes the `context` properties.
create(context): RuleListener {
freezeDeeply(context.options);
Expand Down
19 changes: 17 additions & 2 deletionspackages/utils/src/eslint-utils/RuleCreator.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ export interface RuleWithMeta<
Docs = unknown,
> extends RuleCreateAndOptions<Options, MessageIds> {
meta: RuleMetaData<MessageIds, Docs, Options>;
name?: string;
}

export interface RuleWithMetaAndName<
Expand All@@ -47,6 +48,15 @@ export interface RuleWithMetaAndName<
name: string;
}

type RuleModuleWithName<
MessageIds extends string,
Options extends readonly unknown[] = [],
Docs = unknown,
ExtendedRuleListener extends RuleListener = RuleListener,
> = RuleModule<MessageIds, Options, Docs, ExtendedRuleListener> & {
name: string;
};

/**
* Creates reusable function to create rules with default options and docs URLs.
*
Expand All@@ -67,17 +77,20 @@ export function RuleCreator<PluginDocs = unknown>(
...rule
}: Readonly<
RuleWithMetaAndName<Options, MessageIds, PluginDocs>
>):RuleModule<MessageIds, Options, PluginDocs> {
return createRule<Options, MessageIds, PluginDocs>({
>):RuleModuleWithName<MessageIds, Options, PluginDocs> {
const ruleWithDocs = createRule<Options, MessageIds, PluginDocs>({
meta: {
...meta,
docs: {
...meta.docs,
url: urlCreator(name),
},
},
name,
...rule,
});

return ruleWithDocs as RuleModuleWithName<MessageIds, Options, PluginDocs>;
};
}

Expand All@@ -89,6 +102,7 @@ function createRule<
create,
defaultOptions,
meta,
name,
}: Readonly<RuleWithMeta<Options, MessageIds, PluginDocs>>): RuleModule<
MessageIds,
Options,
Expand All@@ -101,6 +115,7 @@ function createRule<
},
defaultOptions,
meta,
name,
};
}

Expand Down
5 changes: 5 additions & 0 deletionspackages/utils/src/ts-eslint/Rule.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -737,6 +737,11 @@ export interface RuleModule<
* Metadata about the rule
*/
meta: RuleMetaData<MessageIds, Docs, Options>;

/**
* Rule name
*/
name?: string;
}

export type AnyRuleModule = RuleModule<string, readonly unknown[]>;
Expand Down
50 changes: 50 additions & 0 deletionspackages/utils/tests/eslint-utils/RuleCreator.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,5 +42,55 @@ describe(ESLintUtils.RuleCreator, () => {
schema: [],
type: 'problem',
});
expect(rule.name).toBe('test');
});

it('withoutDocs should work without a `name`', () => {
const rule = ESLintUtils.RuleCreator.withoutDocs({
create() {
return {};
},
defaultOptions: [],
meta: {
docs: {
description: 'some description',
},
messages: {
foo: 'some message',
},
schema: [],
type: 'problem',
},
});

expect(rule.meta.docs).toEqual({
description: 'some description',
});
expect(rule.name).toBeUndefined();
});

it('withoutDocs should work with a `name`', () => {
const rule = ESLintUtils.RuleCreator.withoutDocs({
create() {
return {};
},
defaultOptions: [],
meta: {
docs: {
description: 'some description',
},
messages: {
foo: 'some message',
},
schema: [],
type: 'problem',
},
name: 'some-name',
});

expect(rule.meta.docs).toEqual({
description: 'some description',
});
expect(rule.name).toBe('some-name');
});
});

[8]ページ先頭

©2009-2025 Movatter.jp