Skip to content

Commit 25f67a5

Browse files
committed
chore: lint code
1 parent c69de78 commit 25f67a5

14 files changed

Lines changed: 358 additions & 343 deletions

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default antfu({
2222
'ts/no-non-null-asserted-optional-chain': 'off',
2323
'no-unused-expressions': 'off',
2424
'test/consistent-test-it': 'off',
25+
'test/no-identical-title': 'off',
2526

2627
'antfu/if-newline': 'off',
2728
},

packages/deob/src/ast-utils/ast.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import * as t from '@babel/types';
1+
import * as t from '@babel/types'
22

33
export function getPropName(node: t.Node): string | undefined {
44
if (t.isIdentifier(node)) {
5-
return node.name;
5+
return node.name
66
}
77
if (t.isStringLiteral(node)) {
8-
return node.value;
8+
return node.value
99
}
1010
if (t.isNumericLiteral(node)) {
11-
return node.value.toString();
11+
return node.value.toString()
1212
}
1313
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import type { Matcher } from '@codemod/matchers';
1+
import type { Matcher } from '@codemod/matchers'
22

3-
type MatcherType<T> = T extends Matcher<infer U> ? U : T;
3+
type MatcherType<T> = T extends Matcher<infer U> ? U : T
44

55
declare module '@codemod/matchers' {
66
// The library only implements up to 5 arguments, but we need more
77
// Also have to keep the other ones because of recursive matchers (numberExpressions.ts)
88

9-
export function or(): Matcher<never>;
10-
export function or<T>(first: Matcher<T> | T): Matcher<T>;
9+
export function or(): Matcher<never>
10+
export function or<T>(first: Matcher<T> | T): Matcher<T>
1111
export function or<T, U>(
1212
first: Matcher<T> | T,
1313
second: Matcher<U> | U,
14-
): Matcher<T | U>;
14+
): Matcher<T | U>
1515
export function or<T, U, V>(
1616
first: Matcher<T> | T,
1717
second: Matcher<U> | U,
1818
third: Matcher<V> | V,
19-
): Matcher<T | U | V>;
19+
): Matcher<T | U | V>
2020
export function or<T, U, V, W>(
2121
first: Matcher<T> | T,
2222
second: Matcher<U> | U,
2323
third: Matcher<V> | V,
2424
fourth: Matcher<W> | W,
25-
): Matcher<T | U | V | W>;
25+
): Matcher<T | U | V | W>
2626
export function or<T, U, V, W, X>(
2727
first: Matcher<T> | T,
2828
second: Matcher<U> | U,
2929
third: Matcher<V> | V,
3030
fourth: Matcher<W> | W,
3131
fifth: Matcher<X> | X,
32-
): Matcher<T | U | V | W | X>;
32+
): Matcher<T | U | V | W | X>
3333
export function or<const T extends readonly unknown[]>(
3434
...matchers: T
35-
): Matcher<MatcherType<T[number]>>;
35+
): Matcher<MatcherType<T[number]>>
3636
}
3737

3838
declare module '@codemod/matchers/build/matchers/predicate' {
3939
// Convenience overload for not having to cast the value when using it
40-
export function predicate<T>(predicate: (value: T) => boolean): Matcher<T>;
40+
export function predicate<T>(predicate: (value: T) => boolean): Matcher<T>
4141
}
4242

4343
declare module '@babel/traverse' {
4444
interface NodePath {
4545
/**
4646
* Turns an AST into code
4747
*/
48-
toString(): string;
48+
toString: () => string
4949
}
5050
}
Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
1-
import type { Binding, NodePath } from '@babel/traverse';
2-
import traverse from '@babel/traverse';
3-
import * as t from '@babel/types';
4-
import * as m from '@codemod/matchers';
5-
import { codePreview } from './generator';
1+
import type { Binding, NodePath } from '@babel/traverse'
2+
import traverse from '@babel/traverse'
3+
import * as t from '@babel/types'
4+
import * as m from '@codemod/matchers'
5+
import { codePreview } from './generator'
66

77
export function renameFast(binding: Binding, newName: string): void {
88
binding.referencePaths.forEach((ref) => {
9-
if (ref.isExportDefaultDeclaration()) return;
9+
if (ref.isExportDefaultDeclaration()) return
1010
if (!ref.isIdentifier()) {
1111
throw new Error(
1212
`Unexpected reference (${ref.type}): ${codePreview(ref.node)}`,
13-
);
13+
)
1414
}
1515

1616
// To avoid conflicts with other bindings of the same name
17-
if (ref.scope.hasBinding(newName)) ref.scope.rename(newName);
18-
ref.node.name = newName;
19-
});
17+
if (ref.scope.hasBinding(newName)) ref.scope.rename(newName)
18+
ref.node.name = newName
19+
})
2020

2121
// Also update assignments
2222
const patternMatcher = m.assignmentExpression(
2323
'=',
2424
m.or(m.arrayPattern(), m.objectPattern()),
25-
);
25+
)
2626
binding.constantViolations.forEach((ref) => {
2727
// To avoid conflicts with other bindings of the same name
28-
if (ref.scope.hasBinding(newName)) ref.scope.rename(newName);
28+
if (ref.scope.hasBinding(newName)) ref.scope.rename(newName)
2929

3030
if (ref.isAssignmentExpression() && t.isIdentifier(ref.node.left)) {
31-
ref.node.left.name = newName;
32-
} else if (ref.isUpdateExpression() && t.isIdentifier(ref.node.argument)) {
33-
ref.node.argument.name = newName;
34-
} else if (
35-
ref.isUnaryExpression({ operator: 'delete' }) &&
36-
t.isIdentifier(ref.node.argument)
31+
ref.node.left.name = newName
32+
}
33+
else if (ref.isUpdateExpression() && t.isIdentifier(ref.node.argument)) {
34+
ref.node.argument.name = newName
35+
}
36+
else if (
37+
ref.isUnaryExpression({ operator: 'delete' })
38+
&& t.isIdentifier(ref.node.argument)
3739
) {
38-
ref.node.argument.name = newName;
39-
} else if (ref.isVariableDeclarator() && t.isIdentifier(ref.node.id)) {
40-
ref.node.id.name = newName;
41-
} else if (ref.isVariableDeclarator() && t.isArrayPattern(ref.node.id)) {
42-
const ids = ref.getBindingIdentifiers();
40+
ref.node.argument.name = newName
41+
}
42+
else if (ref.isVariableDeclarator() && t.isIdentifier(ref.node.id)) {
43+
ref.node.id.name = newName
44+
}
45+
else if (ref.isVariableDeclarator() && t.isArrayPattern(ref.node.id)) {
46+
const ids = ref.getBindingIdentifiers()
4347
for (const id in ids) {
4448
if (id === binding.identifier.name) {
45-
ids[id].name = newName;
49+
ids[id].name = newName
4650
}
4751
}
48-
} else if (ref.isFor() || patternMatcher.match(ref.node)) {
52+
}
53+
else if (ref.isFor() || patternMatcher.match(ref.node)) {
4954
traverse(ref.node, {
5055
Identifier(path) {
51-
if (path.scope !== ref.scope) return path.skip();
56+
if (path.scope !== ref.scope) return path.skip()
5257
if (path.node.name === binding.identifier.name) {
53-
path.node.name = newName;
58+
path.node.name = newName
5459
}
5560
},
5661
noScope: true,
57-
});
58-
} else if (ref.isFunctionDeclaration() && t.isIdentifier(ref.node.id)) {
59-
ref.node.id.name = newName;
60-
} else {
62+
})
63+
}
64+
else if (ref.isFunctionDeclaration() && t.isIdentifier(ref.node.id)) {
65+
ref.node.id.name = newName
66+
}
67+
else {
6168
throw new Error(
6269
`Unexpected constant violation (${ref.type}): ${codePreview(ref.node)}`,
63-
);
70+
)
6471
}
65-
});
72+
})
6673

67-
binding.scope.removeOwnBinding(binding.identifier.name);
68-
binding.scope.bindings[newName] = binding;
69-
binding.identifier.name = newName;
74+
binding.scope.removeOwnBinding(binding.identifier.name)
75+
binding.scope.bindings[newName] = binding
76+
binding.identifier.name = newName
7077
}
7178

7279
export function renameParameters(
7380
path: NodePath<t.Function>,
7481
newNames: string[],
7582
): void {
76-
const params = path.node.params as t.Identifier[];
83+
const params = path.node.params as t.Identifier[]
7784
for (let i = 0; i < Math.min(params.length, newNames.length); i++) {
78-
const binding = path.scope.getBinding(params[i].name)!;
79-
renameFast(binding, newNames[i]);
85+
const binding = path.scope.getBinding(params[i].name)!
86+
renameFast(binding, newNames[i])
8087
}
8188
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import type { Scope } from '@babel/traverse';
2-
import { toIdentifier } from '@babel/types';
1+
import type { Scope } from '@babel/traverse'
2+
import { toIdentifier } from '@babel/types'
33

44
/**
55
* Like scope.generateUid from babel, but without the underscore prefix and name filters
66
*/
77
export function generateUid(scope: Scope, name: string = 'temp'): string {
8-
let uid = '';
9-
let i = 1;
8+
let uid = ''
9+
let i = 1
1010
do {
11-
uid = toIdentifier(i > 1 ? `${name}${i}` : name);
12-
i++;
11+
uid = toIdentifier(i > 1 ? `${name}${i}` : name)
12+
i++
1313
} while (
14-
scope.hasLabel(uid) ||
15-
scope.hasBinding(uid) ||
16-
scope.hasGlobal(uid) ||
17-
scope.hasReference(uid)
18-
);
14+
scope.hasLabel(uid)
15+
|| scope.hasBinding(uid)
16+
|| scope.hasGlobal(uid)
17+
|| scope.hasReference(uid)
18+
)
1919

20-
const program = scope.getProgramParent();
21-
program.references[uid] = true;
22-
program.uids[uid] = true;
23-
return uid;
20+
const program = scope.getProgramParent()
21+
program.references[uid] = true
22+
program.uids[uid] = true
23+
return uid
2424
}

0 commit comments

Comments
 (0)