palantir / tslint

:vertical_traffic_light: An extensible linter for the TypeScript language
http://palantir.github.io/tslint/
Apache License 2.0
5.91k stars 889 forks source link

Code is ruined when prefer-const and another rule are fixed on the same line #2641

Closed Xapphire13 closed 7 years ago

Xapphire13 commented 7 years ago

Bug Report

When multiple rules (one of which being prefer-const) target the same line and you use --fix, the code generated isn't valid TypeScript

TypeScript code being linted

function test() {
    let foo= "foo";
    let foobar = foo + "bar"
}

with tslint.json configuration:

{
  "defaultSeverity": "warning",
  "rules": {
    "prefer-const": true,
    "semicolon": true,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ]
  }
}

Actual behavior

function test() {
    const f oo= "foo";
    const foobar = foo + ";bar"
}

Expected behavior

function test() {
    const foo = "foo";
    const foobar = foo + "bar";
}
adidahiya commented 7 years ago

related: #2326, #2606, #2556