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
9 changes: 8 additions & 1 deletion packages/rstack/src/configLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ConfigArgs<K extends keyof Configs> = K extends 'app'

/**
* Resolve one tool from ordered, normalized config layers. Lint factories are
* already wrapped by define.lint; merging belongs to the tool adapters.
* already wrapped by define.lint. This function does not merge the results.
*/
export const resolveConfigLayers = async <K extends keyof Configs>(
layers: readonly Configs[],
Expand Down Expand Up @@ -56,3 +56,10 @@ export const resolveConfigLayers = async <K extends keyof Configs>(

return configs;
};

export const resolveRslintConfig = async (
layers: readonly Configs[],
): Promise<RslintConfig | undefined> => {
const configs = await resolveConfigLayers(layers, 'lint');
return configs.length > 1 ? configs.flat() : configs[0];
};
11 changes: 3 additions & 8 deletions packages/rstack/src/rslintConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@ import { join } from 'node:path';
import { loadRstackConfig, type LoadedRstackConfig } from './config.ts';
import type { RslintConfig } from '@rslint/core';
import { color, logger } from 'rslog';
import { resolveRslintConfig } from './configLayers.ts';

// Expose the loaded config so `rs check` can pass it to fmt instead of loading
// and executing the Rstack config a second time.
export const loadedConfig: LoadedRstackConfig = await loadRstackConfig();
const { configs } = loadedConfig;
const lintDefinition = configs.lint;
const lintConfig = await resolveRslintConfig([configs]);

let lintConfig: RslintConfig;

if (lintDefinition === undefined) {
if (lintConfig === undefined) {
logger.error(
`No lint configuration found. Add ${color.cyan('define.lint(...)')} to your Rstack config file.`,
);
process.exit(1);
} else if (typeof lintDefinition === 'function') {
lintConfig = await lintDefinition();
} else {
lintConfig = lintDefinition;
}

const basePath = process.cwd();
Expand Down
26 changes: 26 additions & 0 deletions packages/rstack/tests/config/lint-merge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { RslintConfig } from '@rslint/core';
import { expect, test } from 'rstack/test';
import { normalizeRstackConfig } from '../../src/config.ts';
import { resolveRslintConfig } from '../../src/configLayers.ts';

test('concatenates lint layers in order without merging entries', async () => {
const shared: RslintConfig = [
{ ignores: ['dist/**'] },
[{ files: ['**/*.js'], rules: { 'no-debugger': 'error' } }],
];
const project: RslintConfig = [{ rules: { 'no-debugger': 'off' } }];

const config = await resolveRslintConfig([
{ lint: shared },
normalizeRstackConfig({ lint: () => Promise.resolve(project) }),
]);

expect(config).toEqual([...shared, ...project]);
});

test('preserves a single lint config and distinguishes missing from empty', async () => {
const config: RslintConfig = [];

expect(await resolveRslintConfig([{}])).toBeUndefined();
expect(await resolveRslintConfig([{}, { lint: config }])).toBe(config);
});
Loading