当我们创建vue项目的时候,我们往往会选择linter/Formatter,eslint-config-standard,下面我放张vue图形化配置界面


但这往往是进坑的开始
特别注意一下这里的插件: "standard"插件代表的是eslint的standard插件都要安装,用Vue ui初始化选择了standard安装的话(也只会安装eslint-config-standard),参考一下下面的依赖,没有的话手动安装,防止出现一些莫名的问题:
eslint

babel-eslint

eslint-plugin-html

eslint-config-standard

eslint-plugin-standard

eslint-plugin-promise

下面说下“2 errors and 0 warnings potentially fixable with the --fix option”报错
这种只要隐藏.eslintrc.js中的’@vue/standard’就行了,如下图:


第二种“2 errors and 0 warnings potentially fixable with the --fix option”报错解决方式,
functineName() 左括号前没有空格报错,在.eslintrc.js的rules中输入’space-before-function-paren’: 0

分号; 报错
引号需要是单引号
以上两个问题,创建一个.prettierrc的JSON(json后缀不用写)文件(这个是用来格式化文件的)
“semi”:false, // 在格式化的时候不加分号
“singleQuote”:true // 将双引号转成单引号

eslint常见报错:

  1. 文件末尾存在空行(eol-last):Too many blank lines at the end of file.Max of 0 allowed

  2. 缺少分号(‘semi’: [‘error’,’always’]) :Missing semicolon

  3. 函数关键字后面缺少空格 :Missing space before function parentheses

  4. 字符串没有使用单引号(’quotes’: [1, ’single’]) :String must use singlequote

  5. 缩进错误 : Expected indentation of 2 spaces but found 4

  6. 没有使用全等(eqeqeq) : Expected ’ === ’ and instaed saw ‘==’

  7. 导入组件却没有使用 : ‘seller’ is defined but never used

  8. new了一个对象却没有赋值给某个常量(可以在该实例前添加此代码/eslint-disable

  9. no-new/忽略ESLint的检查): Do not user’new’ for side effects

  10. 超过一行空白行(no-multiple-empty-lines):More than 1 blank line not allowed

  11. 注释符 // 后面缩进错误(lines-around-comment): Expected space or tab after
    ‘//’ in comment

  12. 模块导入没有放在顶部:Import in body of module; reorder to top

  13. 前面缺少空格:Missing space before

  14. 已定义但是没有使用:‘scope’ is defined but never used

下面对Eslint的三个文件做详细解释:

1.editorconfig

主要用于配置IDE,规范缩进风格,缩进大小,tab长度以及字符集等,解决不同IDE的编码范设置。EditorConfig 插件会去查找当前编辑文件的所在文件夹或其上级文件夹中是否有 .editorconfig 文件。如果有,则编辑器的行为会与 .editorconfig 文件中定义的一致,并且其优先级高于编辑器自身的设置。

root = true
#对所有文件有效  //[*js]只对js文件有效
[*]
#设置编码格式
charset = utf-8
#缩进类型  可选space和tab
indent_style = space
#缩进数量可选整数值2 or 4,或者tab
indent_size = 2
#换行符的格式
end_of_line = lf
是否在文件的最后插入一个空行  可选true和false
insert_final_newline = true
是否删除行尾的空格  可选择true和false
trim_trailing_whitespace = true

2. .eslintignore

你可以通过在项目根目录创建一个 .eslintignore 文件告诉 ESLint 去忽略特定的文件和目录。.eslintignore 文件是一个纯文本文件,其中的每一行都是一个 glob 模式表明哪些路径应该忽略检测。例如,以下将忽略所有的 JavaScript 文件:

**/*.js

当 ESLint 运行时,在确定哪些文件要检测之前,它会在当前工作目录中查找一个 .eslintignore 文件。如果发现了这个文件,当遍历目录时,将会应用这些偏好设置。一次只有一个 .eslintignore 文件会被使用,所以,不是当前工作目录下的 .eslintignore 文件将不会被用到。

放置需要ESLint忽略的文件,只对.js文件有效,由于node_modules文件夹里面的内容比较大,如果项目使用的是git管理代码,一般不上传至git。此时应该设置忽略

/build/
/config/
/dist/
/src/utils/
/src/router/*.js
/node_modules/
/bower_components/
#local env files
.env.local
.env.*.local
#Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
#Editor directories and files.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*

3 .eslintrc.js

(vue-cli3改文件的内容在 packageConfig.json中配置eslintConfig)

module.exports = {//此项是用来告诉eslint找当前配置文件不能往父级查找root: true, //此项是用来指定eslint解析器的,解析器必须符合规则,babel-eslint解析器是对babel解析器的包装使其与ESLint解析parser: 'babel-eslint',//此项是用来指定javaScript语言类型和风格,sourceType用来指定js导入的方式,默认是script,此处设置为module,指某块导入方式parserOptions: {sourceType: 'module'},//此项指定环境的全局变量,下面的配置指定为浏览器环境env: {browser: true,node:true},// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style// 此项是用来配置标准的js风格,就是说写代码的时候要规范的写,如果你使用vs-code我觉得应该可以避免出错extends: 'standard',// required to lint *.vue files// 此项是用来提供插件的,插件名称省略了eslint-plugin-,下面这个配置是用来规范html的plugins: ['html'],// add your custom rules here// 下面这些rules是用来设置从插件来的规范代码的规则,使用必须去掉前缀eslint-plugin-// 主要有如下的设置规则,可以设置字符串也可以设置数字,两者效果一致// "off" -> 0 关闭规则// "warn" -> 1 开启警告规则//"error" -> 2 开启错误规则// 了解了上面这些,下面这些代码相信也看的明白了rules: {// allow async-await'generator-star-spacing': 'off',// allow debugger during development'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off','no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',// js语句结尾必须使用分号'semi': ['off', 'always'],// 三等号'eqeqeq': 0,// 强制在注释中 // 或 /* 使用一致的空格'spaced-comment': 0,// 关键字后面使用一致的空格'keyword-spacing': 0,// 强制在 function的左括号之前使用一致的空格'space-before-function-paren': 0,// 引号类型"quotes": [0, "single"],// 禁止出现未使用过的变量'no-unused-vars': 0,// 要求或禁止末尾逗号'comma-dangle': 0,// 严格的检查缩进问题"indent": 0,//引入模块没有放入顶部"import/first": 0,//前面缺少空格,Missing space before"arrow-spacing": 0,//后面没有空位,There should be no space after this paren"space-in-parens": 0,//已定义但是没有使用,'scope' is defined but never used"vue/no-unused-vars": 0}
}

你也可以直接在代码文件中定义

1. 禁用 ESLint:/* eslint-disable */
var a = 100;
console.log(a);
/* eslint-enable */2.禁用一条规则:/*eslint-disable no-console */
var a = 100;
console.log(a);
/*eslint-enable no-console */3.调整规则:/* eslint no-console:0 */
var a = 100;
console.log(a);在初始化项目时选择是否使用ESLint管理代码(选择Y则默认开启)
Use ESLint to lint your code? (Y/n)y

原文地址:https://blog.csdn.net/wron_path/article/details/104655844

2 errors and 0 warnings potentially fixable with the `--fix` option,vue-cli3中eslint详解(转载)相关推荐

  1. 2 errors and 0 warnings potentially fixable with the `--fix` option,vue-cli3中eslint详解

    当我们创建vue项目的时候,我们往往会选择linter/Formatter,eslint-config-standard,下面我放张vue图形化配置界面 但这往往是进坑的开始 特别注意一下这里的插件: ...

  2. Vue报错:3 errors and 0 warnings potentially fixable with the `--fix` option.

    Vue报错:3 errors and 0 warnings potentially fixable with the --fix option. 报错如下 解决办法 注释掉.eslintrc.js文件 ...

  3. errors and 0 warnings potentially fixable with the `--fix` option.

    Vue项目运行中出现 errors and 0 warnings potentially fixable with the --fix option.的报错问题 一.原因: 与创建项目 eslint ...

  4. 解决errors and 0 warnings potentially fixable with the `--fix` option.问题

    新建vue-cli的时候,选择了eslint语法,很烦人 这里注释掉就行 还是解决不了,那没办法,如果能接受的话, 老老实实安装个eslint插件吧 ESLint有很多规范,用的比较多的是标准规范 特 ...

  5. 7 errors and 0 warnings potentially fixable with the `--fix` option.报错处理

    做vue2项目的时候出现了这种错误,发现原有的代码没有出错,自己写的就报错,后来经过查找发现原来是规范写法了,但是每个人的书写习惯不一样,那怎么才能解决掉这个问题呢? 其实很简单我们只需要进入根目录里 ...

  6. 8 errors and 0 warnings potentially fixable with the `--fix` option.

    在用vue-cli3脚手架搭建项目,开始打码之后,各种报错,信息如下: 后来在这个地方去掉了@vue/standard,重启之后就好了- 我看网上一些都是说: 注释掉.eslintrc.js文件中的' ...

  7. ✖ 48 problems (48 errors, 0 warnings) 45 errors and 0 warnings potentially fixable with the `--fix

    ✖ 48 problems (48 errors, 0 warnings)   45 errors and 0 warnings potentially fixable with the `--fix ...

  8. 2 problems (2 errors, 0 warnings) 2 errors and 0 warnings potentially fixable with the `--fix` opt

    创建vue项目初始化完成之后 在终端运行 npm run serve 出现一个错误,如下图: 解决的方法是: ① 项目的代码中找到.eslintrc.js 文件夹将extends中的'@vue/sta ...

  9. 2 problems (2 errors, 0 warnings) 2 errors and 0 warnings potentially fixable with the `--fix` opt

    创建vue项目初始化完成之后 在终端运行 npm run serve 出现一个错误,如下图: 解决的方法是: ① 项目的代码中找到.eslintrc.js 文件夹将extends中的'@vue/sta ...

  10. 解决关于0 errors and 27 warnings potentially fixable with the `--fix` option.的问题

    配置eslint后运行项目有如下警告(换行格式问题): 执行以下命令(可以自动修复这些问题): npm run lint --fix 原因 在window系统中,clone代码下来,会自动把换行符LF ...

最新文章

  1. 添物 不花钱学计算机及编程(预备篇)— 编译原理
  2. python计算precision,recall,f1-score
  3. 对硬盘做镜像,按位与按文件有什么区别?
  4. 源码安装 MariaDB
  5. html5boder属性,你未必知道的CSS小知识:border属性比你想象的要复杂
  6. Android SqlLite数据库的创建、增、删、改、查、使用事务
  7. scale data:线性空间映射
  8. Danfo.js专题 - Danfo.js与Dnotebook简介与入门
  9. 黑马程序员 oc中的类与对象
  10. dubbo服务调用为何先进入到mockClusterInvoker执行
  11. Visio 2013 永久激活,破解工具在win10下避免自动删除程序文件
  12. python进阶方向_python进阶—边练边学,学到极致
  13. 计算机一直显示配置更新开不了机怎么办,电脑开机出现配置更新怎么办
  14. WIN10虚拟机安装教程
  15. 这些行业已经开始用数据挖掘了,我们的前途光明
  16. MyEclipse快捷键Alt+Shift+s详解
  17. 【数据结构与算法分析】第一章、第二章总结
  18. javascript中的prototype原型、_proto_属性、原型链
  19. 易宝正式加入openGauss社区
  20. 弧齿锥齿轮零件图_弧齿锥齿轮加工原理

热门文章

  1. Redis开启远程访问
  2. Ubuntu系统将域名指向指定IP
  3. win10怎么更新显卡驱动_如何更新电脑的显卡驱动(驱动精灵)
  4. 中国VR/AR技术的日渐成熟,带动行业领域巨大发展!
  5. 捕获组合键 键盘组合键
  6. treemap倒叙_java对map进行排序(对日期倒叙)
  7. dns服务器异常不能上网怎么修复,DNS错误无法正常上网怎么办?
  8. 台式计算机识别不了鼠标,USB无线鼠标失灵电脑检测不到无法识别怎么办
  9. 使用高德地图自定义marker、infowindow
  10. android onupgrade调用,Android Sqlite中常见的对于onUpgrade的处理方法