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

space-before-function-paren removes comments when fixing #12259

Comments

@zaygraveyard
Copy link
Contributor

@zaygraveyard zaygraveyard commented Sep 11, 2019

Tell us about your environment

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:

Configuration
{
    "parserOptions": {
        "ecmaVersion": 10,
        "sourceType": "module",
        "ecmaFeatures": {}
    },
    "rules": {
        "space-before-function-paren": ["error", "never"]
    },
    "env": {}
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

Tried to fix the following code

function delay /*:: <T>*/() {}

https://eslint.org/demo#eyJ0ZXh0IjoiLyplc2xpbnQgc3BhY2UtYmVmb3JlLWZ1bmN0aW9uLXBhcmVuOiBbJ2Vycm9yJywgJ25ldmVyJ10qL1xuZnVuY3Rpb24gZGVsYXkgLyo6OiA8VD4qLygpIHt9Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoxMSwic291cmNlVHlwZSI6Im1vZHVsZSIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6e319fQ==

What did you expect to happen?
The space after delay to be removed while preserving the comment.

What actually happened? Please include the actual, raw output from ESLint.
The space and the comment after delay got removed.

Are you willing to submit a pull request to fix this bug?
No

Cause

fix: fixer => fixer.removeRange([leftToken.range[1], rightToken.range[0]])

The fixing is done by removing everything between the identifier and the opening parenthesis (without taking comments into consideration)

@mdjermanovic

This comment has been minimized.

Copy link
Member

@mdjermanovic mdjermanovic commented Sep 11, 2019

Hi @zaygraveyard, thanks for the report! I can reproduce this bug.

@mdjermanovic mdjermanovic added accepted rule and removed triage labels Sep 11, 2019
@mdjermanovic

This comment has been minimized.

Copy link
Member

@mdjermanovic mdjermanovic commented Sep 11, 2019

Perhaps we could implement here the logic from template-tag-spacing?

Demo

It concatenates all block comments. If there is a line comment, just reports without the autofix.

@zaygraveyard

This comment has been minimized.

Copy link
Contributor Author

@zaygraveyard zaygraveyard commented Sep 11, 2019

@mdjermanovic yes, this would indeed fix this issue since it would preserve the comments

@mdjermanovic

This comment has been minimized.

Copy link
Member

@mdjermanovic mdjermanovic commented Sep 12, 2019

I'm working on this

mdjermanovic added a commit that referenced this issue Sep 12, 2019
mysticatea added a commit that referenced this issue Sep 14, 2019
@eslint eslint bot locked and limited conversation to collaborators Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.