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

Update: skip keyword check for fns in space-before-blocks (fixes #13553) #13712

Merged
merged 1 commit into from Oct 24, 2020

Conversation

@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Sep 23, 2020

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:

/* eslint space-before-blocks: ["error", "always"] */

function foo(): string{} // error

But, it doesn't report an error if the return type happens to end with a keyword token, like void:

/* eslint space-before-blocks: ["error", "always"] */

function foo(): void{} // no errors

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 a switch statement as a node, and also produces inconsistent locations.

Copy link
Member

@btmills btmills left a comment

LGTM. Thanks @mdjermanovic!

@btmills btmills merged commit cbf3585 into master Oct 24, 2020
12 checks passed
12 checks passed
Verify Files
Details
Test (ubuntu-latest, 14.x)
Details
Test (ubuntu-latest, 13.x)
Details
Test (ubuntu-latest, 12.x)
Details
Test (ubuntu-latest, 10.x)
Details
Test (ubuntu-latest, 10.12.0)
Details
Test (windows-latest, 12.x)
Details
Test (macOS-latest, 12.x)
Details
Browser Test
Details
commit-message Commit message follows guidelines
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details
@btmills btmills deleted the issue13553 branch Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.