Skip to content

Commit

Permalink
use number for rule severity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaciras committed Dec 18, 2023
1 parent 3ec47cb commit 78d0f17
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
34 changes: 17 additions & 17 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,65 @@ module.exports = {
},
rules: {
// 很多语言单括号用于 char 类型,这里保持一致使用双括号。
"quotes": ["error", "double", {
"quotes": [2, "double", {
avoidEscape: true,
}],

// 空格缩进都是异端!
"indent": ["error", "tab", {
"indent": [2, "tab", {
SwitchCase: 1,
}],

// 换行用俩字符确实多余,统一使用 \n
"linebreak-style": ["error", "unix"],
"linebreak-style": [2, "unix"],

// 函数名和括号间不加空格,关键字与括号间加。
"space-before-function-paren": ["error", {
"space-before-function-paren": [2, {
anonymous: "always",
named: "never",
asyncArrow: "always",
}],

// 单行对象的大括号内加一个空格
"object-curly-spacing": ["error", "always"],
"object-curly-spacing": [2, "always"],

// 代码块与前面的标识符之间加一个空格
"space-before-blocks": "error",
"space-before-blocks": 2,

// 对象键值之间的冒号后面加一个空格
"key-spacing": "error",
"key-spacing": 2,

// 我应该不会这么写吧,不过还是加上以免意外。
"no-array-constructor": "error",
"no-array-constructor": 2,

// 永远使用三等号,避免一些无聊的问题。
// 有时候其它语言写多了,回来会忘。
"eqeqeq": "error",
"eqeqeq": 2,

// 永远不要使用 for-in,这个遗留的糟粕已经被其他写法取代了。
// 同样 Python 写多了可能会忘。
"no-restricted-syntax": ["error", "ForInStatement"],
"no-restricted-syntax": [2, "ForInStatement"],

// 一些永远不要使用的特性。
"no-sequences": "error",
"no-throw-literal": "error",
"no-label-var": "error",
"no-sequences": 2,
"no-throw-literal": 2,
"no-label-var": 2,

"no-unused-vars": ["error", {
"no-unused-vars": [2, {
varsIgnorePattern: "^_+$",
}],

// 不加分号是有坑的,不知道为什么默认不启用这规则。
"semi": ["error", "always"],
"semi": [2, "always"],

// 多行元素末尾一律加逗号,便于删除和调整顺序。
"comma-dangle": ["error", "always-multiline"],
"comma-dangle": [2, "always-multiline"],

// window 对象上一些容易混淆的成员,要求必须以 `window.*` 来调用。
// 该列表参考了:
// https://github.com/facebook/create-react-app/tree/master/packages/confusing-browser-globals
// 这里比它的规则少些,删除了一些常用的。
"no-restricted-globals": ["error",
"no-restricted-globals": [2,
"event", "name", "external",
"top", "length", "parent",
"addEventListener", "removeEventListener",
Expand Down
8 changes: 4 additions & 4 deletions packages/jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ module.exports = {
],
rules: {
// 生命周期钩子当然要写在最前面啊。
"jest/prefer-hooks-on-top": "error",
"jest/prefer-hooks-on-top": 2,

// 无法识别第三方库的断言,添加 assertFunctionNames 也很麻烦。
"jest/expect-expect": "off",
"jest/expect-expect": 0,

// 有些库还在用回调式的 API,强行转异步不好看。
"jest/no-done-callback": "off",
"jest/no-done-callback": 0,

// Prefer sugar functions.
"jest/prefer-mock-promise-shorthand": "error",
"jest/prefer-mock-promise-shorthand": 2,
},
};
4 changes: 2 additions & 2 deletions packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = {
},
rules: {
// 写太快可能没注意这个,加上该规则以便用 ESLint 批量改。
"react/jsx-curly-brace-presence": ["error", {
"react/jsx-curly-brace-presence": [2, {
props: "never",
children: "never",
}],

// 都是动态页面的时代了,默认的 submit 基本用不到,还容易漏。
"react/button-has-type": "error",
"react/button-has-type": 2,
},
};
14 changes: 7 additions & 7 deletions packages/typescript/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ module.exports = {
],
rules: {
// 不让用感叹号和 any 是不对的,总有些情况必须这样做。
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-explicit-any": 0,

// TS 并非完美无缺,总有用到 @ts-ignore 的时候。
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-ts-comment": 0,

// 多行总是加上末尾的逗号,一来整齐些,二是调整顺序更方便。
// TS 多了一些情况比如枚举、泛型,要单独配置下。
"@typescript-eslint/comma-dangle": ["error", "always-multiline"],
"@typescript-eslint/comma-dangle": [2, "always-multiline"],

// 没有用到的参数也不要省略,保持签名的一致性。
"@typescript-eslint/no-unused-vars": ["error", {
"@typescript-eslint/no-unused-vars": [2, {
args: "none",
ignoreRestSiblings: true,
}],

// 复杂类型的数组还是用泛型好些,简单的用方括号。
"@typescript-eslint/array-type": ["error", {
"@typescript-eslint/array-type": [2, {
default: "array-simple",
}],

// 习惯加标点了,保持一致吧。
"@typescript-eslint/member-delimiter-style": "error",
"@typescript-eslint/member-delimiter-style": 2,

// 不要把 non-null 的感叹号跟等号连用。
"@typescript-eslint/no-confusing-non-null-assertion": "error",
"@typescript-eslint/no-confusing-non-null-assertion": 2,
},
};
6 changes: 3 additions & 3 deletions packages/vue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
],
rules: {
// 没有 emits 或是 onXXX props 的话事件会绑到元素上,应当避免。
"vue/require-explicit-emits": ["error", { allowProps: true }],
"vue/require-explicit-emits": [2, { allowProps: true }],

// I use double quote in JS, so single for template.
"vue/html-quotes": ["error", "single", { avoidEscape: true }],
"vue/html-quotes": [2, "single", { avoidEscape: true }],

// 驼峰更好,跟 JSX 一致,同时也和 Custom Element 区分开。
"vue/component-name-in-template-casing": ["error", "PascalCase"],
"vue/component-name-in-template-casing": [2, "PascalCase"],
},
};
2 changes: 1 addition & 1 deletion packages/vue/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ module.exports = {
parser: "vue-eslint-parser",
}],
rules: {
"vue/block-lang": ["error", { script: { lang: "ts" } }],
"vue/block-lang": [2, { script: { lang: "ts" } }],
},
};

0 comments on commit 78d0f17

Please sign in to comment.