Vscode-eslint: autoFixOnSave doesn't work for TypeScript

Created on 29 Aug 2017  路  1Comment  路  Source: microsoft/vscode-eslint

Hi! It looks like the auto fix on save doesn't work for TypeScript files. JavaScript seems to be fine.

{
  "parser": "typescript-eslint-parser",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "modules": true,
      "jsx": true
    }
  },
  "rules": {
    "spaced-comment": ["error", "always"]
  }
}
{
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ]
}
//foo

This will be fixed in a .js file, but not in a .ts file. The error is shown in both cases correctly.

question

Most helpful comment

You need to tell ESLint to enable autoFix for TS. This can be done like this:

{
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {"language": "typescript", "autoFix": true },
    {"language": "typescriptreact", "autoFix": true }
  ]
}

AutoFix is only enabled by default for JS. There were quite some problems with parser and autofix computing wrong fixes and therefore breaking the code. So I made this an opt in.

>All comments

You need to tell ESLint to enable autoFix for TS. This can be done like this:

{
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {"language": "typescript", "autoFix": true },
    {"language": "typescriptreact", "autoFix": true }
  ]
}

AutoFix is only enabled by default for JS. There were quite some problems with parser and autofix computing wrong fixes and therefore breaking the code. So I made this an opt in.

Was this page helpful?
0 / 5 - 0 ratings