首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Visual代码用双引号格式化代码,尽管linter代码样式需要单引号

Visual代码用双引号格式化代码,尽管linter代码样式需要单引号
EN

Stack Overflow用户
提问于 2020-03-23 21:31:11
回答 1查看 1.4K关注 0票数 1

我正在使用NestJ和VueJ进行开发,并使用通过CLI配置的代码样式。因此,Nest在TSLint中使用自己的代码样式,对于VueJ,我想使用AirBnb代码样式。

基于我的当前VSC扩展设置

我使用ESLint、Vetur和更漂亮的设置

代码语言:javascript
复制
{
    "editor.codeActionsOnSave": {
        "source.fixAll": true
    },
    "editor.formatOnSave": true,
    "vetur.format.defaultFormatter.js": "prettier-eslint",
    "vetur.format.defaultFormatter.html": "prettier",
    "vetur.format.defaultFormatter.ts": "prettier-tslint",
    "prettier.singleQuote": true
}

不幸的是,VSC将我的Javascript代码从单引号更新为双引号。我想根据配置的代码样式格式化我的代码,不管它是普通的NodeJs,NestJ,角,React,Vue,.

有人能告诉我如何正确设置编辑器吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-24 02:06:44

不要将eslintprettier结合使用,大多数事情都会发生冲突。这里的设置非常适合我,我使用的是eslint:

代码语言:javascript
复制
{
  "window.zoomLevel": 2,
  "workbench.colorTheme": "Solarized Dark",
  "editor.tabSize": 2,
  "editor.wordWrapColumn": 100,
  "workbench.settings.editor": "json",
  "workbench.settings.useSplitJSON": true,
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": false,
  },
  "eslint.autoFixOnSave": true,
  "eslint.alwaysShowStatus": true,
  "eslint.validate": [
    {
      "language": "vue",
      "autoFix": true
    },
    {
      "language": "html",
      "autoFix": true
    },
    {
      "language": "javascript",
      "autoFix": true
    }
  ],
  "cSpell.userWords": [
    "Dropdown",
    "vuex"
  ],
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.grammar.customBlocks": {
    "page-query": "graphql",
    "static-query": "graphql"
  },
  "explorer.confirmDragAndDrop": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
}

在根文件夹./.eslintrc.json

代码语言:javascript
复制
{
  "extends": ["airbnb", "prettier"],
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": ["error"]
  }
}

如果您仍然喜欢使用更漂亮的,那么在根文件夹中创建文件./.prettierrc

代码语言:javascript
复制
{
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
}

如果您没有这样做,请安装这些vs代码扩展:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60821817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档