Repository navigation
refactor(test): migrate rules to TypeScript - #3036
Conversation
# Conflicts: # tests/lib/utils/ts-utils/index/get-component-emits.ts # tests/lib/utils/ts-utils/index/get-component-props.ts # tests/lib/utils/ts-utils/index/get-component-slots.ts # vitest.config.mts
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
# Conflicts: # tests/lib/rules/no-unsupported-features/define-model.test.ts # tests/lib/rules/no-unsupported-features/define-options.test.ts # tests/lib/rules/no-unsupported-features/define-slots.test.ts # tests/lib/rules/no-unsupported-features/dynamic-directive-arguments.test.ts # tests/lib/rules/no-unsupported-features/is-attribute-with-vue-prefix.test.ts # tests/lib/rules/no-unsupported-features/script-setup.test.ts # tests/lib/rules/no-unsupported-features/slot-scope-attribute.test.ts # tests/lib/rules/no-unsupported-features/style-css-vars-injection.test.ts # tests/lib/rules/no-unsupported-features/v-bind-attr-modifier.test.ts # tests/lib/rules/no-unsupported-features/v-bind-prop-modifier-shorthand.test.ts # tests/lib/rules/no-unsupported-features/v-bind-same-name-shorthand.test.ts # tests/lib/rules/no-unsupported-features/v-is.test.ts # tests/lib/rules/no-unsupported-features/v-memo.test.ts # tests/lib/rules/no-unsupported-features/v-model-argument.test.ts # tests/lib/rules/no-unsupported-features/v-model-custom-modifiers.test.ts # tests/lib/rules/no-unsupported-features/v-slot.test.ts # tests/lib/utils/casing.test.ts # tests/lib/utils/core-rules/wrap-core-rule.test.ts # tests/lib/utils/index.test.ts # tests/lib/utils/regexp.test.ts # tests/lib/utils/vue-component.test.ts # typings/eslint/index.d.ts # vitest.config.mts
# Conflicts: # tests/lib/rules/comma-style.test.ts # tests/lib/rules/func-call-spacing.test.ts # tests/lib/rules/no-dupe-keys.test.ts # tests/lib/rules/no-restricted-props.test.ts # tests/lib/rules/no-undef-properties.test.ts # tests/lib/rules/no-unused-emit-declarations.test.ts # tests/lib/rules/no-unused-properties.test.ts # tests/lib/rules/padding-lines-in-component-definition.test.ts # tests/lib/rules/prefer-prop-type-boolean-first.test.ts # tests/lib/rules/prop-name-casing.test.ts # tests/lib/rules/require-emit-validator.test.ts # tests/lib/rules/require-explicit-emits.test.ts # tests/lib/rules/require-explicit-slots.test.ts # tests/lib/rules/require-prop-comment.test.ts # tests/lib/rules/require-prop-type-constructor.test.ts # tests/lib/rules/require-prop-types.test.ts # tests/lib/rules/require-valid-default-prop.test.ts # tests/lib/rules/return-in-emits-validator.test.ts # tests/test-utils/eslint-stylistic.ts
rules to TypeScript
# Conflicts: # tests/integrations/eslint-plugin-import.test.ts # tests/integrations/flat-config.test.ts # tests/lib/meta.test.ts
There was a problem hiding this comment.
Pull request overview
This PR migrates the rule test suite from CommonJS JavaScript to TypeScript/ESM, aligning test execution with Vitest’s TS workflow and updating a few related typings and rule JSDoc annotations.
Changes:
- Update Vitest test discovery patterns to target
*.test.tsfiles. - Replace CommonJS
require(...)usage in many tests with ESMimport(and introduce a newtests/eslint-compat.tshelper). - Add/adjust some TypeScript typings and a few tests (e.g., new config tests,
block-ordertest), plus minor rule JSDoc return type fixes.
Reviewed changes
Copilot reviewed 236 out of 241 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.mts | Narrow test include globs to *.test.ts and simplify excludes. |
| typings/eslint/index.d.ts | Refine RuleTester typing (constructor + merged namespace aliases). |
| tests/eslint-compat.ts | New ESM TypeScript replacement for tests/eslint-compat.js using eslint-compat-utils. |
| tests/eslint-compat.js | Removed legacy CommonJS compat helper. |
| tests/lib/configs/flat.test.ts | New/ported tests validating flat-config exports and suppression behavior. |
| tests/lib/configs/eslintrc.test.ts | New/ported tests validating legacy plugin:vue/* config loading. |
| tests/lib/rules/block-order.test.ts | New/ported block-order tests using both RuleTester and ESLint API. |
| tests/lib/rules/script-indent.test.ts | Migrated to ESM/TS; uses createRequire but still references __dirname. |
| tests/lib/rules/html-indent.test.ts | Migrated to ESM/TS; still references __dirname and require.resolve. |
| tests/lib/rules/no-export-in-script-setup.test.ts | Migrated to ESM/TS; still uses require.resolve for TS parser resolution. |
| tests/lib/rules/require-default-prop.test.ts | Migrated to ESM/TS; still uses require.resolve for TS parser resolution in parserOptions. |
| tests/lib/rules/*.test.ts | Bulk migration of rule tests from CJS to TS/ESM (imports + parser wiring). |
| lib/rules/use-v-on-exact.js | JSDoc return type updated from Object to RuleListener. |
| lib/rules/this-in-template.js | JSDoc return type updated from Object to RuleListener. |
| lib/rules/no-template-target-blank.js | JSDoc return type updated from Object to RuleListener. |
Comments suppressed due to low confidence (5)
tests/lib/rules/script-indent.test.ts:16
__dirnameis used in an ESM test module (this file already usesimport.meta.url/createRequire). In ESM,__dirnameis undefined, soFIXTURE_ROOTwill throw at runtime. Compute the directory fromimport.meta.url(e.g., viafileURLToPath/path.dirname) or build the fixture path usingnew URL(..., import.meta.url)instead.
tests/lib/rules/html-indent.test.ts:13__dirnameis referenced in this ESM test file, but__dirnameis not defined in ESM. This will crash when computingFIXTURE_ROOT. Usenew URL('../../fixtures/html-indent/', import.meta.url)(or derive a dirname fromimport.meta.url) instead.
tests/lib/rules/html-indent.test.ts:45- This ESM test file still calls
require.resolve(...), butrequireis not defined in ESM, so resolving fixture-provided parsers will throw at runtime. Use acreateRequire(import.meta.url)instance (as inscript-indent.test.ts) and callnodeRequire.resolve(...)here instead (or switch to passing the imported parser object if supported).
tests/lib/rules/no-export-in-script-setup.test.ts:76 - This ESM test file uses
require.resolve('@typescript-eslint/parser'), butrequireis not defined in ESM, so these test cases will crash when evaluated. Use acreateRequire(import.meta.url)instance to resolve the parser, or avoidrequire.resolveby passing the imported parser directly ifvue-eslint-parseraccepts parser objects inparserOptions.parser.
tests/lib/rules/require-default-prop.test.ts:247 - These test cases configure
parserOptions.parserviarequire.resolve('@typescript-eslint/parser'), but this file is ESM sorequireis undefined at runtime. UsecreateRequire(import.meta.url).resolve(...)(or pass the imported TS parser directly, if supported) to avoid a runtime crash.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
FloEdelmann
left a comment
There was a problem hiding this comment.
Thank you so much for pushing the TypeScript migration along!
Test files count:

Before:
After:
