-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d04b4d0
commit 9964f60
Showing
16 changed files
with
109 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* 禁止将await写在循环里,因为这样就无法发送多个异步请求了,无法并发 | ||
* 有时需要在循环中写 await,所以此规则暂时关闭 | ||
*/ | ||
function bar() {} | ||
function baz() {} | ||
async function foo(things) { | ||
const results = []; | ||
for (const thing of things) { | ||
// Bad: each loop iteration is delayed until the entire asynchronous operation completes | ||
results.push(await bar(thing)); | ||
} | ||
return baz(results); | ||
} | ||
foo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* 禁止调用console | ||
*/ | ||
console.log() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* 禁止在正则表达式中使用控制字符 | ||
*/ | ||
const pattern1 = /\x1f/; | ||
const pattern2 = new RegExp("\x1f"); | ||
|
||
console.log(pattern1, pattern2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* 禁用debugger | ||
*/ | ||
function isTruthy(x) { | ||
debugger; | ||
return Boolean(x); | ||
} | ||
isTruthy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* 禁止在函数参数中出现重复名称的参数 | ||
* 禁用后打包会出错 | ||
*/ | ||
function foo(a, b, a) { | ||
console.log("value of the second a:", a); | ||
} | ||
foo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
/** | ||
* 禁止出现空的语句块 | ||
* catch语句中除外 | ||
* 允许catch语句为空语句块 | ||
*/ | ||
const arr = '' | ||
if (arr) { } | ||
if (arr) {} | ||
|
||
try { | ||
//doSomething(); | ||
} | ||
catch (ex) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* 禁止冗余的括号 | ||
* 具体规则: https://cn.eslint.org/docs/rules/no-extra-parens | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* 禁止多余的分号 | ||
* 具体规则: https://cn.eslint.org/docs/rules/no-extra-semi | ||
* prettier会自动修复 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
/** | ||
* 禁止将函数声明重新赋值 | ||
*/ | ||
const bar = 0 | ||
function foo() {} | ||
foo = bar; | ||
|
||
function foo() { | ||
foo = bar; | ||
} | ||
console.log(foo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* 禁止使用不规则的空白符 | ||
* "skipStrings": true (默认) 允许在字符串字面量中出现任何空白字符 | ||
* "skipComments": true 允许在注释中出现任何空白字符 | ||
* "skipRegExps": true 允许在正则表达式中出现任何空白字符 | ||
* "skipTemplates": true 允许在模板字面量中出现任何空白字符 | ||
* 具体规则: https://cn.eslint.org/docs/rules/no-irregular-whitespace | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* 禁止直接调用 Object.prototypes 的内置属性如:hasOwnProperty,isPrototypeOf | ||
*/ | ||
const foo = {} | ||
const hasBarProperty = foo.hasOwnProperty("bar"); | ||
console.warn(hasBarProperty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* 禁止令人困惑的多行表达式 | ||
* 具体规则: https://cn.eslint.org/docs/rules/no-unexpected-multiline | ||
*/ | ||
const bar = 0 | ||
const foo = bar | ||
(1 || 2).baz(); | ||
console.log(foo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* 禁止将 await 或 yield 的结果做为运算符的第二项 | ||
* 具体规则:https://cn.eslint.org/docs/rules/require-atomic-updates | ||
* 市面上大部分eslint规则库都关闭了此项 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
/** | ||
* typeof 操作符比较的对象必须是 'undefined', 'object', 'boolean', 'number', 'string', 'function', 'symbol', 或 'bigint' | ||
* typeof 操作符比较的对象必须是 'undefined', 'object', 'boolean', 'number', | ||
* 'string', 'function', 'symbol', 或 'bigint' | ||
*/ | ||
const foo = ""; | ||
const bar = ""; | ||
typeof foo === "strnig"; | ||
typeof foo === "undefimed"; | ||
typeof bar !== "nunber"; | ||
typeof bar !== "fucntion"; | ||
if (typeof foo === "strnig") { | ||
// | ||
} | ||
if (typeof foo === "undefimed") { | ||
// | ||
} | ||
if (typeof foo !== "nunber") { | ||
// | ||
} | ||
if (typeof foo !== "fucntion") { | ||
// | ||
} |