Skip to content

Commit

Permalink
chore: lint run (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev authored Sep 24, 2024
1 parent 1e4022d commit 695ca39
Show file tree
Hide file tree
Showing 181 changed files with 4,818 additions and 3,266 deletions.
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"*.d.ts",
"*.js",
"dist",
"cdmd_dist",
"build",
"pnpm-lock.yaml",
"node_modules",
Expand Down Expand Up @@ -116,6 +117,7 @@
"input.js",
"output.js",
"dist",
"cdmd_dist",
"build",
"pnpm-lock.yaml",
"node_modules",
Expand All @@ -133,6 +135,7 @@
"ignore": [
"node_modules",
"dist",
"cdmd_dist",
"build",
".next",
".vscode",
Expand Down
6 changes: 2 additions & 4 deletions packages/codemods/ethers/v6/big-numbers/.codemodrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"private": false,
"arguments": [],
"meta": {
"tags": [
"ethers.js"
]
"tags": ["ethers.js"]
}
}
}
8 changes: 2 additions & 6 deletions packages/codemods/ethers/v6/big-numbers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
"test": "vitest run",
"test:watch": "vitest watch"
},
"files": [
"README.md",
".codemodrc.json",
"/dist/index.cjs"
],
"files": ["README.md", ".codemodrc.json", "/dist/index.cjs"],
"type": "module",
"author": "yugal41735"
}
}
80 changes: 44 additions & 36 deletions packages/codemods/ethers/v6/big-numbers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,53 @@ export default function transform(file, api) {
let dirtyFlag = false;

// Transform BigNumber.from('1000') to BigInt('1000')
root.find(j.CallExpression, {
callee: {
object: { name: 'BigNumber' },
property: { name: 'from' }
}
}).forEach(path => {
if (j.Literal.check(path.node.arguments[0])) {
path.replace(j.callExpression(j.identifier('BigInt'), [path.node.arguments[0]]));
dirtyFlag = true;
}
});
root
.find(j.CallExpression, {
callee: {
object: { name: "BigNumber" },
property: { name: "from" },
},
})
.forEach((path) => {
if (j.Literal.check(path.node.arguments[0])) {
path.replace(
j.callExpression(j.identifier("BigInt"), [path.node.arguments[0]]),
);
dirtyFlag = true;
}
});

// Transform value1.add(value2) to value1 + value2
root.find(j.CallExpression, {
callee: {
property: { name: 'add' }
}
}).forEach(path => {
const { object } = path.node.callee;
const args = path.node.arguments;
if (args && args.length === 1) {
path.replace(j.binaryExpression('+', object, args[0]));
dirtyFlag = true;
}
});
root
.find(j.CallExpression, {
callee: {
property: { name: "add" },
},
})
.forEach((path) => {
const { object } = path.node.callee;
const args = path.node.arguments;
if (args && args.length === 1) {
path.replace(j.binaryExpression("+", object, args[0]));
dirtyFlag = true;
}
});

// Transform value1.eq(value2) to value1 == value2
root.find(j.CallExpression, {
callee: {
property: { name: 'eq' }
}
}).forEach(path => {
const { object } = path.node.callee;
const args = path.node.arguments;
if (args && args.length === 1) {
path.replace(j.binaryExpression('==', object, args[0]));
dirtyFlag = true;
}
});
root
.find(j.CallExpression, {
callee: {
property: { name: "eq" },
},
})
.forEach((path) => {
const { object } = path.node.callee;
const args = path.node.arguments;
if (args && args.length === 1) {
path.replace(j.binaryExpression("==", object, args[0]));
dirtyFlag = true;
}
});

return dirtyFlag ? root.toSource() : undefined;
}
}
44 changes: 26 additions & 18 deletions packages/codemods/ethers/v6/big-numbers/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
import { describe, it } from 'vitest';
import jscodeshift, { type API } from 'jscodeshift';
import transform from '../src/index.js';
import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import assert from "node:assert";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import jscodeshift, { type API } from "jscodeshift";
import { describe, it } from "vitest";
import transform from "../src/index.js";

const buildApi = (parser: string | undefined): API => ({
j: parser ? jscodeshift.withParser(parser) : jscodeshift,
jscodeshift: parser ? jscodeshift.withParser(parser) : jscodeshift,
stats: () => {
console.error(
'The stats function was called, which is not supported on purpose',
"The stats function was called, which is not supported on purpose",
);
},
report: () => {
console.error(
'The report function was called, which is not supported on purpose',
"The report function was called, which is not supported on purpose",
);
},
});

