TSLint 中的 `extends` 和 `rulesDirectory` 有什么区别

What is the difference between `extends` and `rulesDirectory` in TSLint

TSLint.json 配置文件 (https://github.com/palantir/tslint) 支持 extends 和像这样的 rulesDirectory 数组

{
  "extends": [
    "tslint-microsoft-contrib",
    "tslint-config-security"
  ],
  "rulesDirectory": [
    "node_modules/tslint-eslint-rules/dist/rules",
    "node_modules/tslint-microsoft-contrib",
    "node_modules/tslint-config-security"
  ]
}

对于不熟悉该工具的新用户,文档似乎有点开放解释。

如果有人能就 extendsrulesDirectory 在 VS Code 编辑器中的使用和一般 tslinting 的行为澄清几点,我将不胜感激。

  1. 是否extends 提供默认配置(如果包提供)?

  2. 因此这与 rulesDirectory 不同吗?

    • 是否 rulesDirectory 仅提供规则供您专门选择加入(如果在根 tslint.json 中指定规则则需要)?

    • 我是否仍应在 extends 中指定 tslint 软件包 rulesDirectory?

  3. 假设 extends 提供来自另一个 tslint 配置文件的默认值,我是否能够指定 rulesDirectory 并添加一个规则来覆盖特定标志?

担心,因为只有一些规则出现在 IntelliSense 自动完成中,只有一些行为我希望更清楚。

?答案取自 tslint configuration docs as of 6 April 2018:

  • extends?: string | string[]: The name of a built-in configuration preset (see built-in presets below), or a path or array of paths to other configuration files which are extended by this configuration. This value is handled using node module resolution semantics. For example, a value of "tslint-config" would tell TSLint to try and load the main file of a module named "tslint-config" as a configuration file. Specific files inside node modules can also be specified, eg. "tslint-config/path/to/submodule". Relative paths to JSON files or JS modules are also supported, e.g. "./tslint-config".
  • rulesDirectory?: string | string[]: A path to a directory or an array of paths to directories of [custom rules][2]. These values are handled using node module resolution semantics, if an index.js is placed in your rules directory. We fallback to use relative or absolute paths, if the module can't be resolved. If you want to avoid module resolution you can directly use a relative or absolute path (e.g. with ./).

在此 rules 块中指定的任何规则将覆盖在任何正在扩展的基本配置中配置的规则。

What is the difference between extends and rulesDirectory in TSLint

它们非常不同。

  • extends 允许您应用现有的 tslint 配置然后扩展它
  • rulesDirectory 只允许您为自定义规则添加目录。

看看docs

似乎主要区别是:

  • "extends" 使用内置 规则集

  • "rulesDirectory" 使用 custom(你自己的,不是内置的)规则