我不知道这是否是VS Code的默认行为,(在默认代码的基础上,我有很多自定义配置)
但是,当我格式化代码时,它会转换这样的代码:
const simpleInput = (
<Input
{...input}
{...others}
state={state}
/>
);
进入 :
const simpleInput = (
<Input
{...input}
{...others}
state={state}
/> <- Here is the difference
);
我的es-lint对此发出了警告
[eslint] The closing bracket must be aligned with the line containing the opening tag (expected column 5) (react/jsx-closing-bracket-location)
如何进行调整,使其与标签开头正确对齐?
注意,该文件不是在.js文件中使用
JSX
,而是我配置了VS代码accordingly。 最佳答案
VSCode在下面使用https://github.com/Microsoft/TypeScript进行自动格式化。
TypeScript存储库中最近有一个与您遇到的相同问题有关的问题:https://github.com/Microsoft/TypeScript/issues/8663
所做的更改尚未反射(reflect)到VSCode Stable版本,但是在VSCode Insiders的当前版本(https://code.visualstudio.com/insiders)中,它标记对齐,使其成为结束括号。
您可以下载并使用VSCode Insiders,也可以更改eslint规则,以使用 props对齐的括号,直到稳定发行版为止:"react/jsx-closing-bracket-location": [ "warning", "props-aligned"],
关于visual-studio-code - VS Code-格式化时如何对齐标签末端和标签开口? (JSX),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41428375/