From 404b6a3f1f4612a651d33992949141b3d39fa366 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Fri, 28 Feb 2025 21:26:38 +0800 Subject: [PATCH 1/3] update synvert-core to 2.24.0 --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index d894fbc..ad4d933 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "license": "ISC", "devDependencies": { - "@synvert-hq/synvert-core": "^2.23.0", + "@synvert-hq/synvert-core": "^2.24.0", "jest": "^27.0.6", "mock-fs": "^5.4.0" } @@ -956,9 +956,9 @@ } }, "node_modules/@synvert-hq/synvert-core": { - "version": "2.23.0", - "resolved": "https://registry.npmjs.org/@synvert-hq/synvert-core/-/synvert-core-2.23.0.tgz", - "integrity": "sha512-6jv3cuGuYSOwAfNn0u6nDWe/h4uF4UdrsqHKXnyaxflh9IMEs/jqzWRMc5Nh9W7HKwal3exH6u5wzmVuzyUgOw==", + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/@synvert-hq/synvert-core/-/synvert-core-2.24.0.tgz", + "integrity": "sha512-Wyi1+bKAMLoEUCO0It0QqPpY5WkR5zc05UQ5BHoJ0gUXr03drPtfvXMVQH7JDUWtjl64doibKqR3VuxhjlzogQ==", "dev": true, "license": "ISC", "dependencies": { @@ -5042,9 +5042,9 @@ } }, "@synvert-hq/synvert-core": { - "version": "2.23.0", - "resolved": "https://registry.npmjs.org/@synvert-hq/synvert-core/-/synvert-core-2.23.0.tgz", - "integrity": "sha512-6jv3cuGuYSOwAfNn0u6nDWe/h4uF4UdrsqHKXnyaxflh9IMEs/jqzWRMc5Nh9W7HKwal3exH6u5wzmVuzyUgOw==", + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/@synvert-hq/synvert-core/-/synvert-core-2.24.0.tgz", + "integrity": "sha512-Wyi1+bKAMLoEUCO0It0QqPpY5WkR5zc05UQ5BHoJ0gUXr03drPtfvXMVQH7JDUWtjl64doibKqR3VuxhjlzogQ==", "dev": true, "requires": { "@synvert-hq/espree": "^10.0.1", diff --git a/package.json b/package.json index aad9f59..9989ef1 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "homepage": "https://github.com/synvert-hq/synvert-snippets-javascript#readme", "devDependencies": { - "@synvert-hq/synvert-core": "^2.23.0", + "@synvert-hq/synvert-core": "^2.24.0", "jest": "^27.0.6", "mock-fs": "^5.4.0" } From 25a72c882ae5cce5e742d3da78bcebaa84f70fa4 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Tue, 4 Mar 2025 17:01:39 +0800 Subject: [PATCH 2/3] test real file system --- .github/workflows/main.yml | 6 +- .gitignore | 1 + test/bun/convert-jest-to-bun.spec.js | 9 +- test/javascript/no-unused-imports.spec.js | 13 +- .../javascript/no-useless-constructor.spec.js | 1 - .../prefer-class-properties.spec.js | 4 +- test/react/add-autocomplete-attribute.spec.js | 3 - test/react/import-named-component.spec.js | 4 +- test/react/import-prop-types.spec.js | 4 - test/react/prefer-class-properties.spec.js | 2 - .../react/remove-unused-react-imports.spec.js | 2 - test/react/short-syntax-fragment.spec.js | 6 - ...form-class-components-to-functions.spec.js | 12 -- test/react/upgrade-to-18.spec.js | 2 +- test/sass/convert-to-scss.spec.js | 4 +- test/scss/convert-to-sass.spec.js | 4 +- test/typescript/array-type.spec.js | 1 - test/utils.js | 115 ++++++++---------- 18 files changed, 67 insertions(+), 126 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 023d667..84d778d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,10 @@ name: CI on: push: - branches: - - main + branches: [ main ] + pull_request: + branches: [ main ] + jobs: build: name: test diff --git a/.gitignore b/.gitignore index 76efb07..7737e08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +tmp .vscode diff --git a/test/bun/convert-jest-to-bun.spec.js b/test/bun/convert-jest-to-bun.spec.js index d6ee63f..abacbaf 100644 --- a/test/bun/convert-jest-to-bun.spec.js +++ b/test/bun/convert-jest-to-bun.spec.js @@ -12,11 +12,10 @@ describe(snippet, () => { `; assertConvert({ - path: "test/foobar.spec.js", + path: "test/bun/convert-jest-to-bun.spec.js", input, output, snippet, - helpers: ["helpers/add-import"], }); }); @@ -39,11 +38,10 @@ describe(snippet, () => { `; assertConvert({ - path: "test/foobar.spec.js", + path: "test/bun/convert-jest-to-bun.spec.js", input, output, snippet, - helpers: ["helpers/add-import"], }); }); @@ -66,11 +64,10 @@ describe(snippet, () => { `; assertConvert({ - path: "test/foobar.spec.js", + path: "test/bun/convert-jest-to-bun.spec.js", input, output, snippet, - helpers: ["helpers/add-import"], }); }); }); diff --git a/test/javascript/no-unused-imports.spec.js b/test/javascript/no-unused-imports.spec.js index 7599afb..56f99d9 100644 --- a/test/javascript/no-unused-imports.spec.js +++ b/test/javascript/no-unused-imports.spec.js @@ -17,7 +17,6 @@ describe(snippet, () => { const c = a() + b + x() + y(); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -36,7 +35,6 @@ describe(snippet, () => { const c = b(x, y); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -59,7 +57,6 @@ describe(snippet, () => { const c = a(y); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -77,7 +74,6 @@ describe(snippet, () => { console.log(y); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -92,7 +88,6 @@ describe(snippet, () => { console.log(c); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -108,7 +103,6 @@ describe(snippet, () => { const c = a() + b; `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -123,7 +117,6 @@ describe(snippet, () => { const c = a() + b; `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -138,7 +131,6 @@ describe(snippet, () => { p.test(); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -152,7 +144,6 @@ describe(snippet, () => { console.log("p"); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -167,7 +158,6 @@ describe(snippet, () => { console.log(y); `, snippet, - helpers: ["helpers/remove-imports"], }); }); @@ -194,8 +184,7 @@ describe(snippet, () => { } `, snippet, - helpers: ["helpers/remove-imports"], - path: "code.jsx", + path: "javascript/no-unused-imports.jsx", }); }); }); diff --git a/test/javascript/no-useless-constructor.spec.js b/test/javascript/no-useless-constructor.spec.js index 93313cf..958ea2c 100644 --- a/test/javascript/no-useless-constructor.spec.js +++ b/test/javascript/no-useless-constructor.spec.js @@ -36,6 +36,5 @@ describe(snippet, () => { input, output, snippet, - path: "code.js", }); }); diff --git a/test/javascript/prefer-class-properties.spec.js b/test/javascript/prefer-class-properties.spec.js index a139494..0809718 100644 --- a/test/javascript/prefer-class-properties.spec.js +++ b/test/javascript/prefer-class-properties.spec.js @@ -65,7 +65,7 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", + path: "javascript/prefer-class-properties.jsx", }); }); @@ -99,7 +99,7 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", + path: "javascript/prefer-class-properties.jsx", }); }); }); diff --git a/test/react/add-autocomplete-attribute.spec.js b/test/react/add-autocomplete-attribute.spec.js index 41ba18a..0ad7605 100644 --- a/test/react/add-autocomplete-attribute.spec.js +++ b/test/react/add-autocomplete-attribute.spec.js @@ -17,7 +17,6 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", }); }); @@ -38,7 +37,6 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", }); }); @@ -71,7 +69,6 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", }); }); }); diff --git a/test/react/import-named-component.spec.js b/test/react/import-named-component.spec.js index b43bdd1..7f15b00 100644 --- a/test/react/import-named-component.spec.js +++ b/test/react/import-named-component.spec.js @@ -21,7 +21,7 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", + path: "react/import-named-component.jsx", }); }); @@ -44,7 +44,7 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", + path: "react/import-named-component.jsx", }); }); }); diff --git a/test/react/import-prop-types.spec.js b/test/react/import-prop-types.spec.js index a10fb84..8368e4a 100644 --- a/test/react/import-prop-types.spec.js +++ b/test/react/import-prop-types.spec.js @@ -16,8 +16,6 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", - helpers: ["helpers/add-import", "helpers/remove-imports"], }); }); @@ -35,8 +33,6 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", - helpers: ["helpers/add-import", "helpers/remove-imports"], }); }); }); diff --git a/test/react/prefer-class-properties.spec.js b/test/react/prefer-class-properties.spec.js index 2f32286..9367f43 100644 --- a/test/react/prefer-class-properties.spec.js +++ b/test/react/prefer-class-properties.spec.js @@ -69,7 +69,5 @@ describe(snippet, () => { input, output, snippet, - subSnippets: ["javascript/no-useless-constructor"], - path: "code.jsx", }); }); diff --git a/test/react/remove-unused-react-imports.spec.js b/test/react/remove-unused-react-imports.spec.js index fe17a6b..90be8d6 100644 --- a/test/react/remove-unused-react-imports.spec.js +++ b/test/react/remove-unused-react-imports.spec.js @@ -20,7 +20,5 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports"], - path: "code.jsx", }); }); diff --git a/test/react/short-syntax-fragment.spec.js b/test/react/short-syntax-fragment.spec.js index c24409a..cdd4b08 100644 --- a/test/react/short-syntax-fragment.spec.js +++ b/test/react/short-syntax-fragment.spec.js @@ -33,8 +33,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports"], - path: "code.jsx", }); }); @@ -69,8 +67,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports"], - path: "code.jsx", }); }); @@ -105,8 +101,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports"], - path: "code.jsx", }); }); }); diff --git a/test/react/transform-class-components-to-functions.spec.js b/test/react/transform-class-components-to-functions.spec.js index ef34c70..f5181e7 100644 --- a/test/react/transform-class-components-to-functions.spec.js +++ b/test/react/transform-class-components-to-functions.spec.js @@ -23,8 +23,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports", "helpers/add-import"], - path: "code.jsx", }); }); @@ -49,8 +47,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports", "helpers/add-import"], - path: "code.jsx", }); }); @@ -84,8 +80,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports", "helpers/add-import"], - path: "code.jsx", }); }); @@ -123,8 +117,6 @@ describe(snippet, () => { assertConvert({ input, output, - path: "code.jsx", - helpers: ["helpers/remove-imports", "helpers/add-import"], snippet: "react/transform-class-components-to-functions", }); }); @@ -161,8 +153,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports", "helpers/add-import"], - path: "code.jsx", }); }); @@ -206,8 +196,6 @@ describe(snippet, () => { input, output, snippet, - helpers: ["helpers/remove-imports", "helpers/add-import"], - path: "code.jsx", }); }); }); diff --git a/test/react/upgrade-to-18.spec.js b/test/react/upgrade-to-18.spec.js index eca0f8f..5820d18 100644 --- a/test/react/upgrade-to-18.spec.js +++ b/test/react/upgrade-to-18.spec.js @@ -17,6 +17,6 @@ describe(snippet, () => { input, output, snippet, - path: "code.jsx", + path: "react/upgrade-to-18.jsx", }); }); diff --git a/test/sass/convert-to-scss.spec.js b/test/sass/convert-to-scss.spec.js index decbb36..ac71aed 100644 --- a/test/sass/convert-to-scss.spec.js +++ b/test/sass/convert-to-scss.spec.js @@ -33,10 +33,10 @@ describe(snippet, () => { `; assertConvert({ - path: "code.sass", + path: "sass/convert-to-scss.sass", input, output, snippet, - newPath: "code.scss", + newPath: "sass/convert-to-scss.scss", }); }); diff --git a/test/scss/convert-to-sass.spec.js b/test/scss/convert-to-sass.spec.js index 6b4bdaa..c7bbb25 100644 --- a/test/scss/convert-to-sass.spec.js +++ b/test/scss/convert-to-sass.spec.js @@ -36,10 +36,10 @@ describe(snippet, () => { `; assertConvert({ - path: "code.scss", + path: "scss/convert-to-sass.scss", input, output, snippet, - newPath: "code.sass", + newPath: "scss/convert-to-sass.sass", }); }); diff --git a/test/typescript/array-type.spec.js b/test/typescript/array-type.spec.js index 4c7d93b..20dc72d 100644 --- a/test/typescript/array-type.spec.js +++ b/test/typescript/array-type.spec.js @@ -15,7 +15,6 @@ describe(snippet, () => { `; assertConvert({ - path: "code.ts", input, output, snippet, diff --git a/test/utils.js b/test/utils.js index 265a1fd..5300276 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,118 +1,105 @@ const fs = require("fs"); const promisesFs = require("fs/promises"); const path = require("path"); -const mock = require("mock-fs"); const Synvert = require("@synvert-hq/synvert-core"); process.env.SYNVERT_SNIPPETS_HOME = path.join(__dirname, ".."); -const SYNVERT_CODE_HOME = path.join(__dirname, "..", "src"); +const SYNVERT_CODE_HOME = path.join(__dirname, "..", "tmp"); Synvert.Configuration.rootPath = SYNVERT_CODE_HOME.toString(); +Synvert.Configuration.respectGitignore = false; -const otherSnippetsMockSync = (options) => { - const mocks = {}; - if (options) { - options.forEach((option) => { - const libraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", option + ".js"); - const content = fs.readFileSync(libraryPath, "utf-8"); - mocks[libraryPath] = content; - }); +const getCodePath = (options) => { + if (options.path) { + return path.join(SYNVERT_CODE_HOME, options.path); } - return mocks; -}; -const otherSnippetsMock = async (options) => { - const mocks = {}; - if (options) { - for await (const option of options) { - const libraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", option + ".js"); - const content = await promisesFs.readFile(libraryPath, "utf-8"); - mocks[libraryPath] = content; - } + switch (options.snippet.split("/")[0]) { + case "scss": + return path.join(SYNVERT_CODE_HOME, options.snippet + '.scss'); + case "sass": + return path.join(SYNVERT_CODE_HOME, options.snippet + '.sass'); + case "css": + return path.join(SYNVERT_CODE_HOME, options.snippet + '.css'); + case "typescript": + return path.join(SYNVERT_CODE_HOME, options.snippet + '.ts'); + case "react": + return path.join(SYNVERT_CODE_HOME, options.snippet + '.jsx'); + default: + return path.join(SYNVERT_CODE_HOME, options.snippet + '.js'); } - return mocks; -}; +} + +const getNewCodePath = (options) => { + if (options.newPath) { + return path.join(SYNVERT_CODE_HOME, options.newPath); + } + + return getCodePath(options); +} const assertConvert = (options) => { - const snippetPath = path.join(SYNVERT_CODE_HOME, options.path || "code.js"); + const codePath = getCodePath(options); const { input, output } = options; if (process.env.SYNC === "true") { beforeEach(() => { - const libraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", options.snippet + ".js"); - const libraryContent = fs.readFileSync(libraryPath, "utf-8"); - mock({ - [libraryPath]: libraryContent, - [snippetPath]: input, - ...otherSnippetsMockSync(options.helpers), - ...otherSnippetsMockSync(options.subSnippets), - }); + fs.mkdirSync(path.dirname(codePath), { recursive: true }); + fs.writeFileSync(codePath, input); }); afterEach(() => { - mock.restore(); + fs.unlinkSync(getNewCodePath(options)); }); test("convert", () => { - const libraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", options.snippet + ".js"); - const rewriter = Synvert.evalSnippetSync(libraryPath); + const rewriter = Synvert.evalSnippetSync(options.snippet); rewriter.processSync(); if (options.newPath) { expect(fs.readFileSync(path.join(SYNVERT_CODE_HOME, options.newPath), "utf-8")).toEqual(output); } else { - expect(fs.readFileSync(snippetPath, "utf-8")).toEqual(output); + expect(fs.readFileSync(codePath, "utf-8")).toEqual(output); } }); } else { beforeEach(async () => { - const libraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", options.snippet + ".js"); - const libraryContent = await promisesFs.readFile(libraryPath, "utf-8"); - mock({ - [libraryPath]: libraryContent, - [snippetPath]: input, - ...(await otherSnippetsMock(options.helpers)), - ...(await otherSnippetsMock(options.subSnippets)), - }); + await promisesFs.mkdir(path.dirname(codePath), { recursive: true }); + await promisesFs.writeFile(codePath, input); }); - afterEach(() => { - mock.restore(); + afterEach(async () => { + await promisesFs.unlink(getNewCodePath(options)); }); test("convert", async () => { - const libraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", options.snippet + ".js"); - const rewriter = await Synvert.evalSnippet(libraryPath); + const rewriter = await Synvert.evalSnippet(options.snippet); await rewriter.process(); if (options.newPath) { expect(await promisesFs.readFile(path.join(SYNVERT_CODE_HOME, options.newPath), "utf-8")).toEqual(output); } else { - expect(await promisesFs.readFile(snippetPath, "utf-8")).toEqual(output); + expect(await promisesFs.readFile(codePath, "utf-8")).toEqual(output); } }); } }; const assertHelper = (options) => { - const helperPath = path.join(SYNVERT_CODE_HOME, options.path || "code.js"); + const helperPath = path.join(SYNVERT_CODE_HOME, options.helper + '.js'); const { input, output } = options; if (process.env.SYNC === "true") { beforeEach(() => { - const helperLibraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", options.helper + ".js"); - const helperContent = fs.readFileSync(helperLibraryPath, "utf-8"); - mock({ - [helperLibraryPath]: helperContent, - [helperPath]: input, - }); + fs.mkdirSync(path.dirname(helperPath), { recursive: true }); + fs.writeFileSync(helperPath, input); }); afterEach(() => { - mock.restore(); + fs.unlinkSync(helperPath); }); test("convert", () => { const rewriter = new Synvert.Rewriter("group", "name", function () { this.configure({ parser: Synvert.Parser.TYPESCRIPT }); - this.withinFilesSync("*.{js,jsx}", function () { + this.withinFilesSync(Synvert.ALL_FILES, function () { this.callHelperSync(options.helper, options.options); }); }); @@ -121,22 +108,18 @@ const assertHelper = (options) => { }); } else { beforeEach(async () => { - const helperLibraryPath = path.join(process.env.SYNVERT_SNIPPETS_HOME, "lib", options.helper + ".js"); - const helperContent = await promisesFs.readFile(helperLibraryPath, "utf-8"); - mock({ - [helperLibraryPath]: helperContent, - [helperPath]: input, - }); + await promisesFs.mkdir(path.dirname(helperPath), { recursive: true }); + await promisesFs.writeFile(helperPath, input); }); - afterEach(() => { - mock.restore(); + afterEach(async () => { + await promisesFs.unlink(helperPath); }); test("convert", async () => { const rewriter = new Synvert.Rewriter("group", "name", async function () { this.configure({ parser: Synvert.Parser.TYPESCRIPT }); - await this.withinFiles("*.{js,jsx}", async function () { + await this.withinFiles(Synvert.ALL_FILES, async function () { await this.callHelper(options.helper, options.options); }); }); From c7246ccfa99e70d527c40b50857f08a21e85628c Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Sat, 8 Mar 2025 19:01:22 +0800 Subject: [PATCH 3/3] use for of to iterate --- lib/javascript/prefer-class-properties.js | 8 ++++---- lib/react/prefer-class-properties.js | 8 ++++---- lib/react/transform-class-components-to-functions.js | 8 ++++---- test/javascript/prefer-class-properties.spec.js | 2 -- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/javascript/prefer-class-properties.js b/lib/javascript/prefer-class-properties.js index 91d0e70..e1a4207 100644 --- a/lib/javascript/prefer-class-properties.js +++ b/lib/javascript/prefer-class-properties.js @@ -84,7 +84,7 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () { }, ); - functions.forEach((func) => { + for (const func of functions) { const source = indentCode( `${this.mutationAdapter.getSource(func.left.name)} = ${this.mutationAdapter.getSource(func.right, { fixIndent: true, @@ -92,9 +92,9 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () { tabSize, ); insert(`\n\n${source.replace(/function ?/, "").replace(/\) {/, ") => {")}`, { at: "end" }); - }); + } - arrowFunctions.forEach((arrowFunction) => { + for (const arrowFunction of arrowFunctions) { const source = indentCode( `${this.mutationAdapter.getSource(arrowFunction.left.name)} = ${this.mutationAdapter.getSource( arrowFunction.right, @@ -103,7 +103,7 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () { tabSize, ); insert(`\n\n${source}`, { at: "end" }); - }); + } }); // handleChange() {} diff --git a/lib/react/prefer-class-properties.js b/lib/react/prefer-class-properties.js index 6431181..12e9992 100644 --- a/lib/react/prefer-class-properties.js +++ b/lib/react/prefer-class-properties.js @@ -99,7 +99,7 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => { }, ); - functions.forEach((func) => { + for (const func of functions) { const source = indentCode( `${this.mutationAdapter.getSource(func.left.name)} = ${this.mutationAdapter.getSource(func.right, { fixIndent: true, @@ -107,9 +107,9 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => { tabSize, ); insert(`\n\n${source.replace(/function ?/, "").replace(/\) {/, ") => {")}`, { at: "end" }); - }); + } - arrowFunctions.forEach((arrowFunction) => { + for (const arrowFunction of arrowFunctions) { const source = indentCode( `${this.mutationAdapter.getSource(arrowFunction.left.name)} = ${this.mutationAdapter.getSource( arrowFunction.right, @@ -118,7 +118,7 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => { tabSize, ); insert(`\n\n${source}`, { at: "end" }); - }); + } }); // handleChange() {} diff --git a/lib/react/transform-class-components-to-functions.js b/lib/react/transform-class-components-to-functions.js index da318b8..9ac4fae 100644 --- a/lib/react/transform-class-components-to-functions.js +++ b/lib/react/transform-class-components-to-functions.js @@ -55,7 +55,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => { // state = { key: value }; findNode(".PropertyDeclaration[name=state]", () => { - this.currentNode.initializer.properties.forEach((property) => { + for (const property of this.currentNode.initializer.properties) { const name = property.name.escapedText; const value = this.mutationAdapter.getSource(property.initializer); functionBody.push( @@ -64,7 +64,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => { 1, ), ); - }); + } }); // foo = () => {} @@ -84,7 +84,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => { if (lifecycleMethods.length > 0) { functionBody.push(addLeadingSpaces("// Synvert TODO: convert lifecycle methods to useEffect by yourself")); setUseEffect(currentFilePath); - lifecycleMethods.forEach((lifecycleMethod) => { + for (const lifecycleMethod of lifecycleMethods) { const lines = this.mutationAdapter.getSource(lifecycleMethod, { fixIndent: true }).split("\n"); functionBody.push( indentCode( @@ -92,7 +92,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => { 1, ), ); - }); + } } // render() {} diff --git a/test/javascript/prefer-class-properties.spec.js b/test/javascript/prefer-class-properties.spec.js index 0809718..eb739ea 100644 --- a/test/javascript/prefer-class-properties.spec.js +++ b/test/javascript/prefer-class-properties.spec.js @@ -65,7 +65,6 @@ describe(snippet, () => { input, output, snippet, - path: "javascript/prefer-class-properties.jsx", }); }); @@ -99,7 +98,6 @@ describe(snippet, () => { input, output, snippet, - path: "javascript/prefer-class-properties.jsx", }); }); });