TSLint 成员排序

TSLint member-ordering

我的 tslint.json 中有以下规则:

    "member-ordering": [
        true,
        {
            "order": [
                "public-before-private",
                "static-before-instance",
                "variables-before-functions"
            ]
        }
    ],

但是我仍然收到此警告:

Warning: member-ordering - Bad member kind: public-before-private

Typescrypt 版本为 3.1.1

节点版本为 10.10.0

如错误消息所述,tslint 无法识别您放入 order 数组的值。在 documentation of the member-ordering rule.

中阅读有关 member-ordering 的内容

您可以在 tslint.json 中指定您想要的确切顺序,或者您可以仅指定一些组件(f.e。让静态方法退出)并且缺少的组件可以保留在 class.

以下配置符合您表达的规则:

"member-ordering": [
    true,
    {
        "order": [
            "public-static-field",
            "public-static-method",
            "public-instance-field",
            "public-constructor",
            "public-instance-method",

            "protected-static-field",
            "protected-static-method",
            "protected-instance-field",
            "protected-constructor",
            "protected-instance-method",

            "private-static-field",
            "private-static-method",
            "private-instance-field",
            "private-constructor",
            "private-instance-method"
        ]
    }
],