如何 select 自定义 .jscsrc 文件

How to select a custom .jscsrc file

我们有多个项目,其中包含各种 .jscsrc 文件。 我想使用我定义的一个,它比大多数项目更严格。

在我的例子中是 ~/.jscsrc

如何配置 sublime-linter 以将该文件用于 jscs

谢谢!

SublimeLinter 正在您的系统上执行 jscs。要使用 CLI 为 jscs 定义配置文件 (according to the docs) 的路径,您需要 运行:

jscs path[ path[...]] --config=~/.config.json

要为 SublimeLinter 包设置此项,您可以对 jscs 使用 SublimeLinter's args setting 并设置配置路径。这将在您的 SublimeLinter.sublime-settings(默认或用户)中:

{
    "user": {
        "linters": {
            "jscs": {
                "args": [
                    "--config=~/.jscsrc"
                ]
            }
        }
    }  
}

或者,您也可以只使用 "args": "--config=~/.jscsrc"

注意,from the docs

If there is no --config option specified, jscs it will consequentially search for jscsConfig option in package.json file then for .jscsrc (which is a just JSON with comments) and .jscs.json files in the current working directory then in nearest ancestor until it hits the system root.

此外,.jscsrc 文件的路径被缓存,因此如果您创建一个新的 .jscsrc 应该优先于前一个(根据上述),您需要清除linter 的缓存使用新 .jcscrc 您可以通过以下方式清除缓存:Tools > SublimeLinter > Clear Caches.

您还可以使用相同的方法覆盖 default/global 设置并将其用于其他包,如果适用且 linter 支持的话。另一个很好的例子是 SublimeLinter-jshint plugin.