英文:
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<SvgIconTypeMap<{}, 'svg'>> & { muiName: string })
| (() => JSX.Element)
primary?: boolean
}
which breaks my linter:
8:3 error Missing space before value for key 'icon' @typescript-eslint/key-spacing
28:3 error Missing space before value for key 'icon' @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<SvgIconTypeMap<{}, 'svg'>> & { muiName: string })
| (() => JSX.Element)
primary?: boolean
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论