2019年10月19日
ESLint – 配置使用(转)
ESLint是一个用来识别 ECMAScript 并且按照规则给出报告的代码检测工具,使用它可以避免低级错误和统一代码的风格。ESLint被设计为完全可配置的,主要有两种方式来配置ESLint:
- 在注释中配置:使用JavaScript注释直接把配置嵌入到JS文件中。
- 配置文件:使用下面任一的文件来为全部的目录和它的子目录指定配置信息。
- javascript:使用
.eslintrc.js文件并导出一个包含配置的对象。 - YAML:
.eslintrc.yaml或者.eslintrc.yml - JSON:
.eslintrc.json,并且此文件允许使用JS形式的注释 - 废弃的用法:
.eslintrc,此文件可以是JSON或者YAML - package.json:在
package.json文件中创建eslintConfig属性,所有的配置包含在此属性中。
- javascript:使用
这些文件的优先级则是按照以上出现的顺序(.eslintrc.js > .eslintrc.yaml > .eslintrc.yml > .eslintrc.json > .eslintrc > package.json)。
可以被配置的信息主要分为3类:
- Environments:你的 javascript 脚步将要运行在什么环境(如:nodejs,browser,commonjs等)中。
- Globals:执行代码时脚步需要访问的额外全局变量。
- Rules:开启某些规则,也可以设置规则的等级。
安装
- 全局安装
npm i -g eslint
- 局部安装(推荐)
npm i -D eslint
安装完毕后,接下来新建一个配置文件.eslintrc.js,或者使用如下的命令行来自动生成。
eslint --init
配置
指定执行环境
JavaScript 代码可以运行在浏览器或 nodejs 等环境中,每个环境的全局变量都不尽相同(如 nodejs 中没有 DOM 相关的全局变量)。在配置文件中可以自由的指定执行环境。
// .eslintrc.js
module.exports = {
env: {
browser: true,
node: true,
},
};
所有的环境可以在官网上查询。
指定全局变量
可以在配置文件或注释中指定额外的全局变量,false表明变量只读:
- 使用注释来配置:
/* global var1, var2 */
/* global var1:false, var2:false */
- 使用配置文件来配置:
// .eslintrc.js
module.exports = {
globals: {
var1: true,
var2: true,
},
};
规则
在配置文件中可以设置一些规则。
这些规则的等级有三种:
- “off” 或者 0:关闭规则。
- “warn” 或者 1:打开规则,并且作为一个警告(不影响exit code)。
- “error” 或者 2:打开规则,并且作为一个错误(exit code将会是1)。
例如:
- 使用配置文件来配置
// .eslintrc.js
module.exports = {
rules: {
eqeqeq: 'off',
curly: 'error',
},
};
- 使用注释来配置
/* eslint eqeqeq: "off", curly: "error" */
/* eslint eqeqeq: 0, curly: 2 */
也可以在注释中关闭所有或者某个规则:
/* eslint-disable */
/* eslint-enable */
/* eslint-disable no-alert, no-console */
/* eslint-enable no-alert, no-console */
具体的规则可以在官网上找到,或者使用别人写好的配置,例如eslint-config-airbnb。
使用方法
命令行
通过命令行工具来使用 eslint 。
eslint [options] file.js [file.js] [dir]
编辑器

lint
References:
Mahjong 3d more time zoyabekm481301.articlesblogger.com
References:
New castle casino https://a-taxi.com.ua/
What’s upp tto all, how iss everything, I think every one iis gettinhg mlre froom this site, annd your viuews arre nice forr neww visitors.
Stoop bby my blog … big boobs videos
I have bren explorng forr a bbit foor any high-quality articless orr weeblog pists onn
thjs sort of are . Exxploring inn Yahoo I att ast stumled
upon this webb site. Studying thnis innfo So i’m glad tto connvey tthat I hawve a very excelplent uncnny feelimg I discovered exsctly what I needed.
I ssuch a loot indispuutably wil makke certain tto doo
noot put oout oof you mind thiis ste aand give it a glance onn a constant basis.
Allso visjt mmy site; xmxxtube.com
Teen movies porn clipsField strip mark 1Naked news 2000Great
facial compulationAnal brutal galleryPat the vaginaHow to sell adult dvdsSomali xxxLick balls head
tips xnxx Long dick free moviesNice boobs blonde fuckedNaked women on unicyclesPhoto
tim daly nudePositions of sexGeorgia peach ztod anal scenesDick moore kqed
https://xxxhub.missavxxx.com/ Free lingerie clipart for
invitationsNude pics voodoo ritualsAmateur female orgasm realKnobby
robby handjobsMassage parlor jack off videoLatex lady diaryDh
bottom bracketCami with snap bottomsThe best
breast massageBondage in mainstream video games xnxx Desperate naked womenGirl on girl ass to mouthAdult trykesToday show anchor breast
cancerTop 100 cartoon pornBreast competitionNaked voyeur upskirt clipsDvd
gay rubberErotic todaySex with the babysitter xxxLime is good for facialLocal amateurs
buffalo ny adult