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

Feature: Force `else` to go on same line as closing brace #4692

Closed
andy-hanson opened this Issue Dec 14, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@andy-hanson
Copy link

andy-hanson commented Dec 14, 2015

Since I'm using "1tbs" for "brace-style", I prefer an else statement to go on the same line as the closing curly brace of an if statement.

However, eslint does not warn for this code:

if (true) {
    console.log(1)
    console.log(2)
}
else
    console.log(3)

presumably because the else statement here does not have braces.

It would be nice if there were a way to detect this anyway. I would like to force code to look like:

if (true) {
    console.log(1)
    console.log(2)
} else
    console.log(3)

See also #4591.

@eslintbot

This comment has been minimized.

Copy link

eslintbot commented Dec 14, 2015

@andy-hanson Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage label Dec 14, 2015

@ilyavolodin ilyavolodin added bug rule accepted and removed triage labels Dec 14, 2015

@ilyavolodin

This comment has been minimized.

Copy link
Member

ilyavolodin commented Dec 14, 2015

Reproducible in online demo.

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 15, 2015

Working on this.

@nzakas nzakas closed this in 44a57ce Dec 16, 2015

ilyavolodin added a commit that referenced this issue Dec 16, 2015

Merge pull request #4717 from eslint/issue4692
Fix: Check 1tbs non-block else (fixes #4692)

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.