File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -232,7 +232,9 @@ if (typeof cliOptions.printConfig === 'string') {
232232 process . exit ( 1 ) ;
233233 }
234234
235- const config = await new Xo ( linterOptions , baseXoConfigOptions ) . calculateConfigForFile ( cliOptions . printConfig ) ;
235+ const absoluteFilePath = path . resolve ( cliOptions . cwd , cliOptions . printConfig ) ;
236+
237+ const config = await new Xo ( linterOptions , baseXoConfigOptions ) . calculateConfigForFile ( absoluteFilePath ) ;
236238 console . log ( JSON . stringify ( config , undefined , '\t') ) ;
237239} else {
238240 const xo = new Xo ( linterOptions , baseXoConfigOptions ) ;
Original file line number Diff line number Diff line change @@ -113,6 +113,22 @@ test('xo --print-config ts', async t => {
113113 t . true ( 'rules' in config ) ;
114114} ) ;
115115
116+ test ( 'xo --print-config relative path' , async t => {
117+ const fileName = 'test.ts' ;
118+ const filePath = path . join ( t . context . cwd , fileName ) ;
119+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
120+ const { stdout} = await $ `node ./dist/cli --cwd ${ t . context . cwd } --print-config=${ fileName } ` ;
121+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
122+ const config = JSON . parse ( stdout ) ;
123+ t . true ( typeof config === 'object' ) ;
124+ t . true ( 'rules' in config ) ;
125+ } ) ;
126+
127+ test ( 'xo --print-config no path' , async t => {
128+ const { stderr} : ExecaError = await t . throwsAsync ( $ `node ./dist/cli --cwd ${ t . context . cwd } --print-config` ) ;
129+ t . is ( 'The `--print-config` flag must be used with exactly one filename' , stderr ?. toString ( ) ?? '' ) ;
130+ } ) ;
131+
116132test ( 'xo --ignore' , async t => {
117133 const testFile = path . join ( t . context . cwd , 'test.js' ) ;
118134 const ignoredFile = path . join ( t . context . cwd , 'ignored.js' ) ;
You can’t perform that action at this time.
0 commit comments