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

Add ASI (automatic semicolon insertion) support to semicolon rule #363

Closed
antoinerousseau opened this issue Apr 14, 2015 · 15 comments · Fixed by #974
Closed

Add ASI (automatic semicolon insertion) support to semicolon rule #363

antoinerousseau opened this issue Apr 14, 2015 · 15 comments · Fixed by #974

Comments

@antoinerousseau
Copy link

As explained in microsoft/TypeScript#2575

Some coders would like to forget about trailing semicolons, but in some cases it can be a source of errors that are undetected by both the TypeScript compiler and tslint.

Example 1:

function dangerous(): string {
    return
        "watch the semi-colons!"
}
dangerous()

Compiles into:

function dangerous() {
    return;
    "watch the semi-colons!";
}
dangerous();

Example 2:

var foo = true
// some comment
['a', 'b'].forEach((l: string) => {/**/})

compiles into

var foo = true['a', 'b'].forEach(function (l) {/**/})

That would be awesome to see some warnings in these cases, e.g. by turning on a new rule 😍

@ashwinr
Copy link
Contributor

ashwinr commented Apr 14, 2015

@antoinerousseau the semicolon rule already does this for you :)

@ashwinr ashwinr closed this as completed Apr 14, 2015
@antoinerousseau
Copy link
Author

The idea was to allow coding without semicolons (and make it safe), not forcing them.

@ashwinr
Copy link
Contributor

ashwinr commented Apr 14, 2015

I see, so you want a "smarter" option that only flags a warning if it actually causes any harm?

@antoinerousseau
Copy link
Author

Exactly! See discussion @ microsoft/TypeScript#2575

@ashwinr
Copy link
Contributor

ashwinr commented Apr 14, 2015

cool, i'm leaving this open for further discussion. not sure when we can get to this, but we'll consider it. thanks!

@antoinerousseau antoinerousseau changed the title ASI: detect edge cases in comma-free code ASI: detect edge cases in semicolons-free code Apr 15, 2015
@thedmi
Copy link

thedmi commented May 20, 2015

+1

@adidahiya adidahiya changed the title ASI: detect edge cases in semicolons-free code Add ASI (automatic semicolon insertion) support to semicolon rule Aug 4, 2015
@adidahiya
Copy link
Contributor

I think we should support this by allowing 2 options in the semicolon rule: "always" and "never", just like ESLint: http://eslint.org/docs/rules/semi

@antoinerousseau
Copy link
Author

"always" and "never" would be perfect indeed!

@WorldMaker
Copy link

I've been contemplating emulating JavaScript Standard Style in TSLint, and this would be a step in that direction.

@iam3yal
Copy link

iam3yal commented Sep 27, 2015

I'd really love to see an option for "always" and "never" where never will follow ASI so in cases it isn't required it will complain about it.

At the moment I'm using semicolons because TSLint can only enforce semicolons and I want to have a consistent code.

@jkillian jkillian added P2 and removed P1 labels Dec 22, 2015
@Pajn
Copy link
Contributor

Pajn commented Feb 17, 2016

I thought I should create a PR for this, but the check the special cases I would need to know what the first token in the next node is but I can't seem to find a good way to do that.

Anyone that can give a hint?

@adidahiya
Copy link
Contributor

@Pajn I think you'll want to create a scanner to read the next line. You can check out some existing code that uses ts.Scanner.

@Pajn
Copy link
Contributor

Pajn commented Feb 17, 2016

Thanks!

@JakeGinnivan
Copy link

Hey all,

As far as I can tell the Example 2 is not fixed..

var foo = true
// some comment
['a', 'b'].forEach((l: string) => {/**/})

Is still dangerous and is not flagged when using semicolons never.

@adidahiya
Copy link
Contributor

@JakeGinnivan can you please file that as a separate issue if it still exists in the latest version?

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.

9 participants