Update: skip keyword check for fns in space-before-blocks (fixes #13553) #13712
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[X] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
fixes #13553
This change can produce more warnings in TypeScript code. It shouldn't make any difference for JS code.
Currently,
space-before-blocks
reports error in the following code:But, it doesn't report an error if the return type happens to end with a keyword token, like
void
:This PR aims to fix this inconsistency and make the rule work better with TS.
What changes did you make? (Give an overview)
Changed
space-before-blocks
rule to skip the keyword check before blocks that represent a function body. In other words, to enforce spacing before function body blocks even if the preceding token is a keyword.This rule generally doesn't enforce spacing between keywords and blocks, to avoid conflicts with the
keyword-spacing
rule. However,keyword-spacing
enforces spacing only around keywords that appear in certain contexts, which doesn't include type annotations before function body blocks, so there are no conflicts in that range.Is there anything you'd like reviewers to focus on?
I'd also like to refactor the confusing
{ASTNode|Token}
logic in another PR. It mistakenly reports{
of aswitch
statement as a node, and also produces inconsistent locations.