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
13 changes: 8 additions & 5 deletions packages/rstack/src/rslintConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
34 changes: 34 additions & 0 deletions packages/rstack/tests/cli/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Loading