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

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

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

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


当前回答

"漂亮":{ “singleQuote”:真的 },

这行代码节省了我的时间。

其他回答

我解决这个问题的方法是通过安装禁用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,
};

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

看起来这个问题有一个漏洞:更漂亮的漏洞

以上方法对我都没用。 唯一有效的是,在package.json中添加这行代码:

"prettier": {
    "singleQuote": true
  },

对我来说唯一有效的方法是: 并且仅适用于Angular项目:

开始你的项目吧。”Editorconfig "文件,并粘贴'quote_type = single'。 希望这对你也有用。

对我有用的是设置。prettierrc。Json配置文件。把它放在你的项目的根,像这样的示例配置:

{
  "singleQuote": true,
  "trailingComma": "all",
  "tabWidth": 2,
  "semi": true,
  "arrowParens": "always"
}

触发Format Document命令后,一切都能正常工作。

旁注:这个解决方案的一个好处是,由于目前的配置文件,每个团队成员都获得了相同的格式化输出。

对于默认使用.editorconfig文件的项目。格式化程序将忽略设置中的规则并使用.editorconfig中的规则,然后您可以:

删除.editorconfig文件,并使用VSCode设置。 根据您的文件类型,在.editorconfig文件中添加quote_type = single。也可以将quote_type value设置为double或auto。