Skip to content

Commit 21a02be

Browse files
committed
improve(eslint-config-ts-lib): 改进执行 lint 的速度
1 parent 922787f commit 21a02be

File tree

191 files changed

+6065
-919
lines changed

Some content is hidden

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

191 files changed

+6065
-919
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
build

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# 变更说明
22

3+
## 0.14.4
4+
5+
- improve(eslint-config-ts-lib): 改进执行 lint 的速度
6+
- fix(eslint-config-ts-lib): 修复 prettier 和 eslint 规则冲突的缺陷
7+
- breadchange(eslint-config-ts-lib): 增加 jsdoc 和 typescript 类型显式声明的规则
8+
- improve(ts-lib-scripts): 启用 eslint 的缓存
9+
310
## v0.14.3 - 2021.8.19
411

512
- fix(ts-lib-tools): 修复打包时包含了 jest 的 `__snapshots__` 目录的缺陷

e2e/eslint/class-use-this.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class Demo {
2+
method_a(): any {
3+
return this.method_a;
4+
}
5+
}

e2e/eslint/method-reassign.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* 累加
3+
*
4+
* @param acc 累加值
5+
* @param item 需要合并的项
6+
*/
7+
export function reduce(acc: Record<string, string>, item: string): void {
8+
acc[item] = '123';
9+
}

e2e/jest-resolver-tsconfig-paths/__tests__/module-a.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import k from '@test/module-a/k';
21
import moduleA from '@test/module-a';
2+
import k from '@test/module-a/k';
33

