1.中文官網:
2.先看一個寫好的eslint規則:

3.下面再給一個例子
module.exports = {
"parser": "babel-eslint",
'env': {
'browser': true,
'es6': true
},
'extends': [
'eslint:recommended',
'plugin:react/recommended'
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaFeatures': {
'jsx': true,
legacyDecorators: true
},
'ecmaVersion': 2018,
'sourceType': 'module'
},
'plugins': [
'react'
],
'rules': {
'no-console':'off',
'indent': [
'error',
2
],
'linebreak-style': [
'error',
'unix'
],
'quotes': [
'error',
'single'
],
'semi': [
'error',
'never'
],
'react/prop-types': 0,
'no-mixed-spaces-and-tabs': [2, 'smart-tabs']
}
}
4.給了這么多例子,但eslint的配置寫起來也太麻煩了。接下來教你一種方法(前提是你的項目必須裝eslint了哈):
在你項目根目錄的終端輸入 :
eslint --init
這時終端會問你幾個問題,你根據你項目的情況回答yes or no,如下:

這時會生成一個.eslinttrc.js文件,你可以在進一步修改。
5.有一些問題,比如eslint的規則http://eslint.cn/docs/rules/中,有小扳手圖標的,編輯器可以幫你自動修復。

這時,你需要在package.json中進行如下配置:

