From b1468ff71f7561c15202236d3030987110f4befd Mon Sep 17 00:00:00 2001 From: fansenze Date: Thu, 3 Dec 2026 18:34:33 +0800 Subject: [PATCH] test(vscode): adapt ProjectService E2E to Rslint 0.11 The ProjectService E2E used no-unused-vars to exercise the type-aware scope gate. Rslint 0.11 can run that rule without type information. Use no-unnecessary-type-assertion to keep testing the scope of type-aware diagnostics. --- .../project-service-scope/rslint.config.js | 7 ++- .../project-service-scope/src/covered.ts | 2 +- .../template-nested/orphan.ts | 6 +-- .../template-nested/rslint.config.js | 2 +- .../project-service-scope/test/skills.test.ts | 2 +- .../project-service-scope.test.ts | 45 +++++++------------ 6 files changed, 24 insertions(+), 40 deletions(-) diff --git a/packages/vscode/e2e/lint/fixtures/project-service-scope/rslint.config.js b/packages/vscode/e2e/lint/fixtures/project-service-scope/rslint.config.js index 4f229f24..7602ed1f 100644 --- a/packages/vscode/e2e/lint/fixtures/project-service-scope/rslint.config.js +++ b/packages/vscode/e2e/lint/fixtures/project-service-scope/rslint.config.js @@ -1,6 +1,5 @@ -// Matches the shape of `ts.configs.recommended`: parserOptions only sets -// `projectService: true`, with no explicit `project`. tsconfig.json's -// `include` covers `src` only. +// With no explicit project, projectService discovers tsconfig.json. +// Its include covers src only. export default [ { ignores: ['**/dist/**'] }, { @@ -12,7 +11,7 @@ export default [ }, }, rules: { - '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', // Non-type-aware marker rule. The suite relies on its diagnostic as a // "rslint has finished linting this file" signal, so the negative // assertion does not need a fixed-duration sleep. diff --git a/packages/vscode/e2e/lint/fixtures/project-service-scope/src/covered.ts b/packages/vscode/e2e/lint/fixtures/project-service-scope/src/covered.ts index 6187b57d..c89e1d49 100644 --- a/packages/vscode/e2e/lint/fixtures/project-service-scope/src/covered.ts +++ b/packages/vscode/e2e/lint/fixtures/project-service-scope/src/covered.ts @@ -1,4 +1,4 @@ // File IN tsconfig.include (`src`). Type-aware rules should fire. export const covered = ((command: string, args: string[], options: unknown) => { - return { stdout: '', stderr: '', exitCode: 0 }; + return { stdout: '', stderr: '', exitCode: 0! }; }) as unknown; diff --git a/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/orphan.ts b/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/orphan.ts index c524fe43..fca3de9e 100644 --- a/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/orphan.ts +++ b/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/orphan.ts @@ -2,9 +2,9 @@ // The nearest rslint config says `projectService: true` + no explicit // `project`, so rslint can't resolve a tsconfig for it. // -// The LSP must not run `@typescript-eslint/no-unused-vars` (a type-aware rule) -// here, but non-type-aware native rules and their fixes must remain active. +// The LSP runs native syntax rules and fixes here. Type-aware rules are +// skipped because the file has no TypeScript project. export const orphan = ((command: string, args: string[], options: unknown) => { var output = command; - return { stdout: output, stderr: '', exitCode: 0 }; + return { stdout: output, stderr: '', exitCode: 0! }; }) as unknown; diff --git a/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/rslint.config.js b/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/rslint.config.js index 5bafb913..a6bea673 100644 --- a/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/rslint.config.js +++ b/packages/vscode/e2e/lint/fixtures/project-service-scope/template-nested/rslint.config.js @@ -14,7 +14,7 @@ export default [ }, }, rules: { - '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', 'no-var': 'error', }, }, diff --git a/packages/vscode/e2e/lint/fixtures/project-service-scope/test/skills.test.ts b/packages/vscode/e2e/lint/fixtures/project-service-scope/test/skills.test.ts index 5f1ff73c..f1ce285a 100644 --- a/packages/vscode/e2e/lint/fixtures/project-service-scope/test/skills.test.ts +++ b/packages/vscode/e2e/lint/fixtures/project-service-scope/test/skills.test.ts @@ -9,5 +9,5 @@ export const uncovered = (( args: string[], options: unknown, ) => { - return { stdout: '', stderr: '', exitCode: 0 }; + return { stdout: '', stderr: '', exitCode: 0! }; }) as unknown; diff --git a/packages/vscode/e2e/lint/suite-project-service-scope/project-service-scope.test.ts b/packages/vscode/e2e/lint/suite-project-service-scope/project-service-scope.test.ts index 7c0a483c..5626d0e2 100644 --- a/packages/vscode/e2e/lint/suite-project-service-scope/project-service-scope.test.ts +++ b/packages/vscode/e2e/lint/suite-project-service-scope/project-service-scope.test.ts @@ -1,4 +1,4 @@ -// Ported verbatim from web-infra-dev/rslint +// Ported from web-infra-dev/rslint // `packages/vscode-extension/__tests__/suite-project-service-scope/project-service-scope.test.ts` (origin/main). import * as assert from 'assert'; import * as vscode from 'vscode'; @@ -9,28 +9,13 @@ import { waitForRslintDiagnostics as waitForDiagnostics, } from '../utils/diagnostics'; -// Type-aware rule scope when parserOptions uses `projectService: true` -// (the shape `ts.configs.recommended` exports) without an explicit -// `project`. The LSP and CLI must agree: only files covered by the -// fallback tsconfig's `include` get type-aware rules, AND a nested -// config that has no tsconfig must not enable type-aware rules. -// -// Fixture: fixtures-project-service-scope -// - rslint.config.js — parserOptions.projectService: true (no explicit project). -// Also enables `no-console` as a non-type-aware marker -// rule so the negative test case can wait for rslint to -// finish linting a file without a fixed-duration sleep. -// - tsconfig.json — include: ["src"] -// - src/covered.ts — IN tsconfig: no-unused-vars SHOULD fire -// - test/skills.test.ts — NOT IN tsconfig: no-unused-vars should NOT fire. -// Contains a `console.log` so the marker rule triggers. -// - template-nested/rslint.config.js — nested config, also projectService: true, -// but the dir has NO tsconfig.json. -// - template-nested/orphan.ts — under the nested config. no-unused-vars -// should NOT fire, while native no-var should -// diagnose and participate in fixAll. +// All three fixtures have a redundant `exitCode: 0!` assertion. Its rule +// exercises the ProjectService type-aware gate because no-unused-vars runs +// without type information in Rslint 0.11. Native rules mark lint completion +// for files outside tsconfig.include and under the config without a tsconfig. suite('rslint projectService type-aware scope', function () { this.timeout(120000); + const typeAwareRule = 'no-unnecessary-type-assertion'; function workspaceRoot(): string { return vscode.workspace.workspaceFolders![0].uri.fsPath; @@ -43,7 +28,7 @@ suite('rslint projectService type-aware scope', function () { return diags.filter((d) => d.source === 'rslint'); } - test('src/covered.ts (in tsconfig include) — no-unused-vars SHOULD fire', async () => { + test('src/covered.ts (in tsconfig include) runs type-aware rules', async () => { const doc = await vscode.workspace.openTextDocument( path.join(workspaceRoot(), 'src/covered.ts'), ); @@ -51,18 +36,18 @@ suite('rslint projectService type-aware scope', function () { const diagnostics = await waitForDiagnostics(doc, (diags) => rslintDiagnostics(diags).some((d) => - diagnosticRuleIdIncludes(d, 'no-unused-vars'), + diagnosticRuleIdIncludes(d, typeAwareRule), ), ); const rslintDiags = rslintDiagnostics(diagnostics); assert.ok( - rslintDiags.some((d) => diagnosticRuleIdIncludes(d, 'no-unused-vars')), - `Expected no-unused-vars on src/covered.ts. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, + rslintDiags.some((d) => diagnosticRuleIdIncludes(d, typeAwareRule)), + `Expected ${typeAwareRule} on src/covered.ts. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, ); }); - test('test/skills.test.ts (outside tsconfig include) — no-unused-vars should NOT fire', async () => { + test('test/skills.test.ts (outside tsconfig include) skips type-aware rules', async () => { const doc = await vscode.workspace.openTextDocument( path.join(workspaceRoot(), 'test/skills.test.ts'), ); @@ -84,8 +69,8 @@ suite('rslint projectService type-aware scope', function () { `Expected no-console marker to appear on test/skills.test.ts. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, ); assert.ok( - !rslintDiags.some((d) => diagnosticRuleIdIncludes(d, 'no-unused-vars')), - `no-unused-vars should NOT fire on a file outside tsconfig.include. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, + !rslintDiags.some((d) => diagnosticRuleIdIncludes(d, typeAwareRule)), + `Expected ${typeAwareRule} to be skipped outside tsconfig.include. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, ); }); @@ -107,8 +92,8 @@ suite('rslint projectService type-aware scope', function () { `Expected native no-var marker. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, ); assert.ok( - !rslintDiags.some((d) => diagnosticRuleIdIncludes(d, 'no-unused-vars')), - `no-unused-vars should not run without a resolved tsconfig. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, + !rslintDiags.some((d) => diagnosticRuleIdIncludes(d, typeAwareRule)), + `Expected ${typeAwareRule} to be skipped without a resolved tsconfig. Got: ${rslintDiags.map((d) => d.message).join(' | ')}`, ); });