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: add beforeStatementContinuationChars to semi (fixes #9521) #9594

Merged
merged 3 commits into from
Nov 26, 2017

Conversation

mysticatea
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] Changes an existing rule: fixes #9521.

What changes did you make? (Give an overview)

This PR adds a new option beforeUnreliableLineButSafe to semi rule. This option specifies the behavior about semicolons (or lacking semicolons) which satisfy the following two condition:

  1. The semicolon (or lacking semicolon) is followed by the tokens which can make ASI hazard ([, (, +, -, or `).
  2. But the semicolon (or lacking semicolon) does not make ASI hazard because the next token does not connect to the previous statement.

For example:

import a from "a"
[1,2,3].forEach(doSomething)

The option can be one of three values:

  • { beforeUnreliableLineButSafe: "any" } ignores the semicolons (or lacking semicolon). This is the default. This is the current behavior.
  • { beforeUnreliableLineButSafe: "always" } requires the semicolons.
  • { beforeUnreliableLineButSafe: "never" } disallow the semicolons.

Is there anything you'd like reviewers to focus on?

The option name beforeUnreliableLineButSafe is not the best name. Does somebody have a better idea?

@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Nov 8, 2017
@not-an-aardvark
Copy link
Member

The option name beforeUnreliableLineButSafe is not the best name. Does somebody have a better idea?

Maybe something like beforeStatementContinuationChars? A "statement continuation character" would be something like ( or [. (I'm not sure if there is a standard name for characters like ( and [.)

Object option (when `"never"`):

* `"beforeUnreliableLineButSafe": "always"` requires semicolons at the end of statements if the next line starts with `[`, `(`, `/`, `+`, or `-`.
* `"beforeUnreliableLineButSafe": "never"` disallows semicolons as the end of statements if it doesn't make ASI hazard even if the next line starts with `[`, `(`, `/`, `+`, or `-`.
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify the default value of beforeUnreliableLineButSafe when never is used? (Is it "ignore"? If so, should we add an explicit "ignore" option?)

Copy link
Member Author

Choose a reason for hiding this comment

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

OK.

I was hovering between adding the description of "any" or not because similar omitLastInOneLineBlock option does not have the description about its default value.

@mysticatea
Copy link
Member Author

I updated this PR.

Copy link
Member

@platinumazure platinumazure 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!

@not-an-aardvark not-an-aardvark changed the title Update: add beforeUnreliableLineButSafe option to semi (fixes #9521) Update: add beforeStatementContinuationChars option to semi (fixes #9521) Nov 26, 2017
@not-an-aardvark not-an-aardvark changed the title Update: add beforeStatementContinuationChars option to semi (fixes #9521) Update: add beforeStatementContinuationChars to semi (fixes #9521) Nov 26, 2017
@not-an-aardvark not-an-aardvark merged commit 71eedbf into master Nov 26, 2017
@not-an-aardvark not-an-aardvark deleted the semi/new-option branch November 26, 2017 02:42
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 26, 2018
@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 May 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 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.

false negative of semi rule with never option
4 participants