2

我使用 prettier 和 tslint,以及https://github.com/alexjoverm/tslint-config-prettierhttps://github.com/ikatyang/tslint-plugin-prettier

tslint.json的就像

{
  "defaultSeverity": "error",
  "extends": [
    "tslint-config-airbnb",
    "tslint-react",
    "tslint-config-prettier"
  ],
  "jsRules": {},
  "rules": {
    "max-line-length": [true, 80],
    "import-name": false,
    "variable-name": false,
    "jsx-boolean-value": false,
    "jsx-no-multiline-js": false,
    "no-else-after-return": false,
    "object-shorthand-properties-first": false,
    "ter-arrow-parens": false,
    "ter-indent": false,
    "prettier": true
  },
  "rulesDirectory": ["tslint-plugin-prettier"]
}

.prettierrc的就像

{
  "trailingComma": "all",
  "singleQuote": true
}

之后tslint --fix "src/**/*.ts",出现如下代码:

import { getChildrenProceduresSelector } from '@src/entities/procedures/selectors';

错误说[tslint] Exceeds maximum line length of 80 (max-line-length)

但是当我手动修复它时

import {
  getChildrenProceduresSelector,
} from '@src/entities/procedures/selectors';

它说

[tslint] Replace `⏎··getChildrenProceduresSelector,⏎` with `·getChildrenProceduresSelector·` (prettier)

我将 VSCode 与 tslint 和更漂亮的扩展一起使用。我的 tslint 命令说同样的错误。如何解决这种冲突?

4

1 回答 1

8

您的配置中的错误来自"max-line-length": [true, 80]. 它与更漂亮的规则相冲突。如果要设置max-line,应该在.prettiercfile ->"printWidth": 80中进行。

tslint-config-prettiertslint - 此配置禁用与冲突的所有规则prettier(因此,在您的情况下,此插件max-line从禁用tslint,但随后您在rules部分中手动设置)

tslint-plugin-prettier - 这个插件运行更漂亮的规则作为tslint规则。此外,您需要ruletslint.json.

考虑到所有这些,您的配置应该或多或少像这样:

// With tslint@5.0.0+
{
  "extends": [
    "tslint-config-airbnb",
    "tslint-config-prettier",
    "tslint-plugin-prettier"
  ],
  "rules": {
    "prettier": true
  }
}

// With tslint@5.2.0+
{
  "extends": [
    "tslint-config-airbnb",
    "tslint-config-prettier",
    "tslint-plugin-prettier"
  ],
  "rules": {
    "prettier": true
  },
  "rulesDirectory": [
    "tslint-plugin-prettier"
  ]
}
于 2018-08-15T12:03:31.033 回答