gpt4 book ai didi

javascript - 使用 ESLint 而不是 PascalCase 强制执行 camelCase

转载 作者:行者123 更新时间:2023-12-03 07:13:28 24 4
gpt4 key购买 nike

我正在为我的项目设置 ESlint,我有一个问题。

我希望以下工作:

class MyClass {

}

function awesomeFunction() {

}

let myVariable = "a";

但不是这个:

class myClass {

}

function AwesomeFunction() {

}

let MyVariable = "a";

我希望所有变量和函数都是 camelCase(而不是 PascalCase),所有类都是 PascalCase(而不是 camelCase)。

有人可以帮我吗?
提前致谢!

最佳答案

现在 typescript 似乎可以做到这一点。
根据https://github.com/typescript-eslint/typescript-eslint/pull/1318你可以像这样指定配置:

{
"@typescript-eslint/naming-conventions": ["error",
{ selector: "default", format: ["camelCase"] },

{ selector: "variableLike", format: ["camelCase"] },
{ selector: "variable", format: ["camelCase", "UPPER_CASE"] },
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },

{ selector: "memberLike", format: ["camelCase"] },
{ selector: "memberLike", modifiers: ["private"], format: ["camelCase"], leadingUnderscore: "require" },

{ selector: "typeLike", format: ["PascalCase"] },
{ selector: "typeParameter", format: ["PascalCase"], prefix: ["T"] },

{ selector: "interface", format: ["PascalCase"], custom: { regex: "^I[A-Z]", match: false } },
],
}

关于javascript - 使用 ESLint 而不是 PascalCase 强制执行 camelCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57980912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com