44
it('module-a', () => {
55
expect(k).toBeDefined();
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export default function a() {
1+
/**
2+
* 测试函数
3+
*/
4+
export default function a(): string {
25
return 'x';
36
}

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lint-staged": "^8.1.7",
2020
"react": "^16.8.6",
2121
"rimraf": "^2.6.3",
22-
"typescript": "^4.3.5"
22+
"typescript": "^4.4.2"
2323
},
2424
"prettier": {
2525
"printWidth": 80,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"husky": "^4.2.5",
2222
"lerna": "^3.16.4",
2323
"lint-staged": "^8.1.7",
24-
"typescript": "^4.3.5",
24+
"typescript": "^4.4.2",
2525
"typescript-plugin-css-modules": "^3.4.0"
2626
},
2727
"eslintConfig": {

packages/babel-preset-ts-lib/create.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module.exports = function create(_api, _opts, env) {
1616
},
1717
},
1818
],
19-
// eslint-disable-next-line prettier/prettier
2019
isEnvProduction && [
2120
require('@babel/preset-env').default,
2221
{
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { transform, TransformOptions } from '@babel/core';
1+
import type { TransformOptions } from '@babel/core';
2+
import { transform } from '@babel/core';
3+
24
import tsLibBabelPreset from '../index';
35

46
const transformOptions: TransformOptions = {
@@ -8,9 +10,10 @@ const transformOptions: TransformOptions = {
810

911
/**
1012
* 编译源码
13+
*
1114
* @param source 源码
1215
*/
13-
export default function buildSource(source: string) {
16+
export default function buildSource(source: string): string {
1417
const babelFileResult = transform(source, transformOptions);
1518
return babelFileResult.code;
1619
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
const eslintConfig = {
22
extends: ['ts-lib'],
3-
rules: {
4-
'prettier/prettier': 'off',
5-
'import/no-cycle': 'off',
6-
},
73
};
84

95
module.exports = eslintConfig;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
tsconfig.json
2+
scripts
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,123 @@
11
# eslint-config-ts-lib
22

33
[ts-lib-scripts](https://github.com/sinoui/ts-lib-scripts) 创建的 ts 库项目使用的 ESLint 配置
4+
5+
## 安装
6+
7+
```bash
8+
yarn add eslint-config-ts-lib typescript --dev
9+
```
10+
11+
## 使用
12+
13+
```json
14+
{
15+
"eslintConfig": {
16+
"extends": "ts-lib"
17+
}
18+
}
19+
```
20+
21+
## 包含的规则
22+
23+
- [for-direction](./docs/rules/for-direction.md)
24+
- [getter-return](./docs/rules/getter-return.md)
25+
- [no-async-promise-executor](./docs/rules/no-async-promise-executor.md)
26+
- [no-compare-neg-zero](./docs/rules/no-compare-neg-zero.md)
27+
- [no-cond-assign](./docs/rules/no-cond-assign.md)
28+
- [no-constant-condition](./docs/rules/no-constant-condition.md)
29+
- [no-control-regex](./docs/rules/no-control-regex.md)
30+
- [no-debugger](./docs/rules/no-debugger.md)
31+
- [no-dupe-args](./docs/rules/no-dupe-args.md)
32+
- [no-dupe-else-if](./docs/rules/no-dupe-else-if.md)
33+
- [no-dupe-keys](./docs/rules/no-dupe-keys.md)
34+
- [no-duplicate-case](./docs/rules/no-duplicate-case.md)
35+
- [no-empty](./docs/rules/no-empty.md)
36+
- [no-empty-character-class](./docs/rules/no-empty-character-class.md)
37+
- [no-ex-assign](./docs/rules/no-ex-assign.md)
38+
- [no-extra-boolean-cast](./docs/rules/no-extra-boolean-cast.md)
39+
- [no-extra-semi](./docs/rules/no-extra-semi.md)
40+
- [no-func-assign](./docs/rules/no-func-assign.md)
41+
- [no-import-assign](./docs/rules/no-import-assign.md)
42+
- [no-inner-declarations](./docs/rules/no-inner-declarations.md)
43+
- [no-invalid-regexp](./docs/rules/no-invalid-regexp.md)
44+
- [no-irregular-whitespace](./docs/rules/no-irregular-whitespace.md)
45+
- [no-misleading-character-class](./docs/rules/no-misleading-character-class.md)
46+
- [no-obj-calls](./docs/rules/no-obj-calls.md)
47+
- [no-prototype-builtins](./docs/rules/no-prototype-builtins.md)
48+
- [no-regex-spaces](./docs/rules/no-regex-spaces.md)
49+
- [no-setter-return](./docs/rules/no-setter-return.md)
50+
- [no-sparse-arrays](./docs/rules/no-sparse-arrays.md)
51+
- [no-unexpected-multiline](./docs/rules/no-unexpected-multiline.md)
52+
- [no-unreachable](./docs/rules/no-unreachable.md)
53+
- [no-unsafe-finally](./docs/rules/no-unsafe-finally.md)
54+
- [no-unsafe-negation](./docs/rules/no-unsafe-negation.md)
55+
- [use-isnan](./docs/rules/use-isnan.md)
56+
- [valid-typeof](./docs/rules/valid-typeof.md)
57+
- [no-case-declarations](./docs/rules/no-case-declarations.md)
58+
- [no-empty-pattern](./docs/rules/no-empty-pattern.md)
59+
- [no-fallthrough](./docs/rules/no-fallthrough.md)
60+
- [no-global-assign](./docs/rules/no-global-assign.md)
61+
- [no-octal](./docs/rules/no-octal.md)
62+
- [no-redeclare](./docs/rules/no-redeclare.md)
63+
- [no-self-assign](./docs/rules/no-self-assign.md)
64+
- [no-unused-labels](./docs/rules/no-unused-labels.md)
65+
- [no-useless-catch](./docs/rules/no-useless-catch.md)
66+
- [no-useless-escape](./docs/rules/no-useless-escape.md)
67+
- [no-with](./docs/rules/no-with.md)
68+
- [no-delete-var](./docs/rules/no-delete-var.md)
69+
- [no-shadow-restricted-names](./docs/rules/no-shadow-restricted-names.md)
70+
- [no-undef](./docs/rules/no-undef.md)
71+
- [no-unused-vars](./docs/rules/no-unused-vars.md)
72+
- [no-mixed-spaces-and-tabs](./docs/rules/no-mixed-spaces-and-tabs.md)
73+
- [constructor-super](./docs/rules/constructor-super.md)
74+
- [no-class-assign](./docs/rules/no-class-assign.md)
75+
- [no-const-assign](./docs/rules/no-const-assign.md)
76+
- [no-dupe-class-members](./docs/rules/no-dupe-class-members.md)
77+
- [no-new-symbol](./docs/rules/no-new-symbol.md)
78+
- [no-this-before-super](./docs/rules/no-this-before-super.md)
79+
- [require-yield](./docs/rules/require-yield.md)
80+
- [react/no-danger-with-children](./docs/rules/react/no-danger-with-children.md)
81+
- [react/display-name](./docs/rules/react/display-name.md)
82+
- [react/no-children-prop](./docs/rules/react/no-children-prop.md)
83+
- [react/no-deprecated](./docs/rules/react/no-deprecated.md)
84+
- [react/no-direct-mutation-state](./docs/rules/react/no-direct-mutation-state.md)
85+
- [react/no-find-dom-node](./docs/rules/react/no-find-dom-node.md)
86+
- [react/no-render-return-value](./docs/rules/react/no-render-return-value.md)
87+
- [react/no-is-mounted](./docs/rules/react/no-is-mounted.md)
88+
- [react/no-string-refs](./docs/rules/react/no-string-refs.md)
89+
- [react/no-unescaped-entities](./docs/rules/react/no-unescaped-entities.md)
90+
- [react/no-unknown-property](./docs/rules/react/no-unknown-property.md)
91+
- [react/react-in-jsx-scope](./docs/rules/react/react-in-jsx-scope.md)
92+
- [react/prop-types](./docs/rules/react/prop-types.md)
93+
- [react/require-render-return](./docs/rules/react/require-render-return.md)
94+
- [react/jsx-key](./docs/rules/react/jsx-key.md)
95+
- [react/jsx-no-comment-textnodes](./docs/rules/react/jsx-no-comment-textnodes.md)
96+
- [react/jsx-no-duplicate-props](./docs/rules/react/jsx-no-duplicate-props.md)
97+
- [react/jsx-no-target-blank](./docs/rules/react/jsx-no-target-blank.md)
98+
- [react/jsx-no-undef](./docs/rules/react/jsx-no-undef.md)
99+
- [react/jsx-uses-react](./docs/rules/react/jsx-uses-react.md)
100+
- [react/jsx-uses-vars](./docs/rules/react/jsx-uses-vars.md)
101+
- [@typescript-eslint/ban-ts-comment](./docs/rules/@typescript-eslint/ban-ts-comment.md)
102+
- [@typescript-eslint/adjacent-overload-signatures](./docs/rules/@typescript-eslint/adjacent-overload-signatures.md)
103+
- [@typescript-eslint/explicit-module-boundary-types](./docs/rules/@typescript-eslint/explicit-module-boundary-types.md)
104+
- [@typescript-eslint/no-explicit-any](./docs/rules/@typescript-eslint/no-explicit-any.md)
105+
- [@typescript-eslint/ban-types](./docs/rules/@typescript-eslint/ban-types.md)
106+
- [@typescript-eslint/no-extra-non-null-assertion](./docs/rules/@typescript-eslint/no-extra-non-null-assertion.md)
107+
- [@typescript-eslint/no-inferrable-types](./docs/rules/@typescript-eslint/no-inferrable-types.md)
108+
- [@typescript-eslint/no-empty-interface](./docs/rules/@typescript-eslint/no-empty-interface.md)
109+
- [@typescript-eslint/no-misused-new](./docs/rules/@typescript-eslint/no-misused-new.md)
110+
- [@typescript-eslint/no-namespace](./docs/rules/@typescript-eslint/no-namespace.md)
111+
- [@typescript-eslint/no-var-requires](./docs/rules/@typescript-eslint/no-var-requires.md)
112+
- [@typescript-eslint/no-non-null-asserted-optional-chain](./docs/rules/@typescript-eslint/no-non-null-asserted-optional-chain.md)
113+
- [@typescript-eslint/no-non-null-assertion](./docs/rules/@typescript-eslint/no-non-null-assertion.md)
114+
- [@typescript-eslint/no-this-alias](./docs/rules/@typescript-eslint/no-this-alias.md)
115+
- [@typescript-eslint/prefer-namespace-keyword](./docs/rules/@typescript-eslint/prefer-namespace-keyword.md)
116+
- [@typescript-eslint/prefer-as-const](./docs/rules/@typescript-eslint/prefer-as-const.md)
117+
- [@typescript-eslint/triple-slash-reference](./docs/rules/@typescript-eslint/triple-slash-reference.md)
118+
- [@typescript-eslint/no-empty-function](./docs/rules/@typescript-eslint/no-empty-function.md)
119+
- [@typescript-eslint/no-array-constructor](./docs/rules/@typescript-eslint/no-array-constructor.md)
120+
- [@typescript-eslint/no-extra-semi](./docs/rules/@typescript-eslint/no-extra-semi.md)
121+
- [@typescript-eslint/no-unused-vars](./docs/rules/@typescript-eslint/no-unused-vars.md)
122+
- [react-hooks/exhaustive-deps](./docs/rules/react-hooks/exhaustive-deps.md)
123+
- [react-hooks/rules-of-hooks](./docs/rules/react-hooks/rules-of-hooks.md)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# @typescript-eslint/adjacent-overload-signatures
2+
3+
> 来自 [plugin:@typescript-eslint/recommended](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin) 的规则。
4+
5+
# Require that member overloads be consecutive (`adjacent-overload-signatures`)
6+
7+
Grouping overloaded members together can improve readability of the code.
8+
9+
## Rule Details
10+
11+
This rule aims to standardize the way overloaded members are organized.
12+
13+
The following patterns are considered warnings:
14+
15+
```ts
16+
declare namespace Foo {
17+
export function foo(s: string): void;
18+
export function foo(n: number): void;
19+
export function bar(): void;
20+
export function foo(sn: string | number): void;
21+
}
22+
23+
type Foo = {
24+
foo(s: string): void;
25+
foo(n: number): void;
26+
bar(): void;
27+
foo(sn: string | number): void;
28+
};
29+
30+
interface Foo {
31+
foo(s: string): void;
32+
foo(n: number): void;
33+
bar(): void;
34+
foo(sn: string | number): void;
35+
}
36+
37+
class Foo {
38+
foo(s: string): void;
39+
foo(n: number): void;
40+
bar(): void {}
41+
foo(sn: string | number): void {}
42+
}
43+
44+
export function foo(s: string): void;
45+
export function foo(n: number): void;
46+
export function bar(): void;
47+
export function foo(sn: string | number): void;
48+
```
49+
50+
The following patterns are not warnings:
51+
52+
```ts
53+
declare namespace Foo {
54+
export function foo(s: string): void;
55+
export function foo(n: number): void;
56+
export function foo(sn: string | number): void;
57+
export function bar(): void;
58+
}
59+
60+
type Foo = {
61+
foo(s: string): void;
62+
foo(n: number): void;
63+
foo(sn: string | number): void;
64+
bar(): void;
65+
};
66+
67+
interface Foo {
68+
foo(s: string): void;
69+
foo(n: number): void;
70+
foo(sn: string | number): void;
71+
bar(): void;
72+
}
73+
74+
class Foo {
75+
foo(s: string): void;
76+
foo(n: number): void;
77+
foo(sn: string | number): void {}
78+
bar(): void {}
79+
}
80+
81+
export function bar(): void;
82+
export function foo(s: string): void;
83+
export function foo(n: number): void;
84+
export function foo(sn: string | number): void;
85+
```
86+
87+
## When Not To Use It
88+
89+
If you don't care about the general structure of the code, then you will not need this rule.
90+
91+
## Compatibility
92+
93+
- TSLint: [adjacent-overload-signatures](https://palantir.github.io/tslint/rules/adjacent-overload-signatures/)
94+
95+
## 参考文档
96+
97+
- [@typescript-eslint/adjacent-overload-signatures 官方文档](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md)

0 commit comments

Comments
 (0)