我正在尝试在现有项目上设置 dprint。 我当前的设置很简单:
"typescript": {
"quoteStyle": "preferSingle",
"lineWidth": 120,
"semiColons": "asi"
}
这允许我将所有双引号更改为单引号,除非有必要。
不过,我想对此破例,并且在 React 元素内部时默认使用双引号。
const randomString = 'hello i am a random string' // this should default to single quotes
(<Text fontSize="lg">some text</Text>) // this "lg" should default to double quotes
这可能吗?
我之前设置过 Prettier,它允许在 React 上使用双引号,但我认为它只是忽略了代码的 Element 部分。
是的,这应该是可能的。配置参数是
jsx.quoteStyle
(https://dprint.dev/plugins/typescript/config/)。配置应该如下所示:
"typescript": {
"quoteStyle": "preferSingle",
"jsx.quoteStyle": "preferDouble",
"lineWidth": 120,
"semiColons": "asi"
}