Prettier 将 import 语句分成两行

发布于 2025-01-15 23:00:09 字数 1224 浏览 2 评论 0原文

我试图防止 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文