File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import type { RslintConfig } from '@rslint/core' ;
2+ import type { Configs } from './config.ts' ;
3+ import { resolveConfigLayers } from './configLayers.ts' ;
4+
5+ export const resolveRslintConfig = async (
6+ layers : readonly Configs [ ] ,
7+ ) : Promise < RslintConfig | undefined > => {
8+ const configs = await resolveConfigLayers ( layers , 'lint' ) ;
9+ return configs . length > 1 ? configs . flat ( ) : configs [ 0 ] ;
10+ } ;
Original file line number Diff line number Diff line change @@ -3,24 +3,19 @@ import { join } from 'node:path';
33import { loadRstackConfig , type LoadedRstackConfig } from './config.ts' ;
44import type { RslintConfig } from '@rslint/core' ;
55import { color , logger } from 'rslog' ;
6+ import { resolveRslintConfig } from './lintConfig.ts' ;
67
78// Expose the loaded config so `rs check` can pass it to fmt instead of loading
89// and executing the Rstack config a second time.
910export const loadedConfig : LoadedRstackConfig = await loadRstackConfig ( ) ;
1011const { configs } = loadedConfig ;
11- const lintDefinition = configs . lint ;
12+ const lintConfig = await resolveRslintConfig ( [ configs ] ) ;
1213
13- let lintConfig : RslintConfig ;
14-
15- if ( lintDefinition === undefined ) {
14+ if ( lintConfig === undefined ) {
1615 logger . error (
1716 `No lint configuration found. Add ${ color . cyan ( 'define.lint(...)' ) } to your Rstack config file.` ,
1817 ) ;
1918 process . exit ( 1 ) ;
20- } else if ( typeof lintDefinition === 'function' ) {
21- lintConfig = await lintDefinition ( ) ;
22- } else {
23- lintConfig = lintDefinition ;
2419}
2520
2621const basePath = process . cwd ( ) ;
Original file line number Diff line number Diff line change 1+ import type { RslintConfig } from '@rslint/core' ;
2+ import { expect , test } from 'rstack/test' ;
3+ import { normalizeRstackConfig } from '../../src/config.ts' ;
4+ import { resolveRslintConfig } from '../../src/lintConfig.ts' ;
5+
6+ test ( 'concatenates lint layers in order without merging entries' , async ( ) => {
7+ const shared : RslintConfig = [
8+ { ignores : [ 'dist/**' ] } ,
9+ [ { files : [ '**/*.js' ] , rules : { 'no-debugger' : 'error' } } ] ,
10+ ] ;
11+ const project : RslintConfig = [ { rules : { 'no-debugger' : 'off' } } ] ;
12+
13+ const config = await resolveRslintConfig ( [
14+ { lint : shared } ,
15+ normalizeRstackConfig ( { lint : ( ) => Promise . resolve ( project ) } ) ,
16+ ] ) ;
17+
18+ expect ( config ) . toEqual ( [ ...shared , ...project ] ) ;
19+ } ) ;
20+
21+ test ( 'preserves a single lint config and distinguishes missing from empty' , async ( ) => {
22+ const config : RslintConfig = [ ] ;
23+
24+ expect ( await resolveRslintConfig ( [ { } ] ) ) . toBeUndefined ( ) ;
25+ expect ( await resolveRslintConfig ( [ { } , { lint : config } ] ) ) . toBe ( config ) ;
26+ } ) ;
You can’t perform that action at this time.
0 commit comments