忽略“命名范围”中的className

发布于 2025-01-23 18:43:01 字数 894 浏览 1 评论 0 原文

我正在使用尾风,反应和eslint。

我有当前的配置

        "@typescript-eslint/naming-convention": [
          "error",
          {
            "selector": "default",
            "format": ["camelCase", "UPPER_CASE", "PascalCase"],
            "leadingUnderscore": "allow",
            "trailingUnderscore": "allow"
          },
          {
            "selector": "variable",
            "format": ["camelCase", "UPPER_CASE", "PascalCase"],
            "leadingUnderscore": "allow",
            "trailingUnderscore": "allow"
          },
          {
            "selector": "typeLike",
            "format": ["PascalCase"]
          }
        ],

,但是在代码中,当我使用className库时,我必须执行以下操作:

   className={
     classNames({
     'py-2 pl-8 pr-4 cursor-pointer ':true,
     })
    }

哪个打破规则...

我想知道我是否可以忽略 className之间的任何内容({{ ***})

I am using tailwind and react, and eslint.

I have the current configuration

        "@typescript-eslint/naming-convention": [
          "error",
          {
            "selector": "default",
            "format": ["camelCase", "UPPER_CASE", "PascalCase"],
            "leadingUnderscore": "allow",
            "trailingUnderscore": "allow"
          },
          {
            "selector": "variable",
            "format": ["camelCase", "UPPER_CASE", "PascalCase"],
            "leadingUnderscore": "allow",
            "trailingUnderscore": "allow"
          },
          {
            "selector": "typeLike",
            "format": ["PascalCase"]
          }
        ],

But in the code, when I use classname library I have to do the following :

   className={
     classNames({
     'py-2 pl-8 pr-4 cursor-pointer ':true,
     })
    }

Which break the rules...

I would like to know if I can ignore the convention for anything in between classname({***})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你的星星会说话 2025-01-30 18:43:01

要忽略 classNames 呼叫中的所有内容,您需要类似于 indent 规则<代码> brim> noce 可以访问AST的内容,但我可以' t查找@typescript-eslint/naming-convention 的类似选项。

一个解决方法是在忽略需要报价的属性

{
    "selector": "property",
    "format": ["strictCamelCase"],
    "filter": {
         "regex": "[- ]",
         "match": false
    }
}

如果您愿意更改代码编写约定而不是工具配置,则可以简单地简单以不同的方式写出类表达式:

classNames(
  foo == bar && 'py-2 pl-8 pr-4 cursor-pointer',
  baz > 0 ? 'rounded' : 'rounded-xl'
)

To ignore everything inside a classNames call, you’d need something similar to the indent rule’s ignoredNodes that has access to the AST but I couldn’t find a similar option for @typescript-eslint/naming-convention.

A workaround would be to follow the documentation’s example on ignoring properties that require quotes with e.g.

{
    "selector": "property",
    "format": ["strictCamelCase"],
    "filter": {
         "regex": "[- ]",
         "match": false
    }
}

If you're willing to change your code writing convention instead of your tooling configuration, you could also simply write the class expression differently:

classNames(
  foo == bar && 'py-2 pl-8 pr-4 cursor-pointer',
  baz > 0 ? 'rounded' : 'rounded-xl'
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文