当前位置:网站首页>Format checking tool eslint
Format checking tool eslint
2022-04-21 07:15:00 【cornivores】
eslint What is it? ?
eslint Is a tool for reporting whether the syntax format conforms to the specification , The purpose is to improve the readability and maintainability of the code , Its principle is to use AST To evaluate the code format . The feature is high scalability ( You can add your own rules )、 Full pluggability ( About eslint The rules of can be applied in many places ).
- For example, to perform
npm install eslintCommand after installation ,package.json Under the devDependencies There will be eslint

- stay vscode There will be... In the expansion store in eslint plug-in unit

- about gitlab Remote format verification of , Is to use gitlab ci runner Inside eslint check
that package.json Under the eslint、vscode Inside eslint and ci runner Inside eslint What's the difference? ?
First ,package.json Inside eslint Only applicable to this package.json Project , This approach applies when you just want to reference locally eslint Check the situation ( That is, you just want to reference format verification in a single project ).
Second, let's look at vscode Inside eslint and ci runner Inside eslint!
The code specification verification of a project usually consists of two parts :
- be based on git hook The check
- webpack Medium eslint-loader validators
The user has installed the corresponding dependency , Starting the project will trigger webpack Calibrator in , Submitting code triggers git Verifier set in hook , At this time , The code format submitted to the remote end is generally secure . The condition that the code format can meet the verification rules is to start the project or execute the submission operation after installing the corresponding dependencies , Therefore, there will also be a blind area that cannot trigger the calibrator . It can be divided into the following two situations :
-
Do not install package ( Do not download node_modules) The situation of
In this case webpack and eslint Dependency does not exist , The corresponding two validators themselves do not exist . Thus, the code pushed to the remote end may have the problem of code format error , To prevent such problems , need gitlab in ci runner Inside eslint Open the remote eslint check . -
Installed package , But don't start and don't submit
In this case eslint and webpack Dependency installed , The project didn't start , therefore eslint-loader Do not trigger verification . No submission , So... Is not triggered git hook , There is no trigger eslint validators . In order to know whether the code conforms to eslint standard , Need to use vscode Inside eslint plugin, This plug-in is based on AST Provides a method of local verification , After installing this plug-in , Will automatically detect js and jsx Whether the document does not conform to eslint Standard code .
Then you can execute some commands , For example, according to .eslintrc.js( This file is automatically generated after installing the plug-in , There is a set of rules by default , You can add your own rules on this basis later ) Configure rules to correct automatically demo.js Non conformance in eslint Standard code :eslint demo.js --fixstay vscode Want more convenient 、 Automatic repair and detection of multiple files can be achieved without using commands , Need to be in vscode Configure the settings in preferences , Every time you save a file, you can use .eslintrc.js Configure rules to check the format of various types of files and make some simple repairs .
vscode in eslint plugin How to configure automatic detection and simple repair ?
-
open vscode Settings in

-
It opens at json Settings in form

-
Here are eslint Some configuration methods ( Add... After the original configuration ):
(1) A set of language identifiers , Specify the file to validate , Only by default "javascript", "javascriptreact" two , That is, only for js And jsx Document carried out eslint check , If you want to edit more files eslint check , Manual configuration required , My project is applied to ts,tsx and vue Type file , Here is my configuration , Added later ts,tsx and vue file :
"eslint.validate": [ "javascript", "javascriptreact", "typescript", "typescriptreact", "vue", ],(2) The following settings include ESLint All providers including turn on automatic repair :
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },(3) More configuration Click here
版权声明
本文为[cornivores]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210615591311.html
边栏推荐
猜你喜欢

【W5500】STM32 H743驱动W5500进行UDP收发

【STM32】H743的25MHZ外部晶振下480MHz时钟的CubeMX配置图
![[STM32 H7] h743 notes on address distribution of each memory block](/img/69/afc9be30693b9b2a64ce5b896e309f.jpg)
[STM32 H7] h743 notes on address distribution of each memory block

How to download and use the journal latex template

Chapter 5 support vector machine (SVM)

云计算中网络基础知识

Sql中 代替not in的一种解决方式

Canvas drawing Luffy
![[AD] modular schematic drawing pit point record](/img/b3/02136b8f9193d87a4780dd131f5d35.png)
[AD] modular schematic drawing pit point record

为短路运算符布尔表达式添加括号
随机推荐
yolov5的onnx模型去除transpose层
2020杭电多校赛第四场1007 Go Running(hdu6808)
毕业设计,疫情心理咨询系统截图查看
【STM32 H7】H743各个内存块地址分布备忘
BatchUpdateException在MySQL和Oracle的区别
applicationContext. How to solve the problem of XML becoming gray document
【ThreadX】H743ZI+LAN8720+ThreadX+NetX Duo移植
Draw biaxial separation diagram with ggplot2
电脑内网外网同时访问-解决办法
杂项1
2020牛客暑期多校训练营第二场 I Interval题解
【KSZ8863】KSZ8863交换机芯片的信息汇总与打板验证结果
vee-validate 验证
2. mysql基本查询
Sublime Text3 安装简体中文
Curl command
开放平台及其技术架构
Draw QQ charts with different distribution
【W5500】STM32 H743驱动W5500进行UDP收发
Official account version update and introduction