11

我不知道这是否是 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 代码。

4

1 回答 1

3

VSCode 在下面使用https://github.com/Microsoft/TypeScript进行自动格式化。

对于您遇到的相同问题,TypeScript repo 最近关闭了一个问题:https ://github.com/Microsoft/TypeScript/issues/8663

这些更改尚未反映到 VSCode 稳定版本,但在当前版本的 VSCode Insiders ( https://code.visualstudio.com/insiders ) 中,它标记对齐右括号。

您可以下载并使用 VSCode Insiders 或更改您的 eslint 规则以使用与 props 对齐的括号,直到它发布到稳定版本:

"react/jsx-closing-bracket-location": [ "warning", "props-aligned" ],

于 2017-01-09T22:00:13.303 回答