Skip to content

Make convertFunctionToEs6Class a codefix #22241

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
5 commits merged into from
Mar 2, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Feb 28, 2018

Part of #19392
Discovered #22240

@ghost ghost requested a review from amcasey February 28, 2018 22:24
@ghost ghost force-pushed the convertFunctionToEs6Class_codefix branch from 522be8d to f53adf8 Compare February 28, 2018 22:25
@@ -3814,6 +3814,10 @@
"category": "Suggestion",
"code": 80001
},
"Function may be converted to a class.": {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DanielRosenwasser any thoughts about the error message

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this message can be enhanced, @DanielRosenwasser might have better suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

We should refine this over time, but

This constructor function may be converted to a class declaration.

or

Constructor function may be better represented as a class declaration.

switch (node.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
if (isInJavaScriptFile(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is the only one we have right now, i would move this to the top of the check function. we can refactor it later as we add more checks.

['1', '2', '3', '4', '5', '6', '7', '8'].forEach(m => verify.applicableRefactorAvailableAtMarker(m));
verify.fileAfterApplyingRefactorAtMarker('7',
verify.codeFix({
description: "Convert function to an ES2015 class",
Copy link
Member

Choose a reason for hiding this comment

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

Can this refer to the resource, rather than including a string literal? That would make it easier to change the resource's value.

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately, diagnostics are automatically named the same as their message. (See scripts/processDIagnosticMessages.ts.) So if we change the message we end up needing to rename a bunch of things anyway...

@ghost ghost merged commit 87c3cca into master Mar 2, 2018
@ghost ghost deleted the convertFunctionToEs6Class_codefix branch March 2, 2018 20:57
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants