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
32 changes: 31 additions & 1 deletion packages/rstack/src/rslintConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { loadRstackConfig, type LoadedRstackConfig } from './config.ts';
import type { RslintConfig } from '@rslint/core';

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

export default lintConfig;
const basePath = process.cwd();
const lintEntries = lintConfig.flat();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Flatten nested Rslint configs recursively

When a valid Rslint configuration contains arrays nested more than one level—such as a shareable preset array wrapped by another composed preset—flat() leaves the inner array intact. The subsequent object spread converts that array into an object with numeric properties rather than preserving its configuration entries, so its rules and file selectors are silently omitted. Flatten the recursive config structure completely before adding basePath.

Useful? React with 👍 / 👎.


// Rslint resolves entries without a basePath from the explicit config file.
// Rstack's explicit config is this internal module, so preserve the historical
// behavior of resolving user-authored paths from the invocation directory.
const resolvedLintConfig: RslintConfig = lintEntries.map((entry) => ({
basePath,
...entry,
}));

const hasExplicitProject = lintEntries.some(
(entry) => entry.languageOptions?.parserOptions?.project !== 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'))) {
resolvedLintConfig.push({
basePath,
languageOptions: {
parserOptions: {
project: ['./tsconfig.json'],
},
},
});
}

export default resolvedLintConfig;
20 changes: 20 additions & 0 deletions packages/rstack/tests/config/define-lint-base-path/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import { test } from '#test-helpers';
import { expect } from 'rstack/test';

test('should preserve an explicit basePath', async ({
cwd,
execCli,
logHelper,
}) => {
const filePath = path.join(cwd, 'src/index.js');
await writeFile(filePath, `alert('hello');\n`);

try {
expect(() => execCli('lint src/index.js')).toThrow();
await logHelper.expectLog('Unexpected alert');
} finally {
await writeFile(filePath, `console.log('hello');\n`);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { define } from 'rstack';

define.lint([
{
basePath: 'src',
files: ['index.js'],
rules: {
'no-alert': 'error',
},
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello');
76 changes: 38 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ catalog:
'@rsbuild/plugin-react': '^2.1.0'
'@rsbuild/plugin-sass': '^2.0.1'
'@rslib/core': '~1.0.0-rc.2'
'@rslint/core': '0.8.1'
'@rslint/core': '0.9.0'
'@rspress/core': '^2.0.20'
'@rspress/plugin-client-redirects': '^2.0.20'
'@rspress/plugin-sitemap': '^2.0.20'
Expand Down