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-blocks" not working correctly #13553
Comments
Thanks for the report. The rule is working fine. There is a missing space between So maybe it can be a rule request to typescript-eslint. |
I think there is a misunderstanding, eslint didn't report any error, but it should because space is missing and I think typescript-eslint won't interfere with any eslint rule until we have the same rule in typescript-eslint, which is not the case here(typescript-eslint do not have space-before-blocks rule). |
Eslint didnt report because it doesnt know about types. So it won't work properly with typescript. I think |
space-before-blocks doesn't control spaces between a keyword and
Maybe the @typescript-eslint/keyword-spacing rule could be updated to support this case, if it doesn't already. |
It's interesting that the rule works well with
We added this check to avoid conflicts with other rules, but there should be no conflicts in this particular case because Wondering if we could change the rule to just not check the type of the previous token if the given block is the body of a function declaration/function expression. |
in this line eslint/lib/rules/space-before-blocks.js Line 102 in 6677180
if we change the following, - if (precedingToken && !isConflicted(precedingToken) && astUtils.isTokenOnSameLine(precedingToken, node)) {
+ if (precedingToken && (['FunctionDeclaration', 'FunctionExpression'].includes(node.type) || !isConflicted(precedingToken)) && astUtils.isTokenOnSameLine(precedingToken, node)) { the rule will be working fine I suppose, (tests are passing) but still, there would be parsing error for types (using the default parser). |
Yes, we could add a fixture parser test. I'd also like to fix some things about reporting, and refactor the code to avoid the |
Yeah, or maybe I am missing something? |
This isn't technically a bug, the rule works fine with JS code. Core rules may or may not work well with TS code. Most of the rules work perfectly well, those that have some complex issues with TS code are usually extended in the typescript plugin. The idea here is to just slightly change the logic where it doesn't affect JS code and in a way that doesn't look unreasonable for JS code, but will make the rule work well with TS code. We used to make such small changes before. |
Coool, |
Hi guys, so what is the conclusion here, will you implement the functionality? Thanks! |
@anikethsaha any update on this? |
I am in support of the change mentioned by @mdjermanovic (that would fix this issue as well. ) . |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Sorry for the delay! I believe the intention of the keyword check was to avoid conflicts with the |
Marking this issue and the PR accepted as there are three 👍 from team members. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
@typescript-eslint/parser
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
Eslint raise 'space-before-blocks' error as there are no space after void and before '{'
What actually happened? Please include the actual, raw output from ESLint.
Eslint passes successfully
Are you willing to submit a pull request to fix this bug?
No
The text was updated successfully, but these errors were encountered: