mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 12:57:11 -06:00
feat(38225): change diagnostic message for remove braces from arrow function body (#38226)
This commit is contained in:
commit
cbf15bb6ed
@ -5657,7 +5657,7 @@
|
||||
"category": "Message",
|
||||
"code": 95111
|
||||
},
|
||||
"Remove block body braces": {
|
||||
"Remove braces from arrow function body": {
|
||||
"category": "Message",
|
||||
"code": 95112
|
||||
},
|
||||
@ -5669,7 +5669,7 @@
|
||||
"category": "Message",
|
||||
"code": 95114
|
||||
},
|
||||
"Remove all incorrect body block braces": {
|
||||
"Remove braces from all arrow function bodies with relevant issues": {
|
||||
"category": "Message",
|
||||
"code": 95115
|
||||
},
|
||||
@ -5677,7 +5677,7 @@
|
||||
"category": "Message",
|
||||
"code": 95116
|
||||
},
|
||||
|
||||
|
||||
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
|
||||
"category": "Error",
|
||||
"code": 18004
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
namespace ts.codefix {
|
||||
const fixId = "returnValueCorrect";
|
||||
const fixIdAddReturnStatement = "fixAddReturnStatement";
|
||||
const fixIdRemoveBlockBodyBrace = "fixRemoveBlockBodyBrace";
|
||||
const fixRemoveBracesFromArrowFunctionBody = "fixRemoveBracesFromArrowFunctionBody";
|
||||
const fixIdWrapTheBlockWithParen = "fixWrapTheBlockWithParen";
|
||||
const errorCodes = [
|
||||
Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code,
|
||||
@ -35,7 +35,7 @@ namespace ts.codefix {
|
||||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
fixIds: [fixIdAddReturnStatement, fixIdRemoveBlockBodyBrace, fixIdWrapTheBlockWithParen],
|
||||
fixIds: [fixIdAddReturnStatement, fixRemoveBracesFromArrowFunctionBody, fixIdWrapTheBlockWithParen],
|
||||
getCodeActions: context => {
|
||||
const { program, sourceFile, span: { start }, errorCode } = context;
|
||||
const info = getInfo(program.getTypeChecker(), sourceFile, start, errorCode);
|
||||
@ -44,7 +44,7 @@ namespace ts.codefix {
|
||||
if (info.kind === ProblemKind.MissingReturnStatement) {
|
||||
return append(
|
||||
[getActionForfixAddReturnStatement(context, info.expression, info.statement)],
|
||||
isArrowFunction(info.declaration) ? getActionForfixRemoveBlockBodyBrace(context, info.declaration, info.expression, info.commentSource): undefined);
|
||||
isArrowFunction(info.declaration) ? getActionForFixRemoveBracesFromArrowFunctionBody(context, info.declaration, info.expression, info.commentSource): undefined);
|
||||
}
|
||||
else {
|
||||
return [getActionForfixWrapTheBlockWithParen(context, info.declaration, info.expression)];
|
||||
@ -58,7 +58,7 @@ namespace ts.codefix {
|
||||
case fixIdAddReturnStatement:
|
||||
addReturnStatement(changes, diag.file, info.expression, info.statement);
|
||||
break;
|
||||
case fixIdRemoveBlockBodyBrace:
|
||||
case fixRemoveBracesFromArrowFunctionBody:
|
||||
if (!isArrowFunction(info.declaration)) return undefined;
|
||||
removeBlockBodyBrace(changes, diag.file, info.declaration, info.expression, info.commentSource, /* withParen */ false);
|
||||
break;
|
||||
@ -196,9 +196,9 @@ namespace ts.codefix {
|
||||
return createCodeFixAction(fixId, changes, Diagnostics.Add_a_return_statement, fixIdAddReturnStatement, Diagnostics.Add_all_missing_return_statement);
|
||||
}
|
||||
|
||||
function getActionForfixRemoveBlockBodyBrace(context: CodeFixContext, declaration: ArrowFunction, expression: Expression, commentSource: Node) {
|
||||
function getActionForFixRemoveBracesFromArrowFunctionBody(context: CodeFixContext, declaration: ArrowFunction, expression: Expression, commentSource: Node) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => removeBlockBodyBrace(t, context.sourceFile, declaration, expression, commentSource, /* withParen */ false));
|
||||
return createCodeFixAction(fixId, changes, Diagnostics.Remove_block_body_braces, fixIdRemoveBlockBodyBrace, Diagnostics.Remove_all_incorrect_body_block_braces);
|
||||
return createCodeFixAction(fixId, changes, Diagnostics.Remove_braces_from_arrow_function_body, fixRemoveBracesFromArrowFunctionBody, Diagnostics.Remove_braces_from_all_arrow_function_bodies_with_relevant_issues);
|
||||
}
|
||||
|
||||
function getActionForfixWrapTheBlockWithParen(context: CodeFixContext, declaration: ArrowFunction, expression: Expression) {
|
||||
|
||||
@ -3,6 +3,6 @@
|
||||
//// const a: ((() => number) | (() => undefined)) = () => { 1 }
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' }
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
//// })
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' },
|
||||
{ description: 'Remove unused label' },
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message },
|
||||
{ description: ts.Diagnostics.Remove_unused_label.message }
|
||||
]);
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
//// }
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' },
|
||||
{ description: 'Remove unused label' },
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message },
|
||||
{ description: ts.Diagnostics.Remove_unused_label.message }
|
||||
]);
|
||||
|
||||
interface A {
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
//// var x = <Comp t={() => { 1 }} />;
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' },
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message },
|
||||
{ description: `Infer type of 'props' from usage` }
|
||||
]);
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
//// }} />;
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' },
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message },
|
||||
{ description: `Infer type of 'props' from usage` },
|
||||
{ description: 'Remove unused label' },
|
||||
{ description: ts.Diagnostics.Remove_unused_label.message },
|
||||
]);
|
||||
|
||||
@ -9,6 +9,6 @@
|
||||
//// }
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' },
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -11,6 +11,6 @@
|
||||
//// }
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' },
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -5,6 +5,6 @@
|
||||
//// }
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' }
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
//// Foo(() => { /* leading */ 1 /* trailing */ })
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove block body braces",
|
||||
description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message,
|
||||
index: 1,
|
||||
newFileContent:
|
||||
`function Foo (a: () => number) { a() }
|
||||
|
||||
@ -4,6 +4,6 @@
|
||||
//// Foo(() => { 1 })
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' }
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -4,6 +4,6 @@
|
||||
//// Foo(() => { 1 })
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' }
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -3,6 +3,6 @@
|
||||
//// const a: () => number = () => { 1 }
|
||||
|
||||
verify.codeFixAvailable([
|
||||
{ description: 'Add a return statement' },
|
||||
{ description: 'Remove block body braces' }
|
||||
{ description: ts.Diagnostics.Add_a_return_statement.message },
|
||||
{ description: ts.Diagnostics.Remove_braces_from_arrow_function_body.message }
|
||||
]);
|
||||
|
||||
@ -58,8 +58,8 @@
|
||||
//// const test: { a: () => A } = { a: () => { bar: '1' } }
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "fixRemoveBlockBodyBrace",
|
||||
fixAllDescription: "Remove all incorrect body block braces",
|
||||
fixId: "fixRemoveBracesFromArrowFunctionBody",
|
||||
fixAllDescription: ts.Diagnostics.Remove_braces_from_all_arrow_function_bodies_with_relevant_issues.message,
|
||||
newFileContent:
|
||||
`interface A {
|
||||
bar: string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user