Tslint: Semicolon rule should flag unnecessary semicolons on class member functions

Created on 11 Aug 2016  ·  8Comments  ·  Source: palantir/tslint

We changed the behavior of the semicolon rule to allow omission of the trailing semicolon after bound class member functions:

class Foo {
  public renderFoo = () => {
    return null;
  }
   ^ right here
}

I propose that we actually _ban_ semicolons at that location in TSLint 4.0. We can support the old functionality with a new option allow-bound-class-methods.

Easy P2 Fixed Breaking Change Enhancement

Most helpful comment

For people coming to this thread looking for the correct tslint config (as I did) - the correct syntax for this would be:
"semicolon": [true, "always", "ignore-bound-class-methods"]

See: https://palantir.github.io/tslint/rules/semicolon/

All 8 comments

I'm not convinced this is need for 4.0, but wouldn't hurt to get it in either. It does seem like a little bit of a minute option though, I'm not entirely convinced it's worth the added complexity

Just as a feedback item (not sure if this is the right venue?), we just stumbled across this, and were very surprised this.

I probably don't quite understand the rationale behind this, but in particular that tslint flags semicolons as unnecessary in this position (i.e. doesn't just accept leaving them out) seems confusing.

You can get the old behavior back with the ignore-bound-class-methods option. We wanted to be a little more opinionated with the default configuration and make bound class methods look like regular class methods in most TS code.

Yeah, I figured so much. I'd have expected tslint to out-of-the-box require that semicolon, erring more on the side of consistency, or ignoring the issue, but adding that option back in works for us.

I tried to get this to stop throwing errors in intellij

I tried removing the semicolon behind class arrow functions, then i get this warning:
image

I tried enabling the option like this:
image

But i get this result:
image

I tried enabling the option like this:
image

But then it stops checking for semicolons all together.

tslint version: 4.4.2
ts version: 2.1.5
intellij version: 2016.3
OS: windows 10 x64

For people coming to this thread looking for the correct tslint config (as I did) - the correct syntax for this would be:
"semicolon": [true, "always", "ignore-bound-class-methods"]

See: https://palantir.github.io/tslint/rules/semicolon/

@popstr Yes, that's what I'm using as well.

"semicolon": [true, "always", "ignore-bound-class-methods"]

I've created #3216 because ignoring is a bad idea in terms of consistency, and the rule without the ignore-bound-class-methods option is still buggy as I found out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

allbto picture allbto  ·  3Comments

mrand01 picture mrand01  ·  3Comments

ghost picture ghost  ·  3Comments

cateyes99 picture cateyes99  ·  3Comments

dashmug picture dashmug  ·  3Comments