vscode 配置eslint 开发vue的相关配置

栏目: JavaScript · 发布时间: 4年前

内容简介:如何在vscode中用JavaScript Standard Style风格去验证 vue文件实际上JavaScript Standard Style有一个FAQ, 说明了如何使用。但是有一点非常重要的作者没有提到,就是eslint-plugin-html这个插件必须要安装3.x.x版本的, 现在eslint-plugin-html, 已经升级到4.x版本,默认不写版本号安装的就是4.x版本的,所以会出现问题。

如何在vscode中用JavaScript Standard Style风格去验证 vue文件

实际上JavaScript Standard Style有一个FAQ, 说明了如何使用。

但是有一点非常重要的作者没有提到,就是eslint-plugin-html这个插件必须要安装3.x.x版本的, 现在eslint-plugin-html, 已经升级到4.x版本,默认不写版本号安装的就是4.x版本的,所以会出现问题。

参考:详情请参考 https://www.npmjs.com/package...

此ESLint插件允许linting和修复HTML文件中包含的内联脚本。

迁移到v4

eslint-plugin-htmlv4至少需要ESLint v4.7。这是因为ESLint v4.7中发生了许多内部更改,包括支持预处理器中自动固定的新API。如果您仍在使用旧版本的ESLint,请考虑升级或继续使用 eslint-plugin-htmlv3。

eslint-plugin-htmlv4中的重要特性(和重大变化)是能够选择在同一HTML文件中的脚本标记之间共享范围的方式。

迁移到v3

如果您正在考虑升级到v3,请阅读本指南。

ESLint v4 is only supported by eslint-plugin-html v3, so you can't use eslint-plugin-html v1.5.2 with it (I should add a warning about this when trying to use the plugin with an incompatible version on ESLint).

If you do not use ESLint v4, please provide more information (package.json, a gist to reproduce, ...)

// FAQ

How to lint script tag in vue or html files?

You can lint them with eslint-plugin-html, just install it first, then enable linting for those file types in settings.json with:

{
 "standard.validate": [
      "javascript",
      "javascriptreact",
      "html"
  ],
  "standard.options": {
      "plugins": ["html"]
  },
  "files.associations": {
      "*.vue": "html"
  }
  }

If you want to enable autoFix for the new languages, you should enable it yourself:

{"standard.validate": [
     "javascript",
     "javascriptreact",
     { "language": "html", "autoFix": true }
 ],
 "standard.options": {
     "plugins": ["html"]
 }
}

1、需要安装插件:

npm i -g standard

npm i -g eslint-plugin-html@3.2.2 此处使用是3x版本

npm i -g eslint 或者 vscode 安装 eslint

2 、vscode setting 设置:

{
  "standard.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "html",
      "autoFix": true
    }
  ],
  "standard.options": {
    "plugin": ["html"]
  },
  "files.associations": {
    "*.vue": "html"
  },
  "standard.autoFixOnSave": true
  }

3、vscode 相关插件 Prettier and eslint 格式化代码:

ESLint (如果全局安装了,vscode 可以不安装)

Prettier formatter

Vetur

#4 格式化代码相关设置

{
  "files.autoSave": "afterDelay",
  "editor.fontSize": 14,
  "editor.tabSize": 2,
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue",
    {
      "language": "html",
      "autoFix": true
    }
  ],
  "prettier.singleQuote": true,
  "prettier.semi": false,
  "editor.formatOnSave": true
}

5 .eslintrc.js 相关

项目根目录下创建 .eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true,
  },
  'extends': [
    // 需要官方的 eslint-plugin-vue,它支持同时检查你 .vue 文件中的模板和脚本。请确保在你的 ESLint 配置中使用了该插件自身的配置:
    'plugin:vue/essential',
      // standard 代码规范  https://github.com/standard/standard/blob/master/docs/RULES-en.md
    '@vue/standard'
  ],
  rules: {
    'no-new-func':0,
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    // 解决 iview 报错问题
    "vue/no-parsing-error": [2, { "x-invalid-end-tag": false }]
  },
  parserOptions: {
    parser: 'babel-eslint'
  }

以上所述就是小编给大家介绍的《vscode 配置eslint 开发vue的相关配置》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

赛博空间的奥德赛

赛博空间的奥德赛

(荷兰)约斯·德·穆尔 (Jos de Mul) / 麦永雄 / 广西师范大学出版社 / 2007-2 / 38.00元

本书揭示了数码信息时代的电子传媒与赛博空间为人类历史的发展提供的新的可能性。本书第一部分“通向未来的高速公路”,涉及无线想象、政治技术和极权主义在赛博空间的消解等题旨;第二部分“赛博空间的想象” ,讨论空间文学探索简史、电影和文化的数码化;第三部分”可能的世界” ,关涉世界观的信息化、数码复制时代的世界、数码此在等层面;第四、五部分探讨主页时代的身份、虚拟人类学、虚拟多神论、赛博空间的进化、超人文......一起来看看 《赛博空间的奥德赛》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具