@@ -993,3 +993,168 @@ test('ts rules apply to js files when "files" is set to a relative glob path', a
993993 t . true ( cachedTsConfig . files ?. includes ( tsFilePath ) , 'TypeScript file should be included in cached tsconfig' ) ;
994994 t . true ( cachedTsConfig . files ?. includes ( jsFilePath ) , 'JavaScript file should be included in cached tsconfig' ) ;
995995} ) ;
996+
997+ // Supports a custom config file
998+ test ( 'supports a custom config file with absolute path' , async t => {
999+ const { cwd} = t . context ;
1000+
1001+ // Create a simple JS file
1002+ const filePath = path . join ( cwd , 'test.js' ) ;
1003+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1004+
1005+ // Create a custom XO config file
1006+ const customConfigPath = path . join ( cwd , 'custom.xo.config.js' ) ;
1007+ const customConfig = dedent `
1008+ export default [
1009+ { ignores: "xo.config.js" },
1010+ {
1011+ rules: {
1012+ 'no-console': 'error',
1013+ }
1014+ }
1015+ ]
1016+ ` ;
1017+ await fs . writeFile ( customConfigPath , customConfig , 'utf8' ) ;
1018+
1019+ // Run XO with the custom config file
1020+ const error = await t . throwsAsync < ExecaError > ( $ `node ./dist/cli --cwd ${ cwd } --config ${ customConfigPath } ` ) ;
1021+ t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
1022+ t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific rule should be mentioned in the output' ) ;
1023+ } ) ;
1024+
1025+ test ( 'supports a custom config file with relative path' , async t => {
1026+ const { cwd} = t . context ;
1027+
1028+ // Create a simple JS file
1029+ const filePath = path . join ( cwd , 'test.js' ) ;
1030+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1031+
1032+ // Create a custom XO config file
1033+ const customConfigPath = path . join ( cwd , 'custom.xo.config.js' ) ;
1034+ const customConfig = dedent `
1035+ export default [
1036+ { ignores: "xo.config.js" },
1037+ {
1038+ rules: {
1039+ 'no-console': 'error',
1040+ }
1041+ }
1042+ ]
1043+ ` ;
1044+ await fs . writeFile ( customConfigPath , customConfig , 'utf8' ) ;
1045+
1046+ // Run XO with the custom config file with relative path
1047+ const error = await t . throwsAsync < ExecaError > ( $ `node ./dist/cli --cwd ${ cwd } --config ${ path . relative ( cwd , customConfigPath ) } ` ) ;
1048+ t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
1049+ t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific rule should be mentioned in the output' ) ;
1050+ } ) ;
1051+
1052+ test ( 'supports a custom config file with relative dot slash path' , async t => {
1053+ const { cwd} = t . context ;
1054+
1055+ // Create a simple JS file
1056+ const filePath = path . join ( cwd , 'test.js' ) ;
1057+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1058+
1059+ // Create a custom XO config file
1060+ const customConfigPath = path . join ( cwd , 'custom.xo.config.js' ) ;
1061+ const customConfig = dedent `
1062+ export default [
1063+ { ignores: "xo.config.js" },
1064+ {
1065+ rules: {
1066+ 'no-console': 'error',
1067+ }
1068+ }
1069+ ]
1070+ ` ;
1071+ await fs . writeFile ( customConfigPath , customConfig , 'utf8' ) ;
1072+
1073+ // Run XO with the custom config file with relative path
1074+ const error = await t . throwsAsync < ExecaError > ( $ `node ./dist/cli --cwd ${ cwd } --config ./${ path . relative ( cwd , customConfigPath ) } ` ) ;
1075+ t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
1076+ t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific rule should be mentioned in the output' ) ;
1077+ } ) ;
1078+
1079+ // Supports custom config file with ts path
1080+ test ( 'supports a custom config file with absolute path for TypeScript' , async t => {
1081+ const { cwd} = t . context ;
1082+
1083+ // Create a simple TS file
1084+ const filePath = path . join ( cwd , 'test.js' ) ;
1085+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1086+
1087+ // Create a custom XO config file
1088+ const customConfigPath = path . join ( cwd , 'custom.xo.config.ts' ) ;
1089+ const customConfig = dedent `
1090+ export default [
1091+ { ignores: "custom.xo.config.ts" },
1092+ {
1093+ rules: {
1094+ 'no-console': 'error',
1095+ }
1096+ }
1097+ ]
1098+ ` ;
1099+ await fs . writeFile ( customConfigPath , customConfig , 'utf8' ) ;
1100+
1101+ // Run XO with the custom config file
1102+ const error = await t . throwsAsync < ExecaError > ( $ `node ./dist/cli --cwd ${ cwd } --config ${ customConfigPath } ` ) ;
1103+ t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
1104+ t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific TypeScript rule should be mentioned in the output' ) ;
1105+ } ) ;
1106+
1107+ // Supports custom config file with ts path
1108+ test ( 'supports a custom config file with relative path for TypeScript' , async t => {
1109+ const { cwd} = t . context ;
1110+
1111+ // Create a simple TS file
1112+ const filePath = path . join ( cwd , 'test.js' ) ;
1113+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1114+
1115+ // Create a custom XO config file
1116+ const customConfigPath = path . join ( cwd , 'custom.xo.config.ts' ) ;
1117+ const customConfig = dedent `
1118+ export default [
1119+ { ignores: "custom.xo.config.ts" },
1120+ {
1121+ rules: {
1122+ 'no-console': 'error',
1123+ }
1124+ }
1125+ ]
1126+ ` ;
1127+ await fs . writeFile ( customConfigPath , customConfig , 'utf8' ) ;
1128+
1129+ // Run XO with the custom config file
1130+ const error = await t . throwsAsync < ExecaError > ( $ `node ./dist/cli --cwd ${ cwd } --config ${ path . relative ( cwd , customConfigPath ) } ` ) ;
1131+ t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
1132+ t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific TypeScript rule should be mentioned in the output' ) ;
1133+ } ) ;
1134+ // Supports custom config file with ts path
1135+ test ( 'supports a custom config file with relative dot slash path for TypeScript' , async t => {
1136+ const { cwd} = t . context ;
1137+
1138+ // Create a simple TS file
1139+ const filePath = path . join ( cwd , 'test.js' ) ;
1140+ await fs . writeFile ( filePath , dedent `console.log('hello');\n` , 'utf8' ) ;
1141+
1142+ // Create a custom XO config file
1143+ const customConfigPath = path . join ( cwd , 'custom.xo.config.ts' ) ;
1144+ const customConfig = dedent `
1145+ export default [
1146+ { ignores: "custom.xo.config.ts" },
1147+ {
1148+ rules: {
1149+ 'no-console': 'error',
1150+ }
1151+ }
1152+ ]
1153+ ` ;
1154+ await fs . writeFile ( customConfigPath , customConfig , 'utf8' ) ;
1155+
1156+ // Run XO with the custom config file
1157+ const error = await t . throwsAsync < ExecaError > ( $ `node ./dist/cli --cwd ${ cwd } --config ./${ path . relative ( cwd , customConfigPath ) } ` ) ;
1158+ t . true ( ( error . stdout as string ) ?. includes ( 'test.js' ) , 'Error should be reported for the test.js file' ) ;
1159+ t . true ( ( error . stdout as string ) ?. includes ( 'no-console' ) , 'The specific TypeScript rule should be mentioned in the output' ) ;
1160+ } ) ;
0 commit comments