Skip to content
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

New: Add fixer for object-shorthand (fixes #6412) #6418

Merged
merged 1 commit into from Jun 17, 2016

Conversation

NickHeiner
Copy link
Contributor

I've tested this manually by linking it into an existing project of mine and seeing that it cleans up ~50 detected rule violations. I've manually spot-checked the fixes to verify that they are what I'd expect.

Some of this would be cleaner if I could return multiple fixes instead of just one fixer call.

Thanks for the review!

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @nzakas, @lemonmade and @vitorbal to be potential reviewers

fix: function(fixer) {
if (node.method) {
if (node.value.generator) {
return fixer.replaceTextRange([node.range[0], node.key.range[1]], node.key.name + ": function*");
Copy link
Member

Choose a reason for hiding this comment

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

Noting for other reviewers that the star spacing might be wrong here-- this will be fixed by another pass in auto-fix. This would also be another example of something that could go into a shared repository settings config. (@NickHeiner you can ignore this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I was thinking about things like that! I'm glad to hear that it's not an issue for this PR.

@nzakas
Copy link
Member

nzakas commented Jun 15, 2016

Can you add some tests that have new lines and comments in them? Like:

var x = {
    a: "B",
    c: c,
    // foo
};

@NickHeiner
Copy link
Contributor Author

Yeah, I'm happy to add that. And do you really want all those other test cases to be on the same line? I was trying to keep with the existing style, but it does get a bit unwieldy.

Also, this is obviously beyond the scope of this PR, but it feels a bit brittle to be outputting a fix as a string, instead of an AST -> AST transformation. If the fixer were just outputting an AST, then issues like what @platinumazure called out above would not occur, because the fixer could produce the necessary structure without also having an opinion about how that structure gets rendered as a string.

@eslintbot
Copy link

LGTM

@NickHeiner NickHeiner force-pushed the add-fixer-for-object-shorthand branch from 5f12ef8 to 536c094 Compare June 15, 2016 18:07
@NickHeiner
Copy link
Contributor Author

@nzakas Additional test for comments and newlines added. Good call.

@nzakas
Copy link
Member

nzakas commented Jun 16, 2016

@NickHeiner we know what we have is a bit brittle, but switching to something else is a massive amount of work and AST -> AST transforms would leave out whitespace fixes (which is what our fixing system was designed for primarily). You can read more about it here: #5329.

@nzakas
Copy link
Member

nzakas commented Jun 16, 2016

@NickHeiner for the tests, we really need a few invalid cases with newlines and comments that are being autofixed so we know we aren't missing up newlines or comments.

@NickHeiner
Copy link
Contributor Author

NickHeiner commented Jun 16, 2016

we know what we have is a bit brittle, but switching to something else is a massive amount of work

Makes sense! 😄 And if this system is designed for whitespace fixes, then yes this is a nice, simple way to address that issue.

@NickHeiner
Copy link
Contributor Author

@nzakas I added the following test case:

        { code: "var x = {y: z,\n x: x,\n a: b\n // comment \n}", output: "var x = {y: z,\n x,\n a: b\n // comment \n}", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Expected property shorthand.", type: "Property" }] },

It seemed to be that this would adequately cover comments and newlines. But I'm happy to add a few more examples.

@NickHeiner NickHeiner force-pushed the add-fixer-for-object-shorthand branch from 536c094 to 0b37057 Compare June 16, 2016 15:49
@eslintbot
Copy link

LGTM

@NickHeiner
Copy link
Contributor Author

6 additional test cases with comments and newlines added.

@ilyavolodin
Copy link
Member

LGTM. @NickHeiner Thanks for working with us on this!

@NickHeiner NickHeiner force-pushed the add-fixer-for-object-shorthand branch from 0b37057 to 88f49fe Compare June 16, 2016 19:59
@eslintbot
Copy link

LGTM

@nzakas
Copy link
Member

nzakas commented Jun 17, 2016

Thanks @NickHeiner !

@nzakas nzakas merged commit da30cf9 into eslint:master Jun 17, 2016
@NickHeiner
Copy link
Contributor Author

You're welcome! Thanks for the review.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants