8000 fix(eslint-plugin): [consistent-type-assertions] handle tagged templates by yeonjuan · Pull Request #8993 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

fix(eslint-plugin): [consistent-type-assertions] handle tagged templates #8993

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ export default createRule<Options, MessageIds>({
node.parent.type === AST_NODE_TYPES.CallExpression ||
node.parent.type === AST_NODE_TYPES.ThrowStatement ||
node.parent.type === AST_NODE_TYPES.AssignmentPattern ||
node.parent.type === AST_NODE_TYPES.JSXExpressionContainer)
node.parent.type === AST_NODE_TYPES.JSXExpressionContainer ||
(node.parent.type === AST_NODE_TYPES.TemplateLiteral &&
node.parent.parent.type ===
AST_NODE_TYPES.TaggedTemplateExpression))
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
10000 Expand Up @@ -26,7 +26,8 @@ const x = new (<Foo>Generic<string>)();
const x = new (<Foo>Generic<string>)('string');
const x = () => <Foo>{ bar: 5 };
const x = () => <Foo>({ bar: 5 });
const x = () => <Foo>bar;`;
const x = () => <Foo>bar;
const x = <Foo>bar<string>\`\${"baz"}\`;`;

const ANGLE_BRACKET_TESTS = `${ANGLE_BRACKET_TESTS_EXCEPT_CONST_CASE}
const x = <const>{ key: 'value' };
Expand All @@ -45,7 +46,8 @@ const x = new (Generic<string> as Foo)();
const x = new (Generic<string> as Foo)('string');
const x = () => ({ bar: 5 } as Foo);
const x = () => ({ bar: 5 } as Foo);
const x = () => (bar as Foo);`;
const x = () => (bar as Foo);
const x = bar<string>\`\${"baz"}\` as Foo;`;

const AS_TESTS = `${AS_TESTS_EXCEPT_CONST_CASE}
const x = { key: 'value' } as const;
Expand All @@ -69,13 +71,15 @@ function b(x = {} as Foo.Bar) {}
function c(x = {} as Foo) {}
print?.({ bar: 5 } as Foo)
print?.call({ bar: 5 } as Foo)
print\`\${{ bar: 5 } as Foo}\`
`;
const OBJECT_LITERAL_ARGUMENT_ANGLE_BRACKET_CASTS = `
print(<Foo>{ bar: 5 })
new print(<Foo>{ bar: 5 })
function foo() { throw <Foo>{ bar: 5 } }
print?.(<Foo>{ bar: 5 })
print?.call(<Foo>{ bar: 5 })
print\`\${<Foo>{ bar: 5 }}\`
`;

ruleTester.run('consistent-type-assertions', rule, {
Expand Down Expand Up @@ -230,6 +234,10 @@ ruleTester.run('consistent-type-assertions', rule, {
messageId: 'angle-bracket',
line: 15,
},
{
messageId: 'angle-bracket',
line: 16,
},
],
}),
...batchedSingleLineTests<MessageIds, Options>({
Expand Down Expand Up @@ -296,6 +304,10 @@ ruleTester.run('consistent-type-assertions', rule, {
messageId: 'as',
line: 15,
},
{
messageId: 'as',
line: 16,
},
],
output: AS_TESTS,
}),
Expand Down Expand Up @@ -359,6 +371,10 @@ ruleTester.run('consistent-type-assertions', rule, {
messageId: 'never',
line: 14,
},
{
messageId: 'never',
line: 15,
},
],
}),
...batchedSingleLineTests<MessageIds, Options>({
Expand Down Expand Up @@ -421,6 +437,10 @@ ruleTester.run('consistent-type-assertions', rule, {
messageId: 'never',
line: 14,
},
{
messageId: 'never',
line: 15,
},
],
}),
...batchedSingleLineTests<MessageIds, Options>({
Expand Down Expand Up @@ -660,6 +680,17 @@ ruleTester.run('consistent-type-assertions', rule, {
},
],
},
{
messageId: 'unexpectedObjectTypeAssertion',
line: 12,
suggestions: [
{
messageId: 'replaceObjectTypeAssertionWithSatisfies',
data: { cast: 'Foo' },
output: `print\`\${{ bar: 5 } satisfies Foo}\``,
},
],
},
],
}),
...batchedSingleLineTests<MessageIds, Options>({
Expand Down Expand Up @@ -769,6 +800,17 @@ ruleTester.run('consistent-type-assertions', rule, {
},
],
},
{
messageId: 'unexpectedObjectTypeAssertion',
line: 10,
suggestions: [
{
messageId: 'replaceObjectTypeAssertionWithSatisfies',
data: { cast: 'Foo' },
output: `print\`\${{ bar: 5 } satisfies Foo}\``,
},
],
},
],
}),
{
Expand Down
Loading
0