How do I configure Prettier not to wrap my multiline interface property value in a way that breaks @typescript-eslint/key-spacing?

huangapple go评论61阅读模式
英文:

How do I configure Prettier not to wrap my multiline interface property value in a way that breaks @typescript-eslint/key-spacing?

问题

Prettier会将我的icon属性格式化为以下方式:

export interface ListIconProps {
  icon:
    | (OverridableComponent<SvgIconTypeMap<{}, 'svg'>> & { muiName: string })
    | (() => JSX.Element)
  primary?: boolean
}

这破坏了我的代码检查器(linter):

   8:3  错误  缺少在键' icon '之前的值的空格  @typescript-eslint/key-spacing
  28:3  错误  缺少在键' icon '之前的值的空格  @typescript-eslint/key-spacing

如何配置Prettier以符合默认的key-spacing规则?

还尝试在eslint.js中添加了一个例外情况,但效果不太好。

英文:

Prettier keeps formatting my icon property like this:

export interface ListIconProps {
  icon:
    | (OverridableComponent&lt;SvgIconTypeMap&lt;{}, &#39;svg&#39;&gt;&gt; &amp; { muiName: string })
    | (() =&gt; JSX.Element)
  primary?: boolean
}

which breaks my linter:

   8:3  error  Missing space before value for key &#39;icon&#39;  @typescript-eslint/key-spacing
  28:3  error  Missing space before value for key &#39;icon&#39;  @typescript-eslint/key-spacing

How can I configure Prettier to format this in a way that conforms with the default rules for key-spacing?

Also tried making an exception in eslint.js which didn't go too well

答案1

得分: 1

你可以使用注释来禁用项目或特定文件或行的ESLint key-spacing规则,如/* eslint-disable key-spacing */// eslint-disable-line key-spacing。这将允许Prettier格式化您的代码而不触发ESLint错误。

例如:

export interface ListIconProps {
  icon: // eslint-disable-line key-spacing
    | (OverridableComponent<SvgIconTypeMap<{}, 'svg'>> & { muiName: string })
    | (() => JSX.Element)
  primary?: boolean
}
英文:

You can disable the ESLint key-spacing rule for your project or for specific files or lines using comments, such as /* eslint-disable key-spacing */ or // eslint-disable-line key-spacing. This will allow Prettier to format your code without triggering ESLint errors.

For example:

export interface ListIconProps {
  icon: // eslint-disable-line key-spacing
    | (OverridableComponent&lt;SvgIconTypeMap&lt;{}, &#39;svg&#39;&gt;&gt; &amp; { muiName: string })
    | (() =&gt; JSX.Element)
  primary?: boolean
}

huangapple
  • 本文由 发表于 2023年7月7日 06:13:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定