Skip to content

Commit cdd9085

Browse files
committed
style(eslint): format
1 parent 338cebe commit cdd9085

23 files changed

+358
-410
lines changed

.prettierrc.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
module.exports = {
2-
// 一行最多 100 字符
3-
printWidth: 100,
4-
// 使用 2 个空格缩进
5-
tabWidth: 2,
6-
// 不使用缩进符使用空格
7-
useTabs: false,
8-
// 行尾需要有分号
9-
semi: true,
10-
// 使用单引号
11-
singleQuote: true,
2+
// 根据显示样式决定 html 要不要折行
3+
htmlWhitespaceSensitivity: 'css',
124
// 对象的 key 仅在必要时用引号
135
quoteProps: 'as-needed',
146
// jsx 不使用单引号,而使用双引号
157
jsxSingleQuote: false,
16-
// 尾随逗号
17-
trailingComma: 'all',
18-
// 大括号内的首尾需要空格
19-
bracketSpacing: true,
208
// 标签的反尖括号需要换行
219
bracketSameLine: true,
2210
// 箭头函数,只有一个参数的时候,也需要括号
2311
arrowParens: 'always',
24-
// 每个文件格式化的范围是文件的全部内容
25-
rangeStart: 0,
26-
rangeEnd: Infinity,
12+
// 使用默认的折行标准 不会更改 markdown 文本中的换行
13+
proseWrap: 'preserve',
14+
// 尾随逗号
15+
trailingComma: 'all',
16+
// 大括号内的首尾需要空格
17+
bracketSpacing: true,
2718
// 不需要写文件开头的 @prettier
2819
requirePragma: false,
2920
// 不需要自动在文件开头插入 @prettier
3021
insertPragma: false,
31-
// 使用默认的折行标准 不会更改 markdown 文本中的换行
32-
proseWrap: 'preserve',
33-
// 根据显示样式决定 html 要不要折行
34-
htmlWhitespaceSensitivity: 'css',
22+
rangeEnd: Infinity,
23+
// 使用单引号
24+
singleQuote: true,
3525
// 换行符使用 auto
3626
endOfLine: 'auto',
27+
// 一行最多 100 字符
28+
printWidth: 100,
29+
// 不使用缩进符使用空格
30+
useTabs: false,
31+
// 每个文件格式化的范围是文件的全部内容
32+
rangeStart: 0,
33+
// 使用 2 个空格缩进
34+
tabWidth: 2,
35+
// 行尾需要有分号
36+
semi: true,
3737
};

__tests__/dom.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { expectError, expectType } from './utils';
21
import type { SettableDOMProps, SettableDOMStyle } from '../src';
2+
import { expectError, expectType } from './utils';
33

