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

Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@zaygraveyard
Copy link
Contributor

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)

@zaygraveyard zaygraveyard added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Sep 11, 2019
@mdjermanovic
Copy link
Member

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

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Sep 11, 2019
@mdjermanovic
Copy link
Member

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
Copy link
Contributor Author

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

@mdjermanovic
Copy link
Member

I'm working on this

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 13, 2020
@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 Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.