red*_*ter 3 visual-studio-code prettier
我在 React 中编写代码,并且总是使用箭头函数。当我在 JS 函数中使用单个参数时,我喜欢不使用括号。我总是使用箭头函数,但我经常使用 Prettier,它会自动将我的所有参数括在括号中。有什么方法可以让 Prettier 不包装参数吗?
Ans*_*onH 12
您正在寻找的选项是“箭头函数括号”。转到您的 Prettier 配置(例如在.prettierrc文件中)并添加此键:
"arrowParens": "avoid"
Run Code Online (Sandbox Code Playgroud)
该选项的作用示例:
// Before formatting
const foo = (x) => 10;
const bar = (x, y) => 20;
// After formatting
const foo = x => 10;
const bar = (x, y) => 20;
Run Code Online (Sandbox Code Playgroud)
阅读更多:如何添加自定义 Prettier 配置
| 归档时间: |
|
| 查看次数: |
2751 次 |
| 最近记录: |