【问题标题】:Enable TSlint ordered-imports rule with module-source-path使用模块源路径启用 TSlint 有序导入规则
【发布时间】:2019-02-11 20:19:35
【问题描述】:

我正在尝试将我的 TSLint 规则配置为包括:ordered-importsmodule-source-path。我想要有规则,其中导入首先按路径排序,然后是具有单独组的源(1grp = 外部库,2grp = 内部源)。自动修复对我来说也很重要。

正确排序的导入示例:

import { CommonModule } from '@angular/common';
import { Observable } from 'rxjs';

import { MainComponent } from 'app/components/main.component';
import { MainService } from 'app/services/main.service';

我将此添加到我的tslint.json

"ordered-imports": [
        true,
        {
            "import-sources-order": "any",
            "named-imports-order": "case-insensitive",
            "grouped-imports": true,
            "module-source-path": "full"
        }
    ],

我的 WebStorm 在行 "grouped-imports": true,"module-source-path": "full" 上抛出错误/警告,说“不允许使用属性 'X'”(其中 X 是这些选项之一)。根据文档https://palantir.github.io/tslint/rules/ordered-imports/ 可以添加它。

有趣的是,GitHub 上的这条规则只有 4 个选项中的 3 个

使用:TSLint 5.11.0WebStorm 2018.2.2

我做错了吗?还有其他方法可以应用这些规则吗?

编辑: 顺便说一句,警告是一回事,另一件事是这两条规则根本不起作用 - linter 不会像这样的导入调用错误:

import { MainService } from 'app/services/main.service';
import { MainComponent } from 'app/components/main.component';

【问题讨论】:

    标签: typescript webstorm tslint


    【解决方案1】:

    选项有效;问题是捆绑的 tslint JSON 模式文件经过验证不是最新的。 登录为WEB-34689,请关注更新。 目前我只能建议在 Settings | 中禁用 Compliance with JSON schema 检查。编辑 |检查 JSON 和 JSON5 以抑制错误

    【讨论】:

    猜你喜欢
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2015-12-06
    • 1970-01-01
    • 2019-06-12
    • 2018-04-20
    • 2021-09-12
    相关资源
    最近更新 更多