前端项目安装 eslint 方法

发布于 2024-12-29 06:28:32 字数 2297 浏览 13 评论 0

安装

yarn add eslint --dev

设置配置文件

yarn run eslint --init
? How would you like to use ESLint? ... 
  To check syntax only
  To check syntax and find problems
> To check syntax, find problems, and enforce code style
? What type of modules does your project use? ... 
> JavaScript modules (import/export)
  CommonJS (require/exports)
  None of these
? Which framework does your project use? ... 
  React
> Vue.js
  None of these
? Does your project use TypeScript? » No / Yes
? Where does your code run? ...  (Press <space> to select, <a> to toggle all, <i> to invert selection)
√ Browser
  Node
? How would you like to define a style for your project? ... 
> Use a popular style guide
  Answer questions about your style
  Inspect your JavaScript file(s)
? Which style guide do you want to follow? ... 
  Airbnb: https://github.com/airbnb/javascript
> Standard: https://github.com/standard/standard
  Google: https://github.com/google/eslint-config-google
  XO: https://github.com/xojs/eslint-config-xo
? What format do you want your config file to be in? ... 
> JavaScript
  YAML
  JSON

接下来会安装依赖包,安装如果失败的话,重新安装一次

最终生成的配置文件 .eslintrc.js

module.exports = {
  'env': {
    'browser': true,
    'es2021': true,
  },
  'extends': [
    'plugin:vue/essential',
    'standard',
  ],
  'parserOptions': {
    'ecmaVersion': 6, // 这里不知道为啥生成 13 了,我们手动改成 6 
    'sourceType': 'module',
  },
  'plugins': [
    'vue',
  ],
  'rules': {},
}

最终安装的开发依赖包

"devDependencies": {
  "eslint": "^7.32.0",
  "eslint-config-standard": "^16.0.3",
  "eslint-plugin-import": "^2.25.4",
  "eslint-plugin-node": "^11.1.0",
  "eslint-plugin-promise": "^5.2.0",
  "eslint-plugin-vue": "^8.2.0"
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

黑色毁心梦

暂无简介

文章
评论
29 人气
更多

推荐作者

闻呓

文章 0 评论 0

深府石板幽径

文章 0 评论 0

mabiao

文章 0 评论 0

枕花眠

文章 0 评论 0

qq_CrTt6n

文章 0 评论 0

红颜悴

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文