Prettier 将 import 语句分成两行
我试图防止 prettier 破坏我的代码。当前设置会导致 125 个字符长的导入语句分成 2 行,从而导致错误。
import DiagnosticsResponseMessageContainer from 'components/DiagnosticsResponseMessage/DiagnosticsResponseMessageContainer';
保存后导入行看起来像这样,并且我在下面看到红色的吱吱作响的线条,说我需要 {
来修复它:
import DiagnosticsResponseMessageContainer,
from 'components/DiagnosticsResponseMessage/DiagnosticsResponseMessageContainer';
- 尝试将
printWidth
值更改为 250、1000,并且5000 但这并没有影响行为。 - 检查我是否使用任何其他类似的工具,例如 Beautify,但我没有。
- 添加了推荐的包 tslint-config-prettier 以确保 tslint/prettier 协同工作不会导致此问题
- 尝试在导入行之前添加 // prettier-ignore 。没有改变任何东西
这是保存后 prettier 的输出:
["INFO" - 11:25:39 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 11:25:39 AM] Prettier Options:
{
"filepath": "***",
"parser": "typescript",
"bracketSpacing": true,
"printWidth": 250,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"quoteProps": "preserve"
}
["INFO" - 11:25:39 AM] Formatting completed in 0.091ms.
这里可能有什么问题?
I am trying to prevent prettier from breaking my code. Current setup causes an import statement that is 125 characters long to break into 2 lines which results in an error.
import DiagnosticsResponseMessageContainer from 'components/DiagnosticsResponseMessage/DiagnosticsResponseMessageContainer';
The import line looks like this after save, and I get red squeaky lines under from saying that I need {
to fix it:
import DiagnosticsResponseMessageContainer,
from 'components/DiagnosticsResponseMessage/DiagnosticsResponseMessageContainer';
- Tried changing
printWidth
value to 250, 1000, and 5000 but it didn't affect the behaviour. - Checked if I'm using any other similar tools such as Beautify, but I'm not.
- Added the recommended package
tslint-config-prettier
to make sure tslint/prettier working together not causing this issue - Tried adding // prettier-ignore before the import line. Didn't change anything
This is the output of prettier after save:
["INFO" - 11:25:39 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 11:25:39 AM] Prettier Options:
{
"filepath": "***",
"parser": "typescript",
"bracketSpacing": true,
"printWidth": 250,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"quoteProps": "preserve"
}
["INFO" - 11:25:39 AM] Formatting completed in 0.091ms.
What might be the problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论