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') {
232
232
process . exit ( 1 ) ;
233
233
}
234
234
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 ) ;
236
238
console . log ( JSON . stringify ( config , undefined , '\t') ) ;
237
239
} else {
238
240
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 => {
113
113
t . true ( 'rules' in config ) ;
114
114
} ) ;
115
115
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
+
116
132
test ( 'xo --ignore' , async t => {
117
133
const testFile = path . join ( t . context . cwd , 'test.js' ) ;
118
134
const ignoredFile = path . join ( t . context . cwd , 'ignored.js' ) ;
You can’t perform that action at this time.
0 commit comments