Dav*_*vid 5 import formatting tslint visual-studio-code prettier
我正在使用VSCode和更漂亮的插件,打字稿以及tslint。
抛开使用此配置的便利性,我得到了一个
[tslint] Exceeds maximum line length of 120 (max-line-length)
Run Code Online (Sandbox Code Playgroud)
对于这样的一行:
import { MyComponent } from "../../some_very_long_path";
Run Code Online (Sandbox Code Playgroud)
我已经配置了100的打印宽度,因此我希望在Format Document这一行上可以将其重构为以下形式:
import { MyComponent }
from "../../some_very_long_path";
Run Code Online (Sandbox Code Playgroud)
或像这样:
import {
MyComponent
} from "../../some_very_long_path";
Run Code Online (Sandbox Code Playgroud)
但事实并非如此。有什么想法吗?
小智 23
文档说printWidth。文档链接在这里
printWidth: 120
Run Code Online (Sandbox Code Playgroud)
也许这应该可以解决问题。
您可以为特定的正则表达式添加例外。Prettier 将在管理导入和导出方面处于领先地位,因为它有一种特殊的方式来处理它们。
// edit your tslint.json
"max-line-length": [
true,
{
"limit": 140,
"ignore-pattern": "^import |^export {(.*?)}"
}
],
Run Code Online (Sandbox Code Playgroud)
Prettier 不会分解导入,您能做的最好的事情就是从 tslint 规则中删除所有风格错误(包括最大行长度),并让 Prettier 处理这些错误并 tslint 与代码相关的错误。
| 归档时间: |
|
| 查看次数: |
2689 次 |
| 最近记录: |