Skip to content

Commit ced14f3

Browse files
committed
fix lint
1 parent d134c94 commit ced14f3

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

biome.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"useIgnoreFile": true
77
},
88
"files": {
9-
"ignore": ["__testfixtures__"]
9+
"ignore": ["__testfixtures__", "tests"]
1010
},
1111
"linter": {
1212
"enabled": true,
@@ -15,6 +15,9 @@
1515
"correctness": {
1616
"noUnusedImports": "error",
1717
"useExhaustiveDependencies": "off"
18+
},
19+
"suspicious": {
20+
"noExplicitAny": "off"
1821
}
1922
}
2023
},

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,5 @@
4747
"engines": {
4848
"node": ">=18"
4949
},
50-
"workspaces": [
51-
"./recipes/*"
52-
]
50+
"workspaces": ["./recipes/*"]
5351
}

recipes/magic-redirect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
"devDependencies": {
2020
"@codemod.com/jssg-types": "^1.3.1"
2121
}
22-
}
22+
}
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
1-
import type { SgRoot } from "@codemod.com/jssg-types/src/main";
2-
import type Js from '@codemod.com/jssg-types/src/langs/javascript';
1+
import type Js from '@codemod.com/jssg-types/src/langs/javascript'
2+
import type { SgRoot } from '@codemod.com/jssg-types/src/main'
33

44
async function transform(root: SgRoot<Js>): Promise<string> {
5-
const rootNode = root.root();
6-
5+
const rootNode = root.root()
6+
77
// Helper function to find the request parameter name
88
function findRequestParamName(node: any): string {
99
// Start from the call expression and traverse up to find function parameters
10-
let current = node;
10+
let current = node
1111
while (current) {
12-
const parent = current.parent();
13-
if (!parent) break;
12+
const parent = current.parent()
13+
if (!parent) break
1414
// Check if we're in a function declaration or arrow function
1515
if (parent.kind() === 'function_declaration' || parent.kind() === 'arrow_function') {
16-
const params = parent.field('parameters');
16+
const params = parent.field('parameters')
1717

1818
if (params && params.children().length > 0) {
19-
const firstParam = params.children()[1];
19+
const firstParam = params.children()[1]
2020
if (firstParam.kind() === 'required_parameter') {
21-
const pattern = firstParam.field('pattern');
21+
const pattern = firstParam.field('pattern')
2222
if (pattern && pattern.kind() === 'identifier') {
23-
return pattern.text();
23+
return pattern.text()
2424
}
2525
}
2626
}
2727
}
2828

29-
current = parent;
29+
current = parent
3030
}
31-
return 'req'; // default fallback
31+
return 'req' // default fallback
3232
}
3333

3434
// Find all redirect and location
3535
const nodes = rootNode.findAll({
3636
rule: {
3737
any: [
3838
{
39-
pattern: "$OBJ.redirect($ARG)",
39+
pattern: '$OBJ.redirect($ARG)',
4040
},
4141
{
42-
pattern: "$OBJ.location($ARG)",
43-
}]
44-
}
45-
});
42+
pattern: '$OBJ.location($ARG)',
43+
},
44+
],
45+
},
46+
})
4647

4748
const edits = nodes.reduce((acc: any[], node: any) => {
48-
const requestParamName = findRequestParamName(node);
49-
const obj = node.getMatch("OBJ");
50-
const arg = node.getMatch("ARG");
49+
const requestParamName = findRequestParamName(node)
50+
const obj = node.getMatch('OBJ')
51+
const arg = node.getMatch('ARG')
5152

5253
// Only transform when the argument is the literal 'back' (single or double quotes)
53-
const argText = arg && typeof arg.text === 'function' ? arg.text() : null;
54-
if (argText !== "'back'" && argText !== '"back"' && argText !== "‘back’" && argText !== "“back”") {
55-
return acc; // skip this node, no edit
54+
const argText = arg && typeof arg.text === 'function' ? arg.text() : null
55+
if (argText !== "'back'" && argText !== '"back"' && argText !== '‘back’' && argText !== '“back”') {
56+
return acc // skip this node, no edit
5657
}
5758

5859
// Case: obj.redirect('back') or obj.location('back')
59-
const objText = obj?.text();
60-
const methodName = node.text().includes('.redirect(') ? 'redirect' : 'location';
61-
acc.push(node.replace(`${objText}.${methodName}(${requestParamName}.get("Referrer") || "/")`));
62-
return acc;
63-
}, [] as any[]);
60+
const objText = obj?.text()
61+
const methodName = node.text().includes('.redirect(') ? 'redirect' : 'location'
62+
acc.push(node.replace(`${objText}.${methodName}(${requestParamName}.get("Referrer") || "/")`))
63+
return acc
64+
}, [] as any[])
6465

65-
const newSource = rootNode.commitEdits(edits);
66-
return newSource;
66+
const newSource = rootNode.commitEdits(edits)
67+
return newSource
6768
}
6869

69-
export default transform;
70+
export default transform

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"strictNullChecks": true,
1111
"outDir": "build"
1212
},
13-
"include": ["**/*.ts", "./recipes/",],
13+
"include": ["**/*.ts", "./recipes/"],
1414
"exclude": ["node_modules", "build", "**/__testfixtures__", "**/__test__", "**/*.spec.ts"]
1515
}

0 commit comments

Comments
 (0)