Eslint

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

Eslint

eslint

eslint是什么

插件化的JS代码检测工具

为什么需要

JS是弱类型语言,开发过程中容易出错。Eslint可以在编码中发现问题而不是执行时。

怎么用

初始化
  1. 安装
    npm install eslint
  2. 设置lint规则
    1. 新建一个.eslintrc文件,手写配置项
      直接在 package.json 文件里的 eslintConfig 字段指定配置
    2. 输入init命令,选择相关配置项后自动生成配置文件
	//选择若干条件,生成.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
启动
  1. 只是在项目里安装了
$ ./node_modules/.bin/eslint yourfile.js

./node_modules/.bin/目录里面放置了整个项目可执行的二进制文件
2. 全局安装了eslint

$ eslint yourfile.js
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值