简体   繁体   English

VSCODE中import语句自动转换为多行

[英]Import statement automatically converted to multi-line in VSCODE

My VSCode editor automatically wraps import statements into new lines on save or format document:我的 VSCode 编辑器在保存或格式化文档时自动将导入语句包装到新行中:

Before:前: 在此处输入图片说明

After:后:

在此处输入图片说明

I don't want this behaviour.我不想要这种行为。 How to disable this rule?如何禁用此规则?

I am programming in Angular 7 typescript and following extension is installed on it:我正在使用 Angular 7 打字稿进行编程,并在其上安装了以下扩展:

  1. Angular Essentials角度要点
  2. Prettier更漂亮
  3. TSlint特林特

Please, help me to remove this rule or behavior.请帮助我删除此规则或行为。

Thank you.谢谢你。

You cannot disable prettier.printWidth, but you can increase the line-length until it so that it stops wrapping your imports.您不能禁用 prettier.printWidth,但您可以增加 line-length 直到它停止包装您的导入。

You can do this by opening (or creating) a file called prettier.rc in the root dir (one above /src in an Angular project) and adding the property:您可以通过在根目录(Angular 项目中 /src 上方的一个)中打开(或创建)一个名为 prettier.rc 的文件并添加属性来完成此操作:

"printWidth": 250

or whatever number is required.或任何需要的数字。

A word of warning: As the printWidth is a central theme of Prettier - as an opinionated formatter, what you are trying to do may not be the best option in the long-term.警告:由于 printWidth 是 Prettier 的中心主题 - 作为一个固执的格式化程序,从长远来看,您尝试做的事情可能不是最佳选择。

For Angular project, as opposed to using Prettier consider adding new rules to tslint or even creating custom rules where required.对于 Angular 项目,与使用 Prettier 不同,请考虑向 tslint 添加新规则,甚至在需要时创建自定义规则。

This is caused by Prettier. 这是由Prettier引起的。

I don't think you can disable this on its own (short of using a // prettier-ignore comment above the import) but you can try increasing the line length at which prettier starts wrapping with the prettier.printWidth setting 我不认为你可以自己禁用它(在导入之上使用// prettier-ignore注释)但你可以尝试使用prettier.printWidth设置增加更漂亮的开始包装的行长度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 VSCode 的 javascript/typescript 项目中的 JSDoc 注释中编写多行代码的正确方法是什么? - What is the correct way to write multi-line code in JSDoc comment in a javascript/typescript project in VSCode? 在Ionic中动态生成多行列表 - Generate Multi-line List dynamically in Ionic JSX里面的多行JavaScript? - Multi-line JavaScript inside JSX? 无法识别TypeScript多行代码 - TypeScript multi-line code not recognized vscode import import console = require(“console”);自动 - vscode imports import console = require(“console”); automatically 如何在Typescript回调中编写/转换多行JavaScript代码? - How to write/convert multi-line JavaScript code in Typescript callback? 从 React 中的集合创建多行字符串 javascript - Create a multi-line string from a set in React javascript 使用 Typescript (React) 截断带有省略号的文本或行的跨浏览器多行文本 - Cross-browser multi-line text using truncate a text or line with ellipsis using Typescript (React) 在vscode中是否存在用于向现有import语句添加导入的键绑定,或者如何在vscode中动态添加导入? - Is there a keybinding in vscode for add import to an existing import statement or how to add imports on the fly in vscode? eslint object-curly-newline 冲突更漂亮的多行基本原理 - eslint object-curly-newline conflicts prettier multi-line rationale
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM