防止函数在其他文件中未使用时被设为“公共”

我试图弄清楚如何防止函数Public在另一个文件中未使用时被创建。

我试图为此寻找规则,但我似乎找不到一个,最接近的是使用explicit-member-accessibility.

到目前为止,我已经尝试通过这样做来解决它

"@typescript-eslint/explicit-member-accessibility": [
    "warn",
    {
        "accessibility": "explicit",
        "overrides": {
            "accessors": "off",
            "constructors": "no-public",
            "methods": "explicit",
            "properties": "off",
            "parameterProperties": "off"
        }
    }
]

但它的问题在于它要求您Public在每个公共方法之前编写。这还需要在现有代码库中编辑大量代码。

如果可能的话,我希望 eslint 能够以这种方式格式化代码

class childClass extends baseClass {
    
    //public method belonging to base class
    //should be `public` since it is used in another file
    baseClassMethod() {
        //some code
    }

    //private method only accessible within the child class
    //should be `private` since it isn't used outside the file
    private childClassMethod() {
        //some code
    }
}

有没有办法解决这个问题或我可能错过的规则?

以上是防止函数在其他文件中未使用时被设为“公共”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>