diff --git a/packages/rstack/src/rslintConfig.ts b/packages/rstack/src/rslintConfig.ts index c221f359..44062819 100644 --- a/packages/rstack/src/rslintConfig.ts +++ b/packages/rstack/src/rslintConfig.ts @@ -29,13 +29,16 @@ const resolvedLintConfig: RslintConfig = lintEntries.map((entry) => ({ ...entry, })); -const hasExplicitProject = lintEntries.some( - (entry) => entry.languageOptions?.parserOptions?.project !== undefined, -); +const hasExplicitProjectMode = lintEntries.some((entry) => { + const options = entry.languageOptions?.parserOptions; + return ( + options?.project !== undefined || options?.projectService !== undefined + ); +}); // Rslint's implicit tsconfig lookup also follows the internal config directory. -// Preserve the CWD lookup without overriding user projects. -if (!hasExplicitProject && existsSync(join(basePath, 'tsconfig.json'))) { +// Preserve the CWD lookup only when neither project option is explicitly set. +if (!hasExplicitProjectMode && existsSync(join(basePath, 'tsconfig.json'))) { resolvedLintConfig.push({ basePath, languageOptions: { diff --git a/packages/rstack/tests/cli/check.test.ts b/packages/rstack/tests/cli/check.test.ts index bf368fad..a89b360f 100644 --- a/packages/rstack/tests/cli/check.test.ts +++ b/packages/rstack/tests/cli/check.test.ts @@ -168,6 +168,40 @@ test('enables type checking only with --type-check', () => { expect(withTypeCheck.stdout).toContain('Format check passed in'); }); +test.each([true, false])( + 'respects explicit projectService: %s with a root tsconfig', + (projectService) => { + writeProjectFile( + 'rstack.config.ts', + `import { define } from 'rstack'; + +define.lint([ + { + files: ['**/*.ts'], + languageOptions: { + parserOptions: { projectService: ${projectService} }, + }, + rules: { 'no-debugger': 'error' }, + }, +]); +`, + ); + writeProjectFile('tsconfig.json', '{"include":["src"]}\n'); + writeProjectFile('src/index.ts', 'const value: string = 1;\n'); + + const result = runCheck(['--type-check', 'src/index.ts']); + + expect(result.status).toBe(projectService ? 1 : 0); + const output = `${result.stdout}\n${result.stderr}`; + if (projectService) { + expect(output).toContain('TS2322'); + } else { + expect(output).not.toContain('TS2322'); + } + expect(result.stdout).toContain('Format check passed in'); + }, +); + test.each([ { source: 'debugger;\n', formatted: true }, { source: 'debugger;const value=true', formatted: false },