当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。

在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。

我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)

如何定制VSCode来避免这种情况?


当前回答

正确解决方法:

我在我的主根项目中添加了. pretierrc .js文件 和写

module.exports = {
    singleQuote: true
  };

其他回答

我解决这个问题的方法是通过安装禁用eslint中的所有格式化规则 npm i -D eslint-config-prettier,然后在eslint配置文件的extends数组的末尾添加“prettier”

module.exports = {
  env: {
    node: true,
  },
  extends: [
    'airbnb-base',
    'airbnb-typescript/base',
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'prettier',

  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
  plugins: ['@typescript-eslint'],
  root: true,
};

然后把它作为我的默认格式化器做得更漂亮

如果你使用的是YAML插件,它还有一个单引号/双引号选项,这让我很困惑。欢呼。

这对我来说很管用: 尝试右键单击当前文档 然后选择format document with, 并为文档选择自己的格式扩展。 :)

对于JSX使用:

{"jsxSingleQuote": false}

我在vscode中也有同样的问题。只需在根目录中创建一个. pretierrc文件,并添加以下json。 对于单引号添加:

{
  "singleQuote": true
}

对于双引号添加:

  {
      "singleQuote": false
  }