【问题标题】:Disable @typescript-eslint/naming-convention for imported types禁用导入类型的@typescript-eslint/naming-convention
【发布时间】:2022-12-16 07:00:03
【问题描述】:

不将 @typescript-eslint/naming-convention 规则应用于从 3rd 方库导入的类型的策略是什么?不得不处理我们无法控制的类型以及包含不符合我们自己约定的名称的类型是很常见的。有时这可能有很多不同的名称,因此我们希望避免每隔一行代码使用 // eslint-disable-next-line @typescript-eslint/naming-convention

【问题讨论】:

  • 你有没有得到答案?我现在也在研究这个。 zod 出于某种原因正在使用 snake_case

标签: eslint


【解决方案1】:

我在 GitHub 问题上找到了答案,尽管它可能不是您要找的。

您可以有选择地忽略在命名约定中强制执行的某些名称。这是一个示例设置:

"@typescript-eslint/naming-convention": [
  "warn",
  {
    selector: "property",
    format: ["camelCase"],
  },
  {
    selector: "property",
    format: null,
    filter: {
      regex: "(required_error|invalid_type_error)",
      match: true,
    },
  },
],

第一条规则要求所有属性都必须在camelCase 中。第二条规则增加了这种情况的例外情况。在我们的特定场景中,我们正在使用 Zod,并且 Zod 在对象中具有被方法接受的属性,如 required_errorinvalid_type_error

无论如何,希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2022-11-10
    • 2019-08-11
    • 2021-06-02
    • 2020-12-11
    • 2019-11-14
    • 2020-01-25
    相关资源
    最近更新 更多