.gitignore 文件配置
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.eslintignore 文件配置
config
node_modules
public
scripts
.editorconfig 文件配置
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
.eslintrc文件配置
module.exports = {
'env': {
'node': true,
'browser': true,
'amd': true,
'es6': true
},
'parser': 'babel-eslint',
'extends': [
'eslint:recommended',
'plugin:react/recommended' // 新增
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaFeatures': {
'jsx': true
},
'ecmaVersion': 2018,
'sourceType': 'module'
},
'plugins': [
'react',
'react-hooks' // 新增
],
'rules': {
'react/jsx-uses-react': 1,
'react-hooks/rules-of-hooks': 'error', // 檢查 Hook 的規(guī)則
'react-hooks/exhaustive-deps': 'warn', // 檢查 effect 的依賴
'react/no-access-state-in-setstate': 0, // 禁止在setstate中使用setstate
'react/jsx-wrap-multilines': 1, // 防止多行JSX周圍缺少括號
'react/jsx-tag-spacing': [1, { // 驗證JSX左括號和右括號中和周圍的空格
'closingSlash': 'never',
'beforeSelfClosing': 'always',
'afterOpening': 'never'
}],
'react/jsx-space-before-closing': 1, // 在JSX中關(guān)閉括號之前驗證間距
'react/jsx-props-no-multi-spaces': 1, // 在內(nèi)聯(lián)JSX道具之間禁止使用多個空格
"react/jsx-curly-spacing": [1, {// 在JSX屬性和表達式中的花括號內(nèi)強制或不允許空格
"when": "always",
"spacing": {
"objectLiterals": "never"
}
}],
"react/jsx-equals-spacing": [1, "never"], // 強制或禁止JSX屬性中等號周圍的空格
'accessor-pairs': 1, // getter與setter同時存在
'arrow-spacing': [1, { // 箭頭前后加空格
'before': true,
'after': true
}],
'block-spacing': [1, 'always'], // 標記塊前后需加空格
'brace-style': [1, '1tbs', { // 函數(shù)()與{}不許換行
'allowSingleLine': true
}],
'camelcase': [0, { // 不強制使用駝峰命名
'properties': 'always'
}],
'comma-dangle': [1, 'never'], // 不允許尾隨逗號
'comma-spacing': [1, { // 在逗號前后不允許有空格
'before': false,
'after': true
}],
'constructor-super': 1, // constructor必須配合super()
'curly': [1, 'multi-line'], // 花括號行內(nèi)可省略,塊級必須加花括號
'dot-location': [1, 'property'], // 在點之前和之后強制換行
'eol-last': 1, // 在文件末尾要求或禁止換行
'eqeqeq': [1, 'allow-null'], // 全等
'generator-star-spacing': [1, { // generator內(nèi)前后增加空位
'before': true,
'after': true
}],
'handle-callback-err': [1, '^(err|error)$'], // 強制執(zhí)行回調(diào)錯誤處理
'indent': [1, 2, { // 縮進規(guī)則
'SwitchCase': 1
}],
'jsx-quotes': [1, 'prefer-single'], // 強制在JSX屬性(jsx引號)中一致使用雙引號或單引號
'key-spacing': [1, { // 鍵間距
'beforeColon': false,
'afterColon': true
}],
'keyword-spacing': [1, { // 關(guān)鍵字間距
'before': true,
'after': true
}],
'new-cap': [1, { // 要求構(gòu)造函數(shù)名稱以大寫字母
'newIsCap': true,
'capIsNew': false
}],
'new-parens': 1, // 不帶參數(shù)(新括號)調(diào)用構(gòu)造函數(shù)時需要括號
'no-debugger': 1,
'no-array-constructor': 1, // 禁止使用Array構(gòu)造函數(shù)
'no-console': 0, // 允許使用console
'no-class-assign': 1, // 禁止修改類聲明的變量
'no-cond-assign': 1, // 在條件語句中禁止賦值運算符
'no-const-assign': 1, // 禁止修改使用const聲明的變量
'no-control-regex': 0, // 禁止在正則表達式中使用控制字符
'no-delete-var': 1, // 禁止刪除變量
'no-dupe-args': 1, // 禁止在function定義中使用重復(fù)的參數(shù)
'no-dupe-class-members': 2, // 禁止使用重復(fù)名稱
'no-dupe-keys': 2, // 禁止在對象文字中使用重復(fù)鍵
'no-duplicate-case': 2, // 禁止重復(fù)案例標簽的規(guī)則
'no-empty-character-class': 1, // 禁止在正則表達式中使用空字符類
'no-empty-pattern': 2, // 禁止使用空的銷毀模式
'no-eval': 0, // 禁止使用eval()
'no-ex-assign': 1, // 禁止在catch子句中重新分配異常
'no-extend-native': 2, // 禁止擴展本機對象
'no-extra-bind': 1, // 禁止不必要的功能綁定
'no-extra-boolean-cast': 1, // 禁止不必要的布爾類型轉(zhuǎn)換
'no-extra-parens': [1, 'functions'], // 禁止不必要的括號
'no-fallthrough': 1, // 禁止案例陳述失敗
'no-floating-decimal': 1, // 禁止浮動小數(shù)
'no-func-assign': 2, // 禁止重新分配function聲明
'no-implied-eval': 2, // 禁止隱含eval()
'no-inner-declarations': [2, 'functions'], // 禁止function在嵌套塊中使用變量或聲明
'no-invalid-regexp': 1, // 禁止在RegExp構(gòu)造函數(shù)中使用無效的正則表達式字符串
'no-irregular-whitespace': 1, // 禁止不規(guī)則空格
'no-iterator': 0, // 允許迭代器
'no-label-var': 2, // 禁止使用標簽作為變量名
'no-labels': [2, { // 禁止帶標簽的語句
'allowLoop': false,
'allowSwitch': false
}],
'no-lone-blocks': 2, // 禁止不必要的嵌套塊
'no-mixed-spaces-and-tabs': 1, // 不允許使用縮進的空格和制表符進行縮進
'no-multi-spaces': 1, // 禁止多個空格
'no-multi-str': 2, // 禁止多行字符串
'no-multiple-empty-lines': [1, { // 禁止多行空行
'max': 1
}],
'no-native-reassign': 2, // 禁止重新分配本機對象
'no-negated-in-lhs': 2, // 不允許在in表達式中取反左操作數(shù)
'no-new-object': 0, // 允許Object構(gòu)造函數(shù)
'no-new-require': 0, // 允許新要求
'no-new-symbol': 2, // 禁止符號構(gòu)造器
'no-new-wrappers': 1, // 禁止原始包裝器實例
'no-obj-calls': 1, // 禁止將全局對象屬性作為函數(shù)調(diào)用
'no-octal': 2, // 禁止使用八進制文字
'no-octal-escape': 2, // 禁止在字符串文字中使用八進制轉(zhuǎn)義序列
'no-path-concat': 2, // 使用__dirname和__filename時禁止字符串連接
'no-proto': 1, // 禁止__proto__
'no-redeclare': 1, // 禁止重新聲明變量
'no-regex-spaces': 1, // 禁止在正則表達式文字中使用多個空格
'no-return-assign': [2, 'except-parens'], // 禁止在return語句中進行賦值
'no-self-assign': 1, // 禁止自我分配
'no-self-compare': 1, // 禁止自我比較
'no-sequences': 2, // 禁止使用逗號運算符
'no-shadow-restricted-names': 2, // 禁止隱藏限制名稱
'no-spaced-func': 1, // 不允許在函數(shù)標識符及其應(yīng)用程序之間使用空格
'no-sparse-arrays': 1, // 禁止稀疏數(shù)組
'no-this-before-super': 0, // 在調(diào)用構(gòu)造函數(shù)之前,允許使用this
'no-throw-literal': 1, // 限制可以作為異常拋出的內(nèi)容
'no-trailing-spaces': 1, // 在行尾禁止尾隨空格
'no-undef': 2, // 禁止未聲明的變量
'no-undef-init': 1, // 禁止初始化為未定義
'no-unexpected-multiline': 2, // 禁止混淆多行表達式
'no-unmodified-loop-condition': 2, // 禁止未經(jīng)修改的循環(huán)條件
'no-unneeded-ternary': [1, { // 存在更簡單的選擇時禁止三元運算符
'defaultAssignment': false
}],
'no-unsafe-finally': 2, // 禁止以finally塊為單位的控制流語句
'no-unused-vars': [1, { // 禁止使用未使用的變量
'vars': 'all',
'args': 'none'
}],
'no-useless-call': 1, // 禁止不必要的.call()和.apply()
'no-useless-computed-key': 1, // 禁止在對象上使用不必要的計算屬性鍵
'no-useless-constructor': 1, // 禁止不必要的構(gòu)造函數(shù)
'no-useless-escape': 0, // 禁止不必要的轉(zhuǎn)義使用
'no-whitespace-before-property': 1, // 禁止在屬性前使用空格
'no-with': 2, // 禁止with
'one-var': [1, { // 強制變量在函數(shù)中一起聲明或一起聲明
'initialized': 'never'
}],
'operator-linebreak': [1, 'after', { // 對操作員實施一致的換行符樣式
'overrides': {
'?': 'before',
':': 'before'
}
}],
'quotes': [1, 'single', { // 強制使用引號,雙引號或單引號(引號)的一致使用
'avoidEscape': true,
'allowTemplateLiterals': true
}],
'semi': [1, 'never'], // 分號的使用
'semi-spacing': [1, { // 在分號之前和之后加強間距
'before': false,
'after': true
}],
'object-curly-spacing': [1, "always", { "objectsInObjects": false }], // 大括號間距
'spaced-line-comment': [0, 'always'], // 注釋后面需加一個空格
'space-before-blocks': [1, 'always'], // 要求或禁止在塊前加空格
'space-before-function-paren': [1, 'never'], // 函數(shù)括號前需要或不允許空格
'space-in-parens': [1, 'never'], // 禁止或在括號內(nèi)使用空格
'space-infix-ops': 1, // 要求在中綴運算符之間加空格
'space-unary-ops': [1, { // 一元運算符之前或之后需要空格或不允許空格
'words': true,
'nonwords': false
}],
'spaced-comment': [1, 'always', { // 要求或不允許以空格(制表符或制表符)開頭的注釋
'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',', ' ']
}],
'template-curly-spacing': [1, 'always'], // 在模板字符串中強制使用間距
'use-isnan': 2, // isNaN()檢查時需要調(diào)用NaN
'valid-typeof': 2, // 強制比較typeof表達式與有效字符串
'wrap-iife': [1, 'any'], // 要求將IIFE包裹起來
'yield-star-spacing': [1, 'both'], // 強制間距圍繞*在yield*表達式
'yoda': [1, 'never'], // 要求或禁止Yoda條件
'prefer-const': 1, // 建議使用const
'array-bracket-spacing': [1, 'never'], // 禁止或在方括號內(nèi)加空格
'react/prop-types': 0,
},
'settings': {
'react': {
'version': '16.8.6' // 新增
}
}
}