From 1bdcf8c60fbf832ca39dbff83382c7e39afaf882 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:34:48 -0400 Subject: [PATCH 1/9] refact: fix prefer-spread and prefer-rest-params eslint warnings --- eslint.config.mjs | 2 -- test/utils/helpers.ts | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 87f89c5e..e0552f96 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -21,8 +21,6 @@ export default [ "no-empty": "warn", "no-useless-escape": "warn", "prefer-const": "off", - "prefer-rest-params": "warn", - "prefer-spread": "warn", }, }, ]; diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index 1093e511..b61c48a1 100755 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -111,10 +111,10 @@ export function createTsProgram( /* Patch host to feed mock files */ const originalGetSourceFile: any = host.getSourceFile; - host.getSourceFile = function (fileName: string, scriptTarget: ts.ScriptTarget) { + host.getSourceFile = function (fileName: string, scriptTarget: ts.ScriptTarget, ...rest) { if (Object.keys(files).includes(fileName)) return tsInstance.createSourceFile(fileName, files[fileName], scriptTarget); - else originalGetSourceFile.apply(undefined, arguments); + else originalGetSourceFile(fileName, scriptTarget, ...rest); }; } From 07e86f155568d1f90413b9daa231a8adc47bc294 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:36:19 -0400 Subject: [PATCH 2/9] refact: fix no-useless-escape eslint warning --- eslint.config.mjs | 1 - test/tests/transformer/specific.test.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e0552f96..1968b81e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -19,7 +19,6 @@ export default [ "@typescript-eslint/no-unused-vars": "warn", "no-case-declarations": "warn", "no-empty": "warn", - "no-useless-escape": "warn", "prefer-const": "off", }, }, diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts index 36960035..c5b90d90 100755 --- a/test/tests/transformer/specific.test.ts +++ b/test/tests/transformer/specific.test.ts @@ -159,7 +159,7 @@ describe(`Specific Tests`, () => { describe(`Tags`, () => { test(`(@no-transform-path) Doesn't transform path`, () => { for (let i = 1; i <= 4; i++) - expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`); + expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root/index`); }); test(`(@transform-path) Transforms path with explicit value`, () => { From e5a417635ca21e9ec9ec8e09f84ab7a7e84bd623 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:37:44 -0400 Subject: [PATCH 3/9] refact: fix no-case-declarations eslint warning --- eslint.config.mjs | 1 - test/tests/transformer/specific.test.ts | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 1968b81e..47c701f5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -17,7 +17,6 @@ export default [ "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-unsafe-function-type": "warn", "@typescript-eslint/no-unused-vars": "warn", - "no-case-declarations": "warn", "no-empty": "warn", "prefer-const": "off", }, diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts index c5b90d90..8f8aab0e 100755 --- a/test/tests/transformer/specific.test.ts +++ b/test/tests/transformer/specific.test.ts @@ -60,7 +60,7 @@ describe(`Specific Tests`, () => { beforeAll(() => { switch (mode) { - case "program": + case "program": { const program = createTsProgram({ tsInstance, tsConfigFile, @@ -81,6 +81,7 @@ describe(`Specific Tests`, () => { }); rootDirsEmit = getEmitResultFromProgram(rootDirsProgram); break; + } case "manual": { skipDts = true; const pcl = tsInstance.getParsedCommandLineOfConfigFile( From d5b5945f4f27bcf173069406a0b62eaf477f93e2 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:39:51 -0400 Subject: [PATCH 4/9] refact: fix no-unsafe-function-type eslint warning --- eslint.config.mjs | 1 - test/utils/helpers.ts | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 47c701f5..8e5d25d3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,7 +15,6 @@ export default [ "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], "@typescript-eslint/no-require-imports": "off", - "@typescript-eslint/no-unsafe-function-type": "warn", "@typescript-eslint/no-unused-vars": "warn", "no-empty": "warn", "prefer-const": "off", diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index b61c48a1..9fe02ffc 100755 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -41,7 +41,10 @@ function createWriteFile(outputFiles: EmittedFiles) { }; } -function createReadFile(outputFiles: EmittedFiles, originalReadFile: Function) { +function createReadFile( + outputFiles: EmittedFiles, + originalReadFile: (path: string, encoding?: string) => string | undefined, +) { return (fileName: string) => { let { 1: rootName, 2: ext } = fileName.match(/(.+)\.((d.ts)|(js))$/) ?? []; if (ext) { From 6b5e467b2e0adb080d2552e4fe0dcda5ff49597a Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:41:10 -0400 Subject: [PATCH 5/9] refact: fix ban-ts-comment eslint warning --- eslint.config.mjs | 1 - src/harmony/versions/three-eight.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 8e5d25d3..7f736312 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -10,7 +10,6 @@ export default [ ...tseslint.configs.recommended, { rules: { - "@typescript-eslint/ban-ts-comment": "warn", "@typescript-eslint/no-empty-object-type": "warn", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], diff --git a/src/harmony/versions/three-eight.ts b/src/harmony/versions/three-eight.ts index 9684bb75..10588503 100644 --- a/src/harmony/versions/three-eight.ts +++ b/src/harmony/versions/three-eight.ts @@ -108,7 +108,7 @@ export function handler(context: TsTransformPathsContext, prop: string | symbol) dsNode.modifiers, dsExportClause, dsModuleSpecifier, - // @ts-ignore - This was added in later versions of 3.x + // @ts-expect-error - This was added in later versions of 3.x dsNode.isTypeOnly, ); }; From 288b7ceb9445e4f06b308df260004b1d39f12c1e Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:43:01 -0400 Subject: [PATCH 6/9] refact: adjust no-empty-object-type eslint warning --- eslint.config.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 7f736312..5a5058a5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -10,7 +10,7 @@ export default [ ...tseslint.configs.recommended, { rules: { - "@typescript-eslint/no-empty-object-type": "warn", + "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }], "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], "@typescript-eslint/no-require-imports": "off", From d119f4e94e61c9afa5872ae6c246ecc653eadb91 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:43:38 -0400 Subject: [PATCH 7/9] chore: separate rules modifications from disabled rules --- eslint.config.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 5a5058a5..01bc45a0 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -11,8 +11,12 @@ export default [ { rules: { "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }], - "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], + }, + }, + { + rules: { + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-unused-vars": "warn", "no-empty": "warn", From 7b5b808e1302b52e4c08ba35c2688e1604e9aa6f Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 11:45:18 -0400 Subject: [PATCH 8/9] refact: fix prefer-const eslint warning --- eslint.config.mjs | 2 +- src/register.ts | 2 +- src/transformer.ts | 4 ++-- src/utils/resolve-module-name.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 01bc45a0..5c933de5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -12,6 +12,7 @@ export default [ rules: { "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }], "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], + "prefer-const": ["error", { destructuring: "all" }], }, }, { @@ -20,7 +21,6 @@ export default [ "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-unused-vars": "warn", "no-empty": "warn", - "prefer-const": "off", }, }, ]; diff --git a/src/register.ts b/src/register.ts index f683f9ea..d951da8a 100755 --- a/src/register.ts +++ b/src/register.ts @@ -68,7 +68,7 @@ export function register(): TSNode.RegisterOptions | undefined { const registerOptions: TSNode.RegisterOptions = Object.assign({}, tsNodeInstance.options); if (registerOptions.transformers) { if (typeof registerOptions.transformers === "function") { - let oldTransformersFactory = registerOptions.transformers; + const oldTransformersFactory = registerOptions.transformers; registerOptions.transformers = (program) => { const transformers = getTransformers(program, beforeConfig, afterDeclarationsConfig); const baseTransformers = oldTransformersFactory(program); diff --git a/src/transformer.ts b/src/transformer.ts index 03fc6115..2c6ff890 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -12,7 +12,6 @@ import { TransformerExtras } from "ts-patch"; /* ****************************************************************************************************************** */ function getTsProperties(args: Parameters) { - let tsInstance: typeof ts; let fileNames: readonly string[] | undefined; let compilerOptions: CompilerOptions; let runMode: RunMode; @@ -20,7 +19,8 @@ function getTsProperties(args: Parameters) { const { 0: program, 2: extras, 3: manualTransformOptions } = args; - tsInstance = extras?.ts ?? ts; + const tsInstance = extras?.ts ?? ts; + if (program) compilerOptions = program.getCompilerOptions(); const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts index ba0e3b59..c49ed9bd 100755 --- a/src/utils/resolve-module-name.ts +++ b/src/utils/resolve-module-name.ts @@ -38,7 +38,7 @@ enum IndexType { /* ****************************************************************************************************************** */ function getPathDetail(moduleName: string, resolvedModule: ResolvedModuleFull) { - let resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName; + const resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName; const implicitPackageIndex = resolvedModule.packageId?.subModuleName; const resolvedDir = implicitPackageIndex From d997a25459e4ad637bc95bdaa7619a9d2c498361 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Thu, 8 Aug 2024 12:01:34 -0400 Subject: [PATCH 9/9] refact: adjust no-empty eslint warning --- eslint.config.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 5c933de5..daaf9f61 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -12,6 +12,7 @@ export default [ rules: { "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }], "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], + "no-empty": ["error", { allowEmptyCatch: true }], "prefer-const": ["error", { destructuring: "all" }], }, }, @@ -20,7 +21,6 @@ export default [ "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-unused-vars": "warn", - "no-empty": "warn", }, }, ];