describe('ethereumjs/1/big-number-to-big-int-and-operator-transformations', () => {
it('test #1', async () => {
const INPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture1.input.ts'), 'utf-8');
const OUTPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture1.output.ts'), 'utf-8');
describe("ethereumjs/1/big-number-to-big-int-and-operator-transformations", () => {
it("test #1", async () => {
const INPUT = await readFile(
join(__dirname, "..", "__testfixtures__/fixture1.input.ts"),
"utf-8",
);
const OUTPUT = await readFile(
join(__dirname, "..", "__testfixtures__/fixture1.output.ts"),
"utf-8",
);

const actualOutput = transform({
path: 'index.js',
const actualOutput = transform(
{
path: "index.js",
source: INPUT,
},
buildApi('tsx'), {}
buildApi("tsx"),
{},
);

assert.deepEqual(

Check failure on line 43 in packages/codemods/ethers/v6/big-numbers/test/test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest, true)

packages/codemods/ethers/v6/big-numbers/test/test.ts > ethereumjs/1/big-number-to-big-int-and-operator-transformations > test #1

AssertionError: Expected values to be loosely deep-equal: '// Using BigNumber in v5\n' + "value = BigInt('1000');\n" + '// Adding two values in v5\n' + 'sum = value1 + value2;\n' + '// Checking equality in v5\n' + 'isEqual = value1 == value2;' should loosely deep-equal '// Using BigInt in v6\n' + "value = BigInt('1000');\n" + '// Addition, keep in mind, both values must be a BigInt\n' + 'sum = value1 + value2;\n' + '// Checking Equality\n' + 'isEqual = value1 == value2;' - Expected + Received - // Using BigInt in v6 + // Using BigNumber in v5 value = BigInt('1000'); - // Addition, keep in mind, both values must be a BigInt + // Adding two values in v5 sum = value1 + value2; - // Checking Equality + // Checking equality in v5 isEqual = value1 == value2; ❯ packages/codemods/ethers/v6/big-numbers/test/test.ts:43:12
actualOutput?.replace(/W/gm, ''),
OUTPUT.replace(/W/gm, ''),
actualOutput?.replace(/W/gm, ""),
OUTPUT.replace(/W/gm, ""),
);
});
});
});
7 changes: 2 additions & 5 deletions packages/codemods/ethers/v6/big-numbers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"lib": [
"ESNext",
"DOM"
],
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"esModuleInterop": true,
"resolveJsonModule": true,
Expand Down Expand Up @@ -35,4 +32,4 @@
"ts-node": {
"transpileOnly": true
}
}
}
6 changes: 3 additions & 3 deletions packages/codemods/ethers/v6/big-numbers/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configDefaults, defineConfig } from 'vitest/config';
import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: [...configDefaults.include, '**/test/*.ts'],
include: [...configDefaults.include, "**/test/*.ts"],
},
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"private": false,
"arguments": [],
"meta": {
"tags": [
"ethers.js",
"Migration"
]
"tags": ["ethers.js", "Migration"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
"test": "vitest run",
"test:watch": "vitest watch"
},
"files": [
"README.md",
".codemodrc.json",
"/dist/index.cjs"
],
"files": ["README.md", ".codemodrc.json", "/dist/index.cjs"],
"type": "module",
"author": "yugal41735"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ export default function transform(file, api) {
let dirtyFlag = false;

// Find all call expressions
root.find(j.CallExpression).forEach(path => {
root.find(j.CallExpression).forEach((path) => {
const { callee, arguments: args } = path.node;

// Check if the callee is a member expression and the object is 'contract' and property is 'foo'
if (j.MemberExpression.check(callee) && j.Identifier.check(callee.object) && callee.object.name === 'contract' && j.Identifier.check(callee.property) && callee.property.name === 'foo') {
if (
j.MemberExpression.check(callee) &&
j.Identifier.check(callee.object) &&
callee.object.name === "contract" &&
j.Identifier.check(callee.property) &&
callee.property.name === "foo"
) {
// Wrap the first argument with Typed.address
if (args.length > 0) {
path.node.arguments[0] = j.callExpression(
j.memberExpression(j.identifier('Typed'), j.identifier('address')),
[args[0]]
j.memberExpression(j.identifier("Typed"), j.identifier("address")),
[args[0]],
);
dirtyFlag = true;
}
}
});

return dirtyFlag ? root.toSource() : undefined;
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
import { describe, it } from 'vitest';
import jscodeshift, { type API } from 'jscodeshift';
import transform from '../src/index.js';
import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import assert from "node:assert";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import jscodeshift, { type API } from "jscodeshift";
import { describe, it } from "vitest";
import transform from "../src/index.js";

const buildApi = (parser: string | undefined): API => ({
j: parser ? jscodeshift.withParser(parser) : jscodeshift,
jscodeshift: parser ? jscodeshift.withParser(parser) : jscodeshift,
stats: () => {
console.error(
'The stats function was called, which is not supported on purpose',
"The stats function was called, which is not supported on purpose",
);
},
report: () => {
console.error(
'The report function was called, which is not supported on purpose',
"The report function was called, which is not supported on purpose",
);
},
});

describe('contract-to-typed-address-wrapper', () => {
it('test #1', async () => {
const INPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture1.input.ts'), 'utf-8');
const OUTPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture1.output.ts'), 'utf-8');
describe("contract-to-typed-address-wrapper", () => {
it("test #1", async () => {
const INPUT = await readFile(
join(__dirname, "..", "__testfixtures__/fixture1.input.ts"),
"utf-8",
);
const OUTPUT = await readFile(
join(__dirname, "..", "__testfixtures__/fixture1.output.ts"),
"utf-8",
);

const actualOutput = transform({
path: 'index.js',
const actualOutput = transform(
{
path: "index.js",
source: INPUT,
},
buildApi('tsx'), {}
buildApi("tsx"),
{},
);

assert.deepEqual(
actualOutput?.replace(/W/gm, ''),
OUTPUT.replace(/W/gm, ''),
actualOutput?.replace(/W/gm, ""),
OUTPUT.replace(/W/gm, ""),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"lib": [
"ESNext",
"DOM"
],
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"esModuleInterop": true,
"resolveJsonModule": true,
Expand Down Expand Up @@ -35,4 +32,4 @@
"ts-node": {
"transpileOnly": true
}
}
}
Loading

0 comments on commit 695ca39

Please sign in to comment.