44
describe('dom', () => {
55
test('SettableProps', () => {
@@ -8,14 +8,14 @@ describe('dom', () => {
88
// @ts-expect-error
99
expectError<T>({ id: '' });
1010

11-
expectType<SettableDOMProps<HTMLAnchorElement>>({ id: '', className: '', href: '' });
11+
expectType<SettableDOMProps<HTMLAnchorElement>>({ className: '', href: '', id: '' });
1212
});
1313
test('SettableProps', () => {
1414
type T = SettableDOMProps<HTMLDivElement>;
15-
expectType<T>({ id: '', className: '' });
15+
expectType<T>({ className: '', id: '' });
1616
// @ts-expect-error
17-
expectError<T>({ id: '', className: '', href: '' });
17+
expectError<T>({ className: '', href: '', id: '' });
1818

19-
expectType<SettableDOMProps<HTMLAnchorElement>>({ id: '', className: '', href: '' });
19+
expectType<SettableDOMProps<HTMLAnchorElement>>({ className: '', href: '', id: '' });
2020
});
2121
});

__tests__/object-path.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { expectError, expectType } from './utils';
21
import type {
3-
PathOf,
4-
TransferPath,
2+
ValueMatchingPath,
53
TransferPathOf,
4+
TransferPath,
65
TypeOfPath,
7-
ValueMatchingPath,
86
PathUnion,
7+
PathOf,
98
} from '../src';
9+
import { expectError, expectType } from './utils';
1010
const ab: 'a' | 'b' = Math.random() > 0.5 ? 'a' : 'b';
1111
describe('object-path', function () {
1212
test('TypeOfPath', () => {
@@ -113,16 +113,16 @@ describe('object-path', function () {
113113
expectError<PathUnion<{ a: number }>>('a' as 'a' | 'b');
114114
expectType<PathUnion<{ a: number; b: string }>>('a' as 'a' | 'b');
115115

116-
type T = PathUnion<{ a: number; b: string; bb: { c: string; cc: { d: string } } }>;
117-
expectType<T>('a' as 'a' | 'b' | 'bb' | 'bb.c' | 'bb.cc' | 'bb.cc.d');
116+
type T = PathUnion<{ bb: { cc: { d: string }; c: string }; a: number; b: string }>;
117+
expectType<T>('a' as 'bb.cc.d' | 'bb.cc' | 'bb.c' | 'bb' | 'a' | 'b');
118118

119119
type T3 = PathUnion<{
120+
b: { cc: { dd: string }; c: boolean };
121+
bb: { cc: { d: string }; c: string };
120122
a: number;
121-
b: { c: boolean; cc: { dd: string } };
122-
bb: { c: string; cc: { d: string } };
123123
}>;
124124
expectType<T3>(
125-
'a' as 'a' | 'b' | 'b.c' | 'b.cc' | 'b.cc.dd' | 'bb' | 'bb.c' | 'bb.cc' | 'bb.cc.d',
125+
'a' as 'b.cc.dd' | 'bb.cc.d' | 'bb.cc' | 'b.cc' | 'bb.c' | 'b.c' | 'bb' | 'a' | 'b',
126126
);
127127
});
128128
});

__tests__/object.test.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { expectError, expectType } from './utils';
2-
import {
1+
import type {
2+
OmitFirstParameters,
3+
ConvertOptionalPart,
4+
FlattenIntersection,
35
CheckDuplicateKey,
4-
DuplicateKeys,
5-
IfEquals,
66
IfEqualsReverse,
7-
OmitFirstParameters,
7+
ConvertOptional,
8+
DuplicateKeys,
9+
ReverseObject,
810
OptionalKeys,
9-
PublicOnly,
1011
ReadonlyKeys,
1112
RequiredKeys,
1213
RequiredOnly,
13-
UrlParams,
1414
WritableKeys,
1515
DeepReadonly,
1616
RequiredPart,
1717
PartialPart,
18+
PublicOnly,
1819
TupleToObj,
19-
ConvertOptionalPart,
20-
ConvertOptional,
21-
FlattenIntersection,
20+
UrlParams,
21+
IfEquals,
2222
Mix,
23-
ReverseObject,
2423
} from '../src';
24+
import { expectError, expectType } from './utils';
25+
import type { Writeable } from '../src';
2526
import * as console from 'console';
26-
import { Writeable } from '../src';
2727

2828
const ab: 'a' | 'b' = Math.random() > 0.5 ? 'a' : 'b';
2929
const abc: 'a' | 'b' | 'c' = Math.random() > 0.5 ? 'a' : Math.random() > 0.5 ? 'b' : 'c';
@@ -65,7 +65,7 @@ describe('object', () => {
6565
expectError<T>(9);
6666
});
6767
test('ReadonlyKeys', () => {
68-
type T = ReadonlyKeys<{ readonly a: number; b: string; readonly c: boolean }>; // 'a'|'c'
68+
type T = ReadonlyKeys<{ readonly c: boolean; readonly a: number; b: string }>; // 'a'|'c'
6969

7070
expectType<T>('a');
7171
expectType<T>('c');
@@ -75,7 +75,7 @@ describe('object', () => {
7575
expectError<T>('d');
7676
});
7777
test('WritableKeys', () => {
78-
type T = WritableKeys<{ readonly a: number; b: string; readonly c: boolean; d: string }>; // 'b'|'d'
78+
type T = WritableKeys<{ readonly c: boolean; readonly a: number; b: string; d: string }>; // 'b'|'d'
7979
expectType<T>('b');
8080
expectType<T>('d');
8181
// @ts-expect-error
@@ -84,7 +84,7 @@ describe('object', () => {
8484
expectError<T>('c');
8585
});
8686
test('RequiredKeys', () => {
87-
type T = RequiredKeys<{ a: string; b?: number; c: boolean }>; // 'a'|'c'
87+
type T = RequiredKeys<{ b?: number; c: boolean; a: string }>; // 'a'|'c'
8888
expectType<T>('a');
8989
expectType<T>('c');
9090
// @ts-expect-error
@@ -93,7 +93,7 @@ describe('object', () => {
9393
expectError<T>('d');
9494
});
9595
test('RequiredKeys', () => {
96-
type T = OptionalKeys<{ a: string; b?: number; c: boolean }>; // 'b'
96+
type T = OptionalKeys<{ b?: number; c: boolean; a: string }>; // 'b'
9797
expectType<T>('b');
9898
// @ts-expect-error
9999
expectError<T>('a');
@@ -102,25 +102,25 @@ describe('object', () => {
102102
});
103103
test('RequiredOnly', () => {
104104
interface I {
105-
a: string;
105+
c: undefined | boolean;
106106
b?: number;
107-
c: boolean | undefined;
107+
a: string;
108108
}
109109
type T = RequiredOnly<I>; // {a: string; c: boolean | undefined}
110110
type T2 = OptionalKeys<I>; // "b"
111-
expectType<T>({ a: '', c: undefined });
112-
expectType<T>({ a: '', c: true });
111+
expectType<T>({ c: undefined, a: '' });
112+
expectType<T>({ c: true, a: '' });
113113
expectType<T2>('b');
114114
// @ts-expect-error
115115
expectError<T>({ a: '', c: 1 });
116116
// @ts-expect-error
117-
expectError<T>({ a: 1, c: false });
117+
expectError<T>({ c: false, a: 1 });
118118
});
119119
test('PublicOnly', () => {
120120
class Foo {
121-
public a = '';
122-
protected b = 2;
123121
private c = false;
122+
protected b = 2;
123+
public a = '';
124124

125125
constructor() {
126126
console.log(this.c);
@@ -224,26 +224,26 @@ describe('object', () => {
224224
});
225225
test('DeepReadonly', () => {
226226
interface A {
227-
a: number;
228-
b: string;
229227
c: {
230228
d: boolean;
231229
f: string;
232230
};
231+
a: number;
232+
b: string;
233233
}
234234

235235
type B = DeepReadonly<A>;
236236

237237
interface C {
238-
readonly a: number;
239-
readonly b: string;
240238
readonly c: DeepReadonly<{
241239
d: boolean;
242240
f: string;
243241
}>;
242+
readonly a: number;
243+
readonly b: string;
244244
}
245245

246-
const b: B = { a: 1, b: '', c: { d: true, f: '' } };
246+
const b: B = { c: { d: true, f: '' }, b: '', a: 1 };
247247

248248
// @ts-expect-error
249249
b.c.d = false; // error 不能修改.c.d,ts检查会报错
@@ -266,10 +266,10 @@ describe('object', () => {
266266

267267
const obj2: RequiredPart<O, 'a'> = { a: 1, c: 2 };
268268

269-
expectType<number | undefined>(obj.a);
269+
expectType<undefined | number>(obj.a);
270270
// @ts-expect-error
271271
expectError<number>(obj.a);
272-
expectType<number | undefined>(obj.b);
272+
expectType<undefined | number>(obj.b);
273273
// @ts-expect-error
274274
expectError<number>(obj.b);
275275
expectType<number>(obj.c);
@@ -280,15 +280,15 @@ describe('object', () => {
280280
expectType<number>(obj2.c);
281281

282282
expectError<{
283-
a: number;
284283
b?: number;
284+
a: number;
285285
c: number;
286286
// @ts-expect-error
287287
}>(obj);
288288

289289
expectType<{
290-
a: number;
291290
b?: number;
291+
a: number;
292292
c: number;
293293
}>(obj2);
294294
});
@@ -306,8 +306,8 @@ describe('object', () => {
306306

307307
expectType<{
308308
a?: number;
309-
b: number;
310309
c?: number;
310+
b: number;
311311
}>(obj);
312312
});
313313
test('TupleToObj', () => {
@@ -324,10 +324,10 @@ describe('object', () => {
324324
type T2 = TupleToObj<typeof a, string, 'a' | 'c', 'dd'>;
325325

326326
expectType<T2>({});
327-
expectType<Required<T2>>({ '1': '', '2': '', '3': '', a: 'dd', b: '', c: 'dd' });
328-
expectType<T2>({ '1': '', '2': '', '3': '', a: 'dd', b: '', c: 'dd' });
327+
expectType<Required<T2>>({ '1': '', '2': '', '3': '', a: 'dd', c: 'dd', b: '' });
328+
expectType<T2>({ '1': '', '2': '', '3': '', a: 'dd', c: 'dd', b: '' });
329329
// @ts-expect-error
330-
expectError<Required<T2>>({ '1': '', '2': '', '3': '', a: 'd', b: '', c: 'd' });
330+
expectError<Required<T2>>({ '1': '', '2': '', '3': '', a: 'd', c: 'd', b: '' });
331331
});
332332

333333
test('ConvertOptionalPart', () => {
@@ -341,7 +341,7 @@ describe('object', () => {
341341

342342
expectType<ConvertOptionalPart<T, 'a'>>({} as { a: 1; b: 2; c: 3; d: 4; e: 5 });
343343
expectType<ConvertOptionalPart<T, 'a'>>({} as { a: undefined; b: 2; c: 3; d: 4; e: 5 });
344-
expectType<ConvertOptionalPart<T, 'a'>>({} as { a: 1 | undefined; b: 2; c: 3; d: 4; e: 5 });
344+
expectType<ConvertOptionalPart<T, 'a'>>({} as { a: undefined | 1; b: 2; c: 3; d: 4; e: 5 });
345345

346346
expectType<ConvertOptionalPart<T, 'a'>>({ a: 1, b: 2, c: 3, d: 4, e: 5 });
347347
expectType<ConvertOptionalPart<T, 'a'>>({ a: undefined, b: 2, c: 3, d: 4, e: 5 });
@@ -402,7 +402,7 @@ describe('object', () => {
402402
e: 5,
403403
});
404404

405-
const v2 = { a: undefined, b: 2, c: 3, d: undefined, e: undefined };
405+
const v2 = { a: undefined, d: undefined, e: undefined, b: 2, c: 3 };
406406
// @ts-expect-error d 和 e 不可设置为 undefined
407407
expectError<ConvertOptionalPart<T2, 'a' | 'b' | 'c'>>(v2);
408408
});
@@ -417,7 +417,7 @@ describe('object', () => {
417417

418418
expectType<ConvertOptional<T>>({} as { a: 1; b: 2; c: 3; d: 4; e: 5 });
419419
expectType<ConvertOptional<T>>({} as { a: undefined; b: 2; c: 3; d: 4; e: 5 });
420-
expectType<ConvertOptional<T>>({} as { a: 1 | undefined; b: 2; c: 3; d: 4; e: 5 });
420+
expectType<ConvertOptional<T>>({} as { a: undefined | 1; b: 2; c: 3; d: 4; e: 5 });
421421

422422
expectType<ConvertOptional<T>>({ a: 1, b: 2, c: 3, d: 4, e: 5 });
423423
expectType<ConvertOptional<T>>({ a: undefined, b: 2, c: 3, d: 4, e: 5 });
@@ -525,19 +525,19 @@ describe('object', () => {
525525
b: string;
526526
}
527527

528-
const objR: A = { a: 1, b: 'b' };
528+
const objR: A = { b: 'b', a: 1 };
529529
// @ts-expect-error
530530
objR.a = 2;
531531

532-
const objW: Writeable<A> = { a: 1, b: 'b' };
532+
const objW: Writeable<A> = { b: 'b', a: 1 };
533533
objW.a = 2;
534534

535535
type B = Readonly<A>;
536-
const objR2: B = { a: 1, b: 'b' };
536+
const objR2: B = { b: 'b', a: 1 };
537537
// @ts-expect-error
538538
objR2.b = 'c';
539539

540-
const objW2: Writeable<B> = { a: 1, b: 'b' };
540+
const objW2: Writeable<B> = { b: 'b', a: 1 };
541541
objW2.b = 'c';
542542
});
543543

@@ -548,6 +548,6 @@ describe('object', () => {
548548
// @ts-expect-error
549549
expectError<ReverseObject<{ a: 1; b: 2; c: 3 }>>({ 1: 'a', 2: 'b' });
550550
// @ts-expect-error
551-
expectError<ReverseObject<{ a: 1; b: 2; c: 3 }>>({ 0: 1, 1: 'a', 2: 'b' });
551+
expectError<ReverseObject<{ a: 1; b: 2; c: 3 }>>({ 1: 'a', 2: 'b', 0: 1 });
552552
});
553553
});

0 commit comments

Comments
 (0)