From 06b0e9f9e88b2a27676ef21d833dea35e95e7e13 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 6 Oct 2025 18:55:15 +0000 Subject: [PATCH] refactor(linter/plugins): convert generated files to TS (#14385) Pure refactor. Generated files `constants.js` and `type_ids.js` are JS files, but they only define `const`s, so are also valid TS, without adding any type annotations. So rename them to `.ts` to allow TS to infer the types of their exports. --- .github/generated/ast_changes_watch_list.yml | 4 ++-- .../src-js/generated/{constants.js => constants.ts} | 0 .../src-js/generated/{type_ids.js => type_ids.ts} | 0 apps/oxlint/src-js/plugins/lint.ts | 2 -- apps/oxlint/src-js/plugins/source_code.ts | 10 +++------- apps/oxlint/src-js/plugins/visitor.ts | 2 -- apps/oxlint/test/compile-visitor.test.ts | 2 -- tasks/ast_tools/src/generators/estree_visit.rs | 3 ++- tasks/ast_tools/src/generators/raw_transfer.rs | 3 ++- 9 files changed, 9 insertions(+), 17 deletions(-) rename apps/oxlint/src-js/generated/{constants.js => constants.ts} (100%) rename apps/oxlint/src-js/generated/{type_ids.js => type_ids.ts} (100%) diff --git a/.github/generated/ast_changes_watch_list.yml b/.github/generated/ast_changes_watch_list.yml index e008e875f78a7..73b1083625d71 100644 --- a/.github/generated/ast_changes_watch_list.yml +++ b/.github/generated/ast_changes_watch_list.yml @@ -3,10 +3,10 @@ src: - '.github/generated/ast_changes_watch_list.yml' - - 'apps/oxlint/src-js/generated/constants.js' + - 'apps/oxlint/src-js/generated/constants.ts' - 'apps/oxlint/src-js/generated/deserialize.js' - 'apps/oxlint/src-js/generated/keys.js' - - 'apps/oxlint/src-js/generated/type_ids.js' + - 'apps/oxlint/src-js/generated/type_ids.ts' - 'apps/oxlint/src-js/generated/types.d.ts' - 'apps/oxlint/src-js/generated/visitor.d.ts' - 'apps/oxlint/src-js/generated/walk.js' diff --git a/apps/oxlint/src-js/generated/constants.js b/apps/oxlint/src-js/generated/constants.ts similarity index 100% rename from apps/oxlint/src-js/generated/constants.js rename to apps/oxlint/src-js/generated/constants.ts diff --git a/apps/oxlint/src-js/generated/type_ids.js b/apps/oxlint/src-js/generated/type_ids.ts similarity index 100% rename from apps/oxlint/src-js/generated/type_ids.js rename to apps/oxlint/src-js/generated/type_ids.ts diff --git a/apps/oxlint/src-js/plugins/lint.ts b/apps/oxlint/src-js/plugins/lint.ts index 184b8b98719bb..36ef7df042618 100644 --- a/apps/oxlint/src-js/plugins/lint.ts +++ b/apps/oxlint/src-js/plugins/lint.ts @@ -6,9 +6,7 @@ import { addVisitorToCompiled, compiledVisitor, finalizeCompiledVisitor, initCom // Lazy implementation /* -// @ts-expect-error we need to generate `.d.ts` file for this module. import { TOKEN } from '../../dist/src-js/raw-transfer/lazy-common.js'; -// @ts-expect-error we need to generate `.d.ts` file for this module. import { walkProgram } from '../generated/walk.js'; */ diff --git a/apps/oxlint/src-js/plugins/source_code.ts b/apps/oxlint/src-js/plugins/source_code.ts index 1001f8f8c9e94..0ffad9f119899 100644 --- a/apps/oxlint/src-js/plugins/source_code.ts +++ b/apps/oxlint/src-js/plugins/source_code.ts @@ -1,13 +1,9 @@ import { createRequire } from 'node:module'; -import { - DATA_POINTER_POS_32, - SOURCE_LEN_OFFSET, - // TODO(camc314): we need to generate `.d.ts` file for this module. - // @ts-expect-error -} from '../generated/constants.js'; -// @ts-expect-error we need to generate `.d.ts` file for this module +import { DATA_POINTER_POS_32, SOURCE_LEN_OFFSET } from '../generated/constants.js'; + // We use the deserializer which removes `ParenthesizedExpression`s from AST, // and with `range`, `loc`, and `parent` properties on AST nodes, to match ESLint +// @ts-expect-error we need to generate `.d.ts` file for this module import { deserializeProgramOnly } from '../../dist/generated/deserialize.js'; import { diff --git a/apps/oxlint/src-js/plugins/visitor.ts b/apps/oxlint/src-js/plugins/visitor.ts index 93b2bd35ab21d..1db4a26d067ce 100644 --- a/apps/oxlint/src-js/plugins/visitor.ts +++ b/apps/oxlint/src-js/plugins/visitor.ts @@ -72,8 +72,6 @@ // for objects created by user code in visitors. If ephemeral user-created objects all fit in new space, // it will avoid full GC runs, which should greatly improve performance. -// TODO(camc314): we need to generate `.d.ts` file for this module. -// @ts-expect-error import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../generated/type_ids.js'; import { assertIs } from './utils.js'; diff --git a/apps/oxlint/test/compile-visitor.test.ts b/apps/oxlint/test/compile-visitor.test.ts index 46600a5b2619f..f6bdb9be0e58a 100644 --- a/apps/oxlint/test/compile-visitor.test.ts +++ b/apps/oxlint/test/compile-visitor.test.ts @@ -1,6 +1,4 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -// TODO(camc314): we need to generate `.d.ts` file for this module -// @ts-expect-error import { NODE_TYPE_IDS_MAP } from '../src-js/generated/type_ids.js'; import { addVisitorToCompiled, diff --git a/tasks/ast_tools/src/generators/estree_visit.rs b/tasks/ast_tools/src/generators/estree_visit.rs index 6ac640fa28f44..2105f03b7dbe4 100644 --- a/tasks/ast_tools/src/generators/estree_visit.rs +++ b/tasks/ast_tools/src/generators/estree_visit.rs @@ -78,7 +78,8 @@ impl Generator for ESTreeVisitGenerator { code: visitor_keys, }, Output::Javascript { - path: format!("{OXLINT_APP_PATH}/src-js/generated/type_ids.js"), + // This file is also valid as TS + path: format!("{OXLINT_APP_PATH}/src-js/generated/type_ids.ts"), code: type_ids_map, }, Output::Javascript { diff --git a/tasks/ast_tools/src/generators/raw_transfer.rs b/tasks/ast_tools/src/generators/raw_transfer.rs index b8e37d5e6717e..caec325d6ff75 100644 --- a/tasks/ast_tools/src/generators/raw_transfer.rs +++ b/tasks/ast_tools/src/generators/raw_transfer.rs @@ -86,7 +86,8 @@ impl Generator for RawTransferGenerator { code: constants_js.clone(), }, Output::Javascript { - path: format!("{OXLINT_APP_PATH}/src-js/generated/constants.js"), + // This file is also valid as TS + path: format!("{OXLINT_APP_PATH}/src-js/generated/constants.ts"), code: constants_js, }, Output::Rust {