Skip to content

Commit b090b46

Browse files
authored
Merge pull request #21 from 142vip/feat/dev-docs
feat: eslint标准化,侧边栏配置优化
2 parents 444f01e + 6ad7e82 commit b090b46

File tree

252 files changed

+15222
-1968
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+15222
-1968
lines changed

.eslintrc.js

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,153 @@ module.exports = {
1717
'@typescript-eslint'
1818
],
1919
rules: {
20-
'no-unused-vars': 0
20+
'no-unused-vars': 0,
21+
'arrow-spacing': [2, {
22+
before: true,
23+
after: true
24+
}], // 箭头函数中的箭头前后加空格
25+
'block-spacing': [2, 'always'], // 花括号内前后加空格
26+
'brace-style': [2, '1tbs', {
27+
allowSingleLine: true
28+
}], // 允许单行方法
29+
'comma-dangle': [2, 'never'], // 在对象、数组文字中不使用尾随逗号
30+
'comma-spacing': [2, {
31+
before: false,
32+
after: true
33+
}], // 逗号后空格
34+
'comma-style': [2, 'last'], // 对象、数组元素同一行后面加逗号
35+
'constructor-super': 2, // 派生类的构造函数必须调用super()
36+
curly: [2, 'multi-line'], // 方法体多行不允许省略花括号
37+
'dot-location': [2, 'property'], // 点与属性在同一行
38+
'eol-last': 2, // 在非空文件的末尾强制使用至少一个换行符
39+
'generator-star-spacing': [2, {
40+
before: true,
41+
after: true
42+
}], // 生成器函数前后加空格
43+
'handle-callback-err': [2, '^(err|error)$'], // err的错误回调必须处理
44+
'key-spacing': [2, {
45+
beforeColon: false,
46+
afterColon: true
47+
}], // 对象字面亮键和冒号之间存在空格
48+
'keyword-spacing': [2, {
49+
before: true,
50+
after: true
51+
}],
52+
'new-cap': [2, {
53+
newIsCap: true,
54+
capIsNew: false
55+
}], // 构造函数首字母大写
56+
'no-class-assign': 2, // 禁止修改类申明的变量
57+
'no-cond-assign': 2, // 禁止条件表达式中出现赋值操作符
58+
'no-const-assign': 2, // 禁止修改 const 声明的变量
59+
'no-delete-var': 2, // 禁止删除变量
60+
'no-dupe-args': 2, // 禁止 function 定义中出现重名参数
61+
'no-dupe-class-members': 2, // 禁止类成员中出现重复的名称
62+
'no-dupe-keys': 2, // 禁止对象字面量中出现重复的 key
63+
'no-duplicate-case': 2, // 禁止出现重复的 case 标签
64+
'no-empty-character-class': 2, // 禁止在正则表达式中使用空字符集
65+
'no-empty-pattern': 2, // 禁止使用空解构模式
66+
'no-eval': 2, // 禁用 eval()
67+
'no-ex-assign': 2, // 禁止对 catch 子句的参数重新赋值
68+
'no-extend-native': 2, // 禁止扩展原生类型
69+
'no-extra-bind': 2, // 禁止不必要的函数绑定
70+
'no-extra-boolean-cast': 2, // 禁止不必要的布尔转换
71+
'no-extra-parens': [2, 'functions'], // 禁止不必要的括号
72+
'no-fallthrough': 2, // 禁止 case 语句落空
73+
'no-func-assign': 2, // 禁止对 function 声明重新赋值
74+
'no-implied-eval': 2, // 禁止使用类似 eval() 的方法
75+
'no-inner-declarations': [2, 'functions'], // 禁止在嵌套的块中出现function 声明
76+
'no-invalid-regexp': 2, // 禁止 RegExp 构造函数中存在无效的正则表达式字符串
77+
'no-irregular-whitespace': 2, // 禁止不规则的空白
78+
'no-iterator': 2, // 禁用 __iterator__ 属性
79+
'no-label-var': 2, // 不允许标签与变量同名
80+
'no-labels': [2, {
81+
allowLoop: false,
82+
allowSwitch: false
83+
}], // 禁用标签语句
84+
'no-lone-blocks': 2, // 禁用不必要的嵌套块
85+
'no-multi-spaces': 2, // 禁止使用多个空格
86+
'no-multi-str': 2, // 禁止使用多行字符串
87+
'no-multiple-empty-lines': [2, {
88+
max: 2
89+
}], // 禁止出现多行空行
90+
'no-global-assign': 2, // 禁止对原生对象或只读的全局对象进行赋值
91+
'no-unsafe-negation': 2, // 禁止对关系运算符的左操作数使用否定操作符
92+
'no-new-object': 2, // 禁用 Object 的构造函数
93+
'no-new-require': 2, // 禁止调用 require 时使用 new 操作符
94+
'no-new-wrappers': 2, // 禁止对 String,Number 和 Boolean 使用 new 操作符
95+
'no-obj-calls': 2, // 禁止把全局对象作为函数调用
96+
'no-octal': 2, // 禁用八进制字面量
97+
'no-octal-escape': 2, // 禁止在字符串中使用八进制转义序列
98+
'no-path-concat': 2, // 禁止对 __dirname 和 __filename 进行字符串连接
99+
'no-proto': 2, // 禁用 __proto__ 属性
100+
'no-redeclare': 2, // 禁止多次声明同一变量
101+
'no-regex-spaces': 2, // 禁止正则表达式字面量中出现多个空格
102+
'no-return-assign': [2, 'except-parens'], // 禁止在 return 语句中使用赋值语句
103+
'no-self-assign': 2, // 禁止自我赋值,禁止自身比较
104+
'no-sequences': 2, // 禁用逗号操作符
105+
'no-shadow-restricted-names': 2, // 禁止将标识符定义为受限的名字
106+
'func-call-spacing': 2, // 要求或禁止在函数标识符和其调用之间有空格
107+
'no-sparse-arrays': 2, // 禁用稀疏数组
108+
'no-this-before-super': 2, // 禁止在构造函数中,在调用 super() 之前使用 this 或 super
109+
'no-trailing-spaces': 2, // 禁用行尾空格
110+
'no-undef-init': 2, // 禁止将变量初始化为 undefined
111+
'no-unexpected-multiline': 2, // 禁止出现令人困惑的多行表达式
112+
'no-unmodified-loop-condition': 2, // 禁用一成不变的循环条件
113+
'no-unneeded-ternary': [2, {
114+
defaultAssignment: false
115+
}], // 禁止可以在有更简单的可替代的表达式时使用三元操作符
116+
'no-unreachable': 2, // 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
117+
'no-unsafe-finally': 2, // 禁止在 finally 语句块中出现控制流语句
118+
'no-useless-call': 2, // 禁止不必要的 .call() 和 .apply()
119+
'no-useless-computed-key': 2, // 禁止在对象中使用不必要计算属性
120+
'no-useless-constructor': 2, // 禁用不必要的构造函数
121+
'no-useless-escape': 0, // 禁用不必要的转义字符
122+
'no-whitespace-before-property': 2, // 禁止属性前有空白
123+
'no-with': 2, // 禁用 with 语句
124+
'one-var': [2, {
125+
initialized: 'never'
126+
}], // 强制函数中的变量要么一起声明要么分开声明
127+
'operator-linebreak': [2, 'after', {
128+
overrides: {
129+
'?': 'before',
130+
':': 'before'
131+
}
132+
}], // 强制操作符使用一致的换行符
133+
'padded-blocks': [2, 'never'], // 要求或禁止块内填充
134+
quotes: [2, 'single', {
135+
avoidEscape: true,
136+
allowTemplateLiterals: true
137+
}], // 强制使用一致的反勾号、双引号或单引号
138+
'semi-spacing': [2, {
139+
before: false,
140+
after: true
141+
}], // 强制在块之前使用一致的空格
142+
'space-before-blocks': [2, 'always'], // 强制在块之前使用一致的空格
143+
'space-before-function-paren': [2, 'never'], // 强制在 function的左括号之前使用一致的空格
144+
'space-in-parens': [2, 'never'], // 强制在圆括号内使用一致的空格
145+
'space-infix-ops': 2, // 要求操作符周围有空格
146+
'space-unary-ops': [2, {
147+
words: true,
148+
nonwords: false
149+
}], // 强制在一元操作符前后使用一致的空格
150+
'template-curly-spacing': [2, 'never'], // 禁止模板字符串中的嵌入表达式周围空格的使用
151+
'use-isnan': 2, // 要求使用 isNaN() 检查 NaN
152+
'valid-typeof': 2, // 强制 typeof 表达式与有效的字符串进行比较
153+
'wrap-iife': [2, 'any'], // 要求 IIFE(立即执行函数) 使用括号括起来
154+
'prefer-const': 2, // 要求使用 const 声明那些声明后不再被修改的变量
155+
'object-curly-spacing': [2, 'always', {
156+
objectsInObjects: false
157+
}], // 强制在大括号中使用一致的空格
158+
'array-bracket-spacing': [2, 'never'], // 强制数组方括号中使用一致的空格
159+
160+
/* 非强制 */
161+
camelcase: [0, {
162+
properties: 'always'
163+
}], // 对属性名称强制使用驼峰样式
164+
'no-array-constructor': 2, // 禁止使用 Array 构造函数创建数组
165+
'no-caller': 2, // 禁止使用 arguments.caller 和 arguments.callee
166+
'no-console': 'off', // 禁用console
167+
'no-control-regex': 0// 禁止在正则表达式中使用控制字符
21168
}
22169
}

code/algorithm/DeepClone.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* 判断数据类型
33
* @param target
44
*/
5-
function checkType (target) {
5+
function checkType(target) {
66
// 判断类型 -typeof -instanceof -toString.call() -Array.isArray()
77
return Object.prototype.toString.call(target).slice(8, -1)
88
}
@@ -11,12 +11,12 @@ function checkType (target) {
1111
* 基于Json序列化的深拷贝【不能处理函数】
1212
* @param target
1313
*/
14-
function DeepCloneByJSON (target) {
14+
function DeepCloneByJSON(target) {
1515
return JSON.parse(JSON.stringify(target))
1616
}
1717

1818
// 基于递归思想的深拷贝
19-
function DeepClone (target) {
19+
function DeepClone(target) {
2020
let result
2121
const targetType = checkType(target)
2222

code/algorithm/GetNumberOfK.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param data
44
* @param k
55
*/
6-
function GetNumberOfK (data, k) {
6+
function GetNumberOfK(data, k) {
77
// 分两次二分查找,知道重复元素首次和最后一次出现位置,相减就能拿到重复次数了.
88

99
// 左侧二分查找,重复元素第一次出现的索引位置
@@ -16,7 +16,7 @@ function GetNumberOfK (data, k) {
1616
return left === -1 && right === -1 ? 0 : right - left + 1
1717
}
1818

19-
function rightBinarySearch (data, target) {
19+
function rightBinarySearch(data, target) {
2020
if (!data.length) {
2121
return -1
2222
}
@@ -44,7 +44,7 @@ function rightBinarySearch (data, target) {
4444
}
4545

4646
// [left,right]
47-
function leftBinarySearch (data, target) {
47+
function leftBinarySearch(data, target) {
4848
if (!data.length) {
4949
return -1
5050
}

code/algorithm/LeftRotateString.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
function LeftRotateString (str, n) {
2+
function LeftRotateString(str, n) {
33
if (!str) {
44
return str
55
}
@@ -15,7 +15,7 @@ function LeftRotateString (str, n) {
1515
}
1616

1717
// 数组中翻转
18-
function reverse (arr, left, right) {
18+
function reverse(arr, left, right) {
1919
while (left < right) {
2020
// 元素交换
2121
arr = swap(arr, left, right)
@@ -28,7 +28,7 @@ function reverse (arr, left, right) {
2828
}
2929

3030
// 元素交换
31-
function swap (arr, left, right) {
31+
function swap(arr, left, right) {
3232
const temp = arr[left]
3333
arr[left] = arr[right]
3434
arr[right] = temp

code/algorithm/QuickSort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @param low
55
* @param high
66
*/
7-
function quickSort (data, low, high) {
7+
function quickSort(data, low, high) {
88
console.log(data, low, high)
99
const pivot = partition(data, low, high)
1010
const result = []
@@ -39,7 +39,7 @@ function quickSort (data, low, high) {
3939
* @param low
4040
* @param high
4141
*/
42-
function partition (data, low, high) {
42+
function partition(data, low, high) {
4343
const pivot = data[low]
4444

4545
while (low < high) {

code/algorithm/debounce.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param func
44
* @param time
55
*/
6-
function debounce (func, time) {
6+
function debounce(func, time) {
77
let timeout
88
return () => {
99
clearTimeout(timeout)
@@ -14,7 +14,7 @@ function debounce (func, time) {
1414
}
1515
}
1616

17-
function test () {
17+
function test() {
1818
console.log(new Date().getTime())
1919
}
2020

code/algorithm/find.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param target
44
* @param array
55
*/
6-
function Find (target, array) {
6+
function Find(target, array) {
77
if (!array) {
88
return false
99
}

code/algorithm/isUSD.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { lstat } = require('fs-extra')
22

3-
function isUSD (str) {
3+
function isUSD(str) {
44
if (!str.startsWith('$')) {
55
return false
66
}

code/algorithm/merge.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/**
2-
*
32
* @param A int整型一维数组
43
* @param B int整型一维数组
5-
* @return void
64
*/
7-
function merge (A, m, B, n) {
5+
function merge(A, m, B, n) {
86
let pre = 0
97
let next = 0
108
let result = []
@@ -29,8 +27,4 @@ function merge (A, m, B, n) {
2927
}
3028
return result
3129
}
32-
module.exports = {
33-
merge
34-
}
35-
3630
console.log(merge([], 0, [1], 1))

code/algorithm/mergeLink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
function ListNode (x) {
1+
function ListNode(x) {
22
this.val = x
33
this.next = null
44
}
55

6-
function Merge1 (pHead1, pHead2) {
6+
function Merge1(pHead1, pHead2) {
77
// 单调不减 可以理解 等于或者大于递增
88
let p1 = pHead1
99
let p2 = pHead2
@@ -37,7 +37,7 @@ function Merge1 (pHead1, pHead2) {
3737
return result.next
3838
}
3939

40-
function Merge (pHead1, pHead2) {
40+
function Merge(pHead1, pHead2) {
4141
const vhead = {}
4242
let cur = vhead
4343
while (pHead1 && pHead2) {

0 commit comments

Comments
 (0)