File tree Expand file tree Collapse file tree 2 files changed +55
-6
lines changed Expand file tree Collapse file tree 2 files changed +55
-6
lines changed Original file line number Diff line number Diff line change @@ -166,8 +166,7 @@ export class Xo {
166
166
167
167
this . xoConfig = [
168
168
this . baseXoConfig ,
169
- // Ensure resolved options do not mutate between runs
170
- ...structuredClone ( flatOptions ) ,
169
+ ...flatOptions ,
171
170
] ;
172
171
173
172
// Split off the TS rules in a special case, so that you won't get errors
@@ -210,13 +209,16 @@ export class Xo {
210
209
// Apply TS rules to all files
211
210
tsConfig . files = [ tsFilesGlob ] ;
212
211
213
- // Set the other rules to the original config
214
- config . rules = Object . fromEntries ( otherRules ) ;
212
+ const otherConfig : XoConfigItem = {
213
+ ...config ,
214
+ // Set the other rules to the original config
215
+ rules : Object . fromEntries ( otherRules ) ,
216
+ } ;
215
217
216
218
// These rules should still apply to all files
217
- config . files = [ allFilesGlob ] ;
219
+ otherConfig . files = [ allFilesGlob ] ;
218
220
219
- return [ tsConfig , config ] ;
221
+ return [ tsConfig , otherConfig ] ;
220
222
} ) ;
221
223
222
224
this . prettier = this . xoConfig . some ( config => config . prettier ) ;
Original file line number Diff line number Diff line change @@ -404,3 +404,50 @@ test('lint-text can be ran multiple times in a row with top level typescript rul
404
404
t . is ( results3 [ 0 ] ?. errorCount , 0 ) ;
405
405
t . true ( results3 [ 0 ] ?. messages ?. length === 0 ) ;
406
406
} ) ;
407
+
408
+ test ( 'config with custom plugin' , async t => {
409
+ const { cwd} = t . context ;
410
+
411
+ await fs . writeFile (
412
+ path . join ( cwd , 'xo.config.js' ) ,
413
+ dedent `
414
+ const testRule = {
415
+ create(context) {
416
+ return {
417
+ Program(node) {
418
+ context.report({
419
+ node,
420
+ message: 'Custom error',
421
+ });
422
+ },
423
+ };
424
+ },
425
+ };
426
+
427
+ export default [
428
+ {
429
+ plugins: {
430
+ 'test-plugin': {
431
+ rules: {
432
+ 'test-rule': testRule,
433
+ },
434
+ },
435
+ },
436
+ rules: {
437
+ 'test-plugin/test-rule': 'error',
438
+ },
439
+ },
440
+ ];\n
441
+ ` ,
442
+ 'utf8' ,
443
+ ) ;
444
+
445
+ const { results} = await Xo . lintText ( dedent `console.log('hello');\n` , {
446
+ cwd,
447
+ filePath : path . join ( cwd , 'test.js' ) ,
448
+ } ) ;
449
+
450
+ t . is ( results [ 0 ] ?. messages ?. length , 1 ) ;
451
+ t . is ( results [ 0 ] ?. messages [ 0 ] ?. ruleId , 'test-plugin/test-rule' ) ;
452
+ t . is ( results [ 0 ] ?. messages [ 0 ] ?. message , 'Custom error' ) ;
453
+ } ) ;
You can’t perform that action at this time.
0 commit comments