vue项目启动报错 error Parsing error: missing-semicolon-after-chara

举报
DevFeng 发表于 2021/10/13 10:51:20 2021/10/13
【摘要】 问题:今天拉取代码后,启动项目提示  error  Parsing error: missing-semicolon-after-chara; 解析的错误:字符后缺少分号。找文件:找到错误文件发发现代码有红色波浪线体提示将鼠标移动到错误代码块上,有更详细的错误提示,提示内容和启动项目时的错误一致观察错误提示,发现使用了eslint-plugin-vue 发现项目中.eslintrc.js文件...

问题:今天拉取代码后,启动项目提示  error  Parsing error: missing-semicolon-after-chara; 解析的错误:字符后缺少分号。

找文件:找到错误文件发

发现代码有红色波浪线体提示

将鼠标移动到错误代码块上,有更详细的错误提示,提示内容和启动项目时的错误一致

观察错误提示,发现使用了eslint-plugin-vue

 

发现项目中.eslintrc.js文件以前都没有注意过

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
  parserOptions: {
    parser: "babel-eslint"
  },
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
    "no-unused-vars": "off", // 多余变量检查,声明了多余变量但没使用
    "no-irregular-whitespace": "off", //这禁止掉 空格报错检查
    "prettier/prettier": "off"//关闭prettier
  }
};
“off” 或 0 - 关闭规则
“warn” 或 1 - 开启规则
“error” 或 2 - 开启规则

ESLint的用途

  • 1.审查代码是否符合编码规范和统一的代码风格;
  • 2.审查代码是否存在语法错误;

ESLint的介绍

About

ESLint is an open source JavaScript linting utility originally created by Nicholas C. Zakas in June 2013. Code linting is a type of static analysis that is frequently used to find problematic patterns or code that doesn’t adhere to certain style guidelines. There are code linters for most programming languages, and compilers sometimes incorporate linting into the compilation process.

ESLint 是一个开源的 JavaScript 代码检查工具,由 Nicholas C. Zakas 于2013年6月创建。代码检查是一种静态的分析,常用于寻找有问题的模式或者代码,并且不依赖于具体的编码风格。对大多数编程语言来说都会有代码检查,一般来说编译程序会内置检查工具。

JavaScript, being a dynamic and loosely-typed language, is especially prone to developer error. Without the benefit of a compilation process, JavaScript code is typically executed in order to find syntax or other errors. Linting tools like ESLint allow developers to discover problems with their JavaScript code without executing it.

JavaScript 是一个动态的弱类型语言,在开发中比较容易出错。因为没有编译程序,为了寻找 JavaScript 代码错误通常需要在执行过程中不断调试。像 ESLint 这样的可以让程序员在编码的过程中发现问题而不是在执行的过程中。

The primary reason ESLint was created was to allow developers to create their own linting rules. ESLint is designed to have all rules completely pluggable. The default rules are written just like any plugin rules would be. They can all follow the same pattern, both for the rules themselves as well as tests. While ESLint will ship with some built-in rules to make it useful from the start, you’ll be able to dynamically load rules at any point in time.

ESLint 的初衷是为了让程序员可以创建自己的检测规则。ESLint 的所有规则都被设计成可插入的。ESLint 的默认规则与其他的插件并没有什么区别,规则本身和测试可以依赖于同样的模式。为了便于人们使用,ESLint 内置了一些规则,当然,你可以在使用过程中自定义规则。

ESLint is written using Node.js to provide a fast runtime environment and easy installation via npm.

ESLint 使用 Node.js 编写,这样既可以有一个快速的运行环境的同时也便于安装。

Philosophy

Everything is pluggable:

所有都是可拔插的

Rule API is used both by bundled and custom rules
内置规则和自定义规则共用一套规则 API
Formatter API is used both by bundled and custom formatters
内置的格式化方法和自定义的格式化方法共用一套格式化 API
Additional rules and formatters can be specified at runtime
额外的规则和格式化方法能够在运行时指定
Rules and formatters don’t have to be bundled to be used
规则和对应的格式化方法并不强制捆绑使用

Every rule:

每条规则:

Is standalone
各自独立
Can be turned off or on (nothing can be deemed “too important to turn off”)
可以开启或关闭(没有什么可以被认为“太重要所以不能关闭”)
Can be set to a warning or error individually
可以将结果设置成警告或者错误

Additionally:

另外:

Rules are “agenda free” - ESLint does not promote any particular coding style
ESLint 并不推荐任何编码风格,规则是自由的
Any bundled rules are generalizable
所有内置规则都是泛化的

The project:

项目:

Values documentation and clear communication
通过丰富文档减少沟通成本
Is as transparent as possible
尽可能的简单透明
Believes in the importance of testing
相信测试的重要性

ESLint的配置

ESlint 被设计为完全可配置的,这意味着你可以关闭每一个规则而只运行基本语法验证,或混合和匹配 ESLint 默认绑定的规则和你的自定义规则,以让 ESLint 更适合你的项目。有两种主要的方式来配置 ESLint:

Configuration Comments - 使用 JavaScript 注释把配置信息直接嵌入到一个代码源文件中。
Configuration Files - 使用 JavaScript、JSON 或者 YAML 文件为整个目录(处理你的主目录)和它的子目录指定配置信息。可以配置一个独立的 .eslintrc.* 文件,或者直接在 package.json 文件里的 eslintConfig 字段指定配置,ESLint 会查找和自动读取它们,再者,你可以在命令行运行时指定一个任意的配置文件。
如果你在你的主目录(通常 ~/)有一个配置文件,ESLint 只有在无法找到其他配置文件时才使用它。

有很多信息可以配置:

Environments - 指定脚本的运行环境。每种环境都有一组特定的预定义全局变量。
Globals - 脚本在执行期间访问的额外的全局变量。
Rules - 启用的规则及其各自的错误级别。
所有这些选项让你可以细粒度地控制 ESLint 如何对待你的代码。

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。