Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Support else / catch on next line #12

Closed
Bartvds opened this issue Aug 15, 2013 · 11 comments
Closed

Support else / catch on next line #12

Bartvds opened this issue Aug 15, 2013 · 11 comments
Labels
Formatting rule Relates to a rule which enforces code formatting and likely overlaps with prettier Type: Enhancement

Comments

@Bartvds
Copy link
Contributor

Bartvds commented Aug 15, 2013

It should be possible to enforce the position of trailing block headers like else/catch statements:

Currently this is expected:

if (myVar) {
    //...
} else {
    //...
}

Otherwise you get the 'misplaced else' warning.

But we want the trailing block bumped a line like this::

if (myVar) {
    //...
}
else {
    //...
}

Or for try/catch

try {
    //..
}
catch (e) {
    //..
}
finally {
    //..
}

An all other similar structures.

We find it easier to read as the keyword is tight on the left margin and the closing brace's position enforces a nearly blank line, just like in the starting block.

@Bartvds
Copy link
Contributor Author

Bartvds commented Aug 15, 2013

I can toggle it with the oneline rule.

I think it should be split to it's own rule: it is not the same thing as oneline's "opening brace to be on the same line as the expression preceding it".

@ashwinr
Copy link
Contributor

ashwinr commented Aug 15, 2013

sure, makes sense.

@ashwinr
Copy link
Contributor

ashwinr commented Aug 16, 2013

made all checks optional, fixed by 5cd203a

@ashwinr ashwinr closed this as completed Aug 16, 2013
@eirikhm
Copy link

eirikhm commented Mar 30, 2015

It would be great if next-line braces was a rule as well. Solving it by ignoring the "oneline" rule is not ideal.

@gscshoyru
Copy link
Contributor

Can you give us an example of what you mean, @eirikhm? If you want your braces to be on the next line, why do you want to one-line rule enabled at all?

@eirikhm
Copy link

eirikhm commented Mar 31, 2015

Let me clarify:

I'd like a rule which checks if braces are on the next line, and that it complains if they are on the same line.

As far as I could tell there is no way to enforce this.

@jkjustjoshing
Copy link

jkjustjoshing commented Dec 22, 2016

Is there any way to enforce the opposite of check-else? I want to enforce the following style:

if (expr) {
    // code
}
else {
    // code
}

and restrict the following style:

if (expr) {
    // code
} else {
    // code
}

EDIT - this can be accomplished with tslint-eslint-rules

mohsen1 pushed a commit to mohsen1/tslint that referenced this issue Jan 28, 2017
@JoshMcCullough
Copy link

Agreed, why not add the inverse to force blocks to their own line?

@adidahiya adidahiya added the Formatting rule Relates to a rule which enforces code formatting and likely overlaps with prettier label Mar 7, 2019
@sam-s4s
Copy link

sam-s4s commented Jul 4, 2019

Is there any way to enforce the opposite of check-else? I want to enforce the following style:

if (expr) {
    // code
}
else {
    // code
}

and restrict the following style:

if (expr) {
    // code
} else {
    // code
}

This is a very common requirement - I've just found out it's not supported in tslint and I'm a bit surprised... I thought this was exactly the type of thing tslint was for?

@JoshuaKGoldberg
Copy link
Contributor

@sam-s4s see #4534

@sam-s4s
Copy link

sam-s4s commented Jul 7, 2019

Aww that's almost a bit sad :( lol

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Formatting rule Relates to a rule which enforces code formatting and likely overlaps with prettier Type: Enhancement
Projects
None yet
Development

No branches or pull requests

9 participants