1、

为什么要有规范化规范

软件开发须要多人协同

不同开发有不同习惯和爱好

不同爱好减少我的项目保护老本

所以须要统一标准

哪里须要

代码、文档、日志

人为编写的都须要

代码标准化标准

施行规范化的办法

编码前人为的规范约定

通过工具实现Lint

2、ESLint介绍

最为支流的js lint检测工具

很容易对立开发者的编码格调

能够帮忙晋升编码能力

3、EsLint装置

npm install eslint --save-dev

4、疾速上手

查看步骤

编写问题代码

应用eslint执行

之前实现eslint配置

npm eslint init

npm eslint 对应地址

module.exports = {  env: {    browser: true,    es2020: true  },  extends: [    'standard'  ],  parserOptions: {    ecmaVersion: 11  },  rules: {  }}

eslint配置文件

module.exports = { env: {   browser: false,   es6: false }, extends: [  'standard' ], parserOptions: {    ecmaVersion: 2015 //检测语法,然而不检测变量是否可用,配置须要env来配置 }, rules: {   'no-alert': "error" }, globals: {   "jQuery": "readonly" }}

eslint配置正文

const str1 = "${name} is a coder" // eslint-disable-line no-template-curly-in-string

联合自动化工具

与我的项目对立,治理更加不便

eslint联合webpack后续配置

extends: [  ‘standard’,  ‘plugin:react/recommended’],查看typescriptparser: '@typescript-eslint/parser’,//配置语法解析器parserOptions: {ecmaVersion: 11},plugins: ['@typescript-eslint'],

eslint联合git hooks

pre-commit文件进行批改

husky能够实现git hooks的应用需要

'husky':{   hook:{   precommit:'npm run test'   }}