Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d377da9

Browse files
adds reverse id preset
1 parent d6219d4 commit d377da9

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { applyTransform } from "@codeshift/test-utils";
2+
import * as transformer from "./transform";
3+
4+
describe("codeshift-community#reverse-identifiers transform", () => {
5+
it("should transform correctly", async () => {
6+
const result = await applyTransform(
7+
transformer,
8+
`
9+
var foo = 'codeshift-community';
10+
console.log(foo);
11+
`,
12+
{ parser: "tsx" }
13+
);
14+
15+
expect(result).toMatchInlineSnapshot(`
16+
"var oof = 'codeshift-community';
17+
elosnoc.gol(oof);"
18+
`);
19+
});
20+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { API, FileInfo, Options } from "jscodeshift";
2+
3+
export default function transformer(
4+
file: FileInfo,
5+
{ jscodeshift: j }: API,
6+
options: Options
7+
) {
8+
const source = j(file.source);
9+
10+
/**
11+
* Codemod logic goes here 👇
12+
* -----
13+
* This is where the core logic for your codemod will go,
14+
* consider grouping specific actions into 'motions' and running them in sequence
15+
*
16+
* See this page for more information:
17+
* https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/authoring#motions
18+
*/
19+
source.find(j.Identifier).forEach((path) => {
20+
j(path).replaceWith(
21+
j.identifier(
22+
path.node.name
23+
.split("")
24+
.reverse()
25+
.join("")
26+
)
27+
);
28+
});
29+
30+
/**
31+
* Return your modified AST here 👇
32+
* -----
33+
* This is where your modified AST will be transformed back into a string
34+
* and written back to the file.
35+
*/
36+
return source.toSource(options.printOptions);
37+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /