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

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.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion 3rd party plugin This is an issue related to a 3rd party plugin, config, or parser labels Sep 23, 2020
@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 19, 2020
Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @mdjermanovic!

@btmills btmills merged commit cbf3585 into master Oct 24, 2020
@btmills btmills deleted the issue13553 branch October 24, 2020 00:38
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 23, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3rd party plugin This is an issue related to a 3rd party plugin, config, or parser 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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"space-before-blocks" not working correctly
2 participants