Skip to content

Commit 56fe4e1

Browse files
committed
fix: support Rslint v0.9.0 config paths
1 parent 8fc3677 commit 56fe4e1

6 files changed

Lines changed: 102 additions & 40 deletions

File tree

packages/rstack/src/rslintConfig.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { existsSync } from 'node:fs';
2+
import { join } from 'node:path';
13
import { loadRstackConfig, type LoadedRstackConfig } from './config.ts';
24
import type { RslintConfig } from '@rslint/core';
35

@@ -16,4 +18,32 @@ if (typeof lintDefinition === 'function') {
1618
lintConfig = lintDefinition;
1719
}
1820

19-
export default lintConfig;
21+
const basePath = process.cwd();
22+
const lintEntries = lintConfig.flat();
23+
24+
// Rslint resolves entries without a basePath from the explicit config file.
25+
// Rstack's explicit config is this internal module, so preserve the historical
26+
// behavior of resolving user-authored paths from the invocation directory.
27+
const resolvedLintConfig: RslintConfig = lintEntries.map((entry) => ({
28+
basePath,
29+
...entry,
30+
}));
31+
32+
const hasExplicitProject = lintEntries.some(
33+
(entry) => entry.languageOptions?.parserOptions?.project !== undefined,
34+
);
35+
36+
// Rslint's implicit tsconfig lookup also follows the internal config directory.
37+
// Preserve the CWD lookup without overriding user projects.
38+
if (!hasExplicitProject && existsSync(join(basePath, 'tsconfig.json'))) {
39+
resolvedLintConfig.push({
40+
basePath,
41+
languageOptions: {
42+
parserOptions: {
43+
project: ['./tsconfig.json'],
44+
},
45+
},
46+
});
47+
}
48+
49+
export default resolvedLintConfig;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { writeFile } from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { test } from '#test-helpers';
4+
import { expect } from 'rstack/test';
5+
6+
test('should preserve an explicit basePath', async ({
7+
cwd,
8+
execCli,
9+
logHelper,
10+
}) => {
11+
const filePath = path.join(cwd, 'src/index.js');
12+
await writeFile(filePath, `alert('hello');\n`);
13+
14+
try {
15+
expect(() => execCli('lint src/index.js')).toThrow();
16+
await logHelper.expectLog('Unexpected alert');
17+
} finally {
18+
await writeFile(filePath, `console.log('hello');\n`);
19+
}
20+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { define } from 'rstack';
2+
3+
define.lint([
4+
{
5+
basePath: 'src',
6+
files: ['index.js'],
7+
rules: {
8+
'no-alert': 'error',
9+
},
10+
},
11+
]);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hello');

pnpm-lock.yaml

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ catalog:
1717
'@rsbuild/plugin-react': '^2.1.0'
1818
'@rsbuild/plugin-sass': '^2.0.1'
1919
'@rslib/core': '~1.0.0-rc.2'
20-
'@rslint/core': '0.8.1'
20+
'@rslint/core': '0.9.0'
2121
'@rspress/core': '^2.0.20'
2222
'@rspress/plugin-client-redirects': '^2.0.20'
2323
'@rspress/plugin-sitemap': '^2.0.20'

0 commit comments

Comments
 (0)