Eslint
eslint
eslint是什么
插件化的JS代码检测工具
为什么需要
JS是弱类型语言,开发过程中容易出错。Eslint可以在编码中发现问题而不是执行时。
怎么用
初始化
- 安装
npm install eslint - 设置lint规则
- 新建一个.eslintrc文件,手写配置项
直接在 package.json 文件里的 eslintConfig 字段指定配置 - 输入init命令,选择相关配置项后自动生成配置文件
- 新建一个.eslintrc文件,手写配置项
//选择若干条件,生成.eslintrc.js文件
./node_modules/.bin/eslint --init
具体需要选择的配置项内容
>? How would you like to use ESLint? To check syntax, find problems, and enforce code style
>? What type of modules does your project use? JavaScript modules (import/export)
>? Which framework does your project use? Vue.js
>? Does your project use TypeScript? No
>? Where does your code run? (Press <space> to select, <a> to toggle all, <i> to invert selection)Browser
>? How would you like to define a style for your project? Use a popular style guide
?? Which style guide do you want to follow? Airbnb (https://github.com/airbnb/javascript)
>? What format do you want your config file to be in? JavaScript
启动
- 只是在项目里安装了
$ ./node_modules/.bin/eslint yourfile.js
./node_modules/.bin/目录里面放置了整个项目可执行的二进制文件
2. 全局安装了eslint
$ eslint yourfile.js

Eslint是一款插件化的JS代码检测工具,它可在编码阶段发现潜在问题,避免运行时错误。本文介绍如何使用Eslint进行初始化配置,包括安装、设置规则及启动过程。通过选择不同的配置项,如项目类型、模块使用、代码风格等,Eslint能自动生成适合项目的配置文件,有效提升代码质量和团队协作效率。
776

被折叠的 条评论
为什么被折叠?



