visual-studio-code - VS Code - 格式化时如何对齐标签结尾和标签开头? (JSX)

标签 visual-studio-code jsx vscode-settings

我不知道这是否是 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)
如何调整它以使其与标签开始正确对齐?

请注意,该文件正在使用 JSX在 .js 文件中,我配置了 VS 代码 accordingly .

最佳答案

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

TypeScript 存储库中有一个最近关闭的问题,用于解决您遇到的相同问题:https://github.com/Microsoft/TypeScript/issues/8663

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

您可以下载并使用 VSCode Insiders 或更改您的 eslint 规则以使用 Prop 对齐 括号直到它稳定发布:
"react/jsx-closing-bracket-location": [ "warning", "props-aligned" ],

关于visual-studio-code - VS Code - 格式化时如何对齐标签结尾和标签开头? (JSX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41428375/

相关文章:

python vscode modulenotfound错误

c# - 下载dotnet运行时v7.0.9时VSCode超时错误

visual-studio-code - 有没有办法在 vs code explorer 中展平或合并单个文件夹?

visual-studio-code - vscode : How to set that when I press CTRL + up or down arrow, 光标随页面移动?

visual-studio-code - 如何在 VSCode 中禁用斜体?

java - 我想在vscode最近的扩展上使用jdk8,如何在setting.json上设置

f# - 如何使用 vscode 在 F# 项目中强制文件排序?

javascript - TSX 文件无法呈现导入的 React 组件

vue.js - Vue3 + Vite 使用 JSX 的推荐方式

javascript - 保存文件时 JS/JSX 自动缩进错误