简体   繁体   English

如何将 html 属性格式化为 VSCode 中的垂直列表

[英]How to format html properties to vertical list in VSCode

Writing html attributes in a single line in React quickly gets out of control.在 React 的一行中写入 html 个属性很快就会失控。 Is there any hotkey or plugin to take html attributes in a single line and stack them vertically?是否有任何热键或插件可以在一行中获取 html 个属性并将它们垂直堆叠?

For a simple example, how do I convert this:举一个简单的例子,我如何转换它:

<input onChange={handleChange('name')} type="text" className="form-control" />

To this:对此:

<input 
  onChange={handleChange('name')} 
  type="text" 
  className="form-control" 
/>

Thanks!谢谢!

ESLint + Prettier ESLint + Prettier

'react/jsx-first-prop-new-line': [1, 'multiline'],
'react/jsx-max-props-per-line': [1, {'maximum': 1}]

Check out my answer for the full setup here https://stackoverflow.com/a/66059378/10413635在此处查看完整设置的答案https://stackoverflow.com/a/66059378/10413635

// .eslintrc.js
module.exports = {
  extends: [
    'react-app',
    'prettier',
    'plugin:prettier/recommended',
  ],
  plugins: ['prettier'],
  rules: {
    'react/jsx-first-prop-new-line': [2, 'multiline'],
    'react/jsx-max-props-per-line': [
      2,
      { maximum: 1, when: 'multiline' },
    ],
    'react/jsx-indent-props': [2, 2],
    'react/jsx-closing-bracket-location': [
      2,
      'tag-aligned',
    ],
  },
}

// .prettierrc
{
 "semi": false,
 "singleQuote": true,
 "printWidth":80 // default
}

// .eslintr rules
'react/jsx-first-prop-new-line': [2, 'multiline'],
'react/jsx-max-props-per-line': [2, { maximum: 1, when: 'multiline' }],
'react/jsx-indent-props': [2, 2],
'react/jsx-closing-bracket-location': [2, 'tag-aligned'],

Writing html attributes in a single line in React quickly gets out of control.在 React 中的一行中写入 html 属性很快就会失控。 Is there any hotkey or plugin to take html attributes in a single line and stack them vertically?是否有任何热键或插件可以将 html 属性放在一行中并将它们垂直堆叠?

For a simple example, how do I convert this:举个简单的例子,我该如何转换:

<input onChange={handleChange('name')} type="text" className="form-control" />

To this:对此:

<input 
  onChange={handleChange('name')} 
  type="text" 
  className="form-control" 
/>

Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM