8000 Quick fix for functions lacking return expressions by Kingwl · Pull Request #26434 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Quick fix for functions lacking return expressions #26434

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 28 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3f59aa9
stash
Kingwl Aug 10, 2018
7671221
add surmise for return type
Kingwl Aug 14, 2018
0b1e6cc
add support for more case
Kingwl Aug 14, 2018
1f9b9c0
add more test case
Kingwl Aug 16, 2018
aca1722
add more testcase and fix all test
Kingwl Aug 20, 2018
7cfd0fb
Merge branch 'master' into returnValueSurmise
Kingwl Apr 29, 2019
cbe59bb
fix changed diagnosis
Kingwl Apr 30, 2019
48f1cca
Merge branch 'master' into returnValueSurmise
Kingwl May 8, 2019
98d7eba
fix broken test case
Kingwl May 8, 2019
537e806
add more case
8000 Kingwl May 8, 2019
505e299
Merge branch 'master' into returnValueSurmise
Kingwl Jan 9, 2020
6fecf32
rename quickfix
Kingwl Jan 9, 2020
4c0af72
fix conflict
Kingwl Jan 9, 2020
98377f3
fix fix desc
Kingwl Jan 9, 2020
49d21bf
fix semi
Kingwl Jan 9, 2020
a2b15ed
Merge branch 'master' into returnValueSurmise
Kingwl Mar 4, 2020
eabc5a4
Merge branch 'master' into returnValueSurmise
Kingwl Mar 4, 2020
944ddf4
Avoid replace brace with paren
Kingwl Mar 18, 2020
6c88a01
Split fix all action
Kingwl Mar 18, 2020
94f845a
Add return work in same line
Kingwl Mar 18, 2020
a7f37a3
Merge branch 'master' into returnValueSurmise
Kingwl Mar 18, 2020
7fe9a82
fix test cases
Kingwl Mar 18, 2020
af9552e
rename baseline
Kingwl Mar 26, 2020
601fc5e
refactor and handle comment
Kingwl Mar 26, 2020
175cf4e
Support semi
Kingwl Mar 26, 2020
8b332fe
Merge branch 'master' into returnValueSurmise
Kingwl Mar 26, 2020
5d8355c
make helper internal
Kingwl Mar 26, 2020
522cac8
Merge branch 'master' into returnValueSurmise
Kingwl Apr 2, 2020
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
Next Next commit
stash
  • Loading branch information
Kingwl committed Aug 10, 2018
commit 3f59aa9871509ece6d4e688cb1eb314c2cffaa62
20 changes: 20 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4563,5 +4563,25 @@
"Add all missing imports": {
"category": "Message",
"code": 95064
},
"Add a return statement": {
"category": "Message",
"code": 95065
},
"Remove block body braces": {
"category": "Message",
"code": 95066
},
"Replace braces with parentheses": {
"category": "Message",
"code": 95067
},
"Wrap this block with parentheses": {
"category": "Message",
"code": 95068
},
"Surmise all return value": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got to admit: I don't know what the word surmise means, and I don't know if users will either. What's the intent here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Correct all return expressions" would be best here

"surmise" is not in basic English vocabulary and we need to avoid it entirely for clarity's sake.

"category": "Message",
"code": 95069
}
}
50 changes: 50 additions & 0 deletions src/services/codefixes/returnValueSurmise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* @internal */
namespace ts.codefix {
const fixId = "returnValueSurmise";
const errorCodes = [
Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code,
Diagnostics.Type_0_is_not_assignable_to_type_1.code,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code
];
registerCodeFix({
errorCodes,
getCodeActions: context => {
const { host, sourceFile, span: { start } } = context;
return packageName === undefined ? []
: [createCodeFixAction(fixId, /*changes*/ [], [Diagnostics.Install_0, packageName], fixId, Diagnostics.Install_all_missing_types_packages, getCommand(sourceFile.fileName, packageName))];
},
fixIds: [fixId],
getAllCodeActions: context => codeFixAll(context, errorCodes, (_, diag, commands) => {
const pkg = getTypesPackageNameToInstall(context.host, diag.file, diag.start, diag.code);
if (pkg) {
commands.push(getCommand(diag.file.fileName, pkg));
}
}),
});

interface Info {

}

function getInfo (checker: TypeChecker, sourceFile: SourceFile, position: number): Info | undefined {
const node = getTokenAtPosition(sourceFile, position);
if (!node.parent) return undefined;

if (isTypeNode(node) && isFunctionLikeDeclaration(node.parent)) {

}
else if (isDeclarationName(node) && isVariableLike(node.parent)) {

}
else {
Debug.fail('unknow pattern');
}


const functionLikeDeclaration = cast(node.parent, isFunctionLike);
Debug.assert(functionLikeDeclaration.type === node);

const returnType = checker.getTypeFromTypeNode(cast(node, isTypeNode));

}
}
1 change: 1 addition & 0 deletions src/services/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
"codefixes/importFixes.ts",
"codefixes/fixSpelling.ts",
"codefixes/returnValueSurmise.ts",
"codefixes/fixAddMissingMember.ts",
"codefixes/fixCannotFindModule.ts",
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
Expand Down
0