Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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/**'] },
{
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default [
},
},
rules: {
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'no-var': 'error',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const uncovered = ((
args: string[],
options: unknown,
) => {
return { stdout: '', stderr: '', exitCode: 0 };
return { stdout: '', stderr: '', exitCode: 0! };
}) as unknown;
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -43,26 +28,26 @@ 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'),
);
await vscode.window.showTextDocument(doc);

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'),
);
Expand All @@ -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(' | ')}`,
);
});

Expand All @@ -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(' | ')}`,
);
});

Expand Down