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 merge5 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
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
3 changes: 2 additions & 1 deletionpackages/rule-tester/src/RuleTester.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -444,9 +444,10 @@ export class RuleTester extends TestFramework {
return normalizedTests;
}

defineRule(name: string, rule: AnyRuleModule): void {
defineRule(name: string, rule:Omit<AnyRuleModule, 'name'>): void {
this.#rules[name] = {
...rule,
name,
// Create a wrapper rule that freezes the `context` properties.
create(context): RuleListener {
freezeDeeply(context.options);
Expand Down
6 changes: 6 additions & 0 deletionspackages/rule-tester/tests/RuleTester.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -94,6 +94,7 @@ const NOOP_RULE: RuleModule<'error'> = {
schema: [],
type: 'problem',
},
name: 'rule',
};

function windowsToPosixPath(p: string): string {
Expand DownExpand Up@@ -1107,6 +1108,7 @@ describe('RuleTester - hooks', () => {
schema: [],
type: 'problem',
},
name: 'rule',
};

const ruleTester = new RuleTester();
Expand DownExpand Up@@ -1330,6 +1332,7 @@ describe('RuleTester - multipass fixer', () => {
schema: [],
type: 'problem',
},
name: 'rule',
};

it('passes with no output', () => {
Expand DownExpand Up@@ -1415,6 +1418,7 @@ describe('RuleTester - multipass fixer', () => {
schema: [],
type: 'problem',
},
name: 'rule',
};

it('passes with correct string output', () => {
Expand DownExpand Up@@ -1537,6 +1541,7 @@ describe('RuleTester - multipass fixer', () => {
schema: [],
type: 'problem',
},
name: 'rule',
};

it('passes with correct array output', () => {
Expand DownExpand Up@@ -1643,6 +1648,7 @@ describe('RuleTester - run types', () => {
],
type: 'suggestion',
},
name: 'rule',
};

describe('infer from `rule` parameter', () => {
Expand Down
4 changes: 4 additions & 0 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 DownExpand Up@@ -76,6 +77,7 @@ export function RuleCreator<PluginDocs = unknown>(
url: urlCreator(name),
},
},
name,
...rule,
});
};
Expand All@@ -89,6 +91,7 @@ function createRule<
create,
defaultOptions,
meta,
name,
}: Readonly<RuleWithMeta<Options, MessageIds, PluginDocs>>): RuleModule<
MessageIds,
Options,
Expand All@@ -101,6 +104,7 @@ function createRule<
},
defaultOptions,
meta,
name: 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@@ -735,6 +735,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
24 changes: 24 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@@ -43,4 +43,28 @@ describe(ESLintUtils.RuleCreator, () => {
type: 'problem',
});
});

it('withoutDocs should not add docs url', () => {
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).toBe('');
});
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp