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

Semicolon rule should flag unnecessary semicolons on class member functions #1476

Closed
adidahiya opened this issue Aug 11, 2016 · 8 comments · Fixed by #1643
Closed

Semicolon rule should flag unnecessary semicolons on class member functions #1476

adidahiya opened this issue Aug 11, 2016 · 8 comments · Fixed by #1643

Comments

@adidahiya
Copy link
Contributor

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.

@jkillian
Copy link
Contributor

jkillian commented Oct 5, 2016

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

@mprobst
Copy link
Contributor

mprobst commented Dec 13, 2016

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.

@adidahiya
Copy link
Contributor Author

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.

@mprobst
Copy link
Contributor

mprobst commented Dec 13, 2016

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.

@bertyhell
Copy link

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

@popstr
Copy link

popstr commented Apr 18, 2017

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/

@robertpenner
Copy link

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

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

@rkrisztian
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants