我正在运行Prettier.js(VSCode插件)/ prettier-eslint-cli.它格式化超过80个字符限制的方法参数,如下所示(将每个参数放在一个新行上)
someMethod(
argumentOne,
argumentTwo,
argumentThree,
argumentFour,
argumentFive,// Hits 80 character word wrap here
argumentSix,
argumentSeven
) {
//Some Code
}
Run Code Online (Sandbox Code Playgroud)
有没有办法修改选项,以便格式化参数,以尝试在每行上适合80个字符?而不是每次只将它们添加到新行
someMethod(argumentOne, argumentTwo, argumentThree, argumentFour,
argumentFive, argumentSix, argumentSeven) {
//Some Code
}
Run Code Online (Sandbox Code Playgroud)
Fei*_*bow 10
在 VSC 窗口中右键单击并选择“命令面板”。搜索“prettier”并选择“创建配置文件”,它将打开您选择文件夹窗口(选择您要保存prettier配置文件的文件夹),然后打开配置文件并添加您要更改的选项。例子:
{
"printWidth": 150
}
Run Code Online (Sandbox Code Playgroud)
据我所知,目前没有这样做的选择。当您的参数超过 printWidth(默认为 80)时,prettier 会将每个参数分成单独的一行。
一种方法是增加 printWidth 选项,以便您的参数保持在同一行。更漂亮的文档提到maximum line length rules are often set to 100 or 120(https://prettier.io/docs/en/options.html)