1
- 'use strict' ;
2
- import os from 'os' ;
3
- import path from 'path' ;
1
+ import os from 'node:os' ;
2
+ import path from 'node:path' ;
4
3
import fsExtra from 'fs-extra' ;
5
4
import arrify from 'arrify' ;
6
5
import { mergeWith , groupBy , flow , pick } from 'lodash-es' ;
@@ -43,7 +42,7 @@ const resolveFrom = (moduleId, fromDirectory = process.cwd()) => resolveModule(m
43
42
resolveFrom . silent = ( moduleId , fromDirectory ) => {
44
43
try {
45
44
return resolveFrom ( moduleId , fromDirectory ) ;
46
- } catch { }
45
+ } catch { }
47
46
} ;
48
47
49
48
const resolveLocalConfig = name => resolveModule ( normalizePackageName ( name , 'eslint-config' ) , import . meta. url ) ;
@@ -92,7 +91,7 @@ const getEmptyXOConfig = () => ({
92
91
const mergeFn = ( previousValue , value , key ) => {
93
92
if ( Array . isArray ( previousValue ) ) {
94
93
if ( MERGE_OPTIONS_CONCAT . includes ( key ) ) {
95
- return previousValue . concat ( value ) ;
94
+ return [ ... previousValue , ... value ] ;
96
95
}
97
96
98
97
return value ;
@@ -186,7 +185,7 @@ const mergeWithFileConfigs = async (files, options, configFiles) => {
186
185
187
186
await Promise . all ( Object . entries ( groupBy ( groups . filter ( ( { options} ) => Boolean ( options . ts ) ) , group => group . options . tsConfigPath || '' ) ) . map (
188
187
( [ tsConfigPath , groups ] ) => {
189
- const files = [ ] . concat ( ... groups . map ( group => group . files ) ) ;
188
+ const files = groups . flatMap ( group => group . files ) ;
190
189
const cachePath = getTsConfigCachePath ( files , tsConfigPath ) ;
191
190
192
191
for ( const group of groups ) {
@@ -386,7 +385,7 @@ const buildXOConfig = options => config => {
386
385
387
386
// Only apply if the user has the React plugin
388
387
if ( options . cwd && resolveFrom . silent ( 'eslint-plugin-react' , options . cwd ) ) {
389
- config . baseConfig . plugins = config . baseConfig . plugins . concat ( 'react' ) ;
388
+ config . baseConfig . plugins . push ( 'react' ) ;
390
389
config . baseConfig . rules [ 'react/jsx-indent-props' ] = [ 'error' , spaces ] ;
391
390
config . baseConfig . rules [ 'react/jsx-indent' ] = [ 'error' , spaces ] ;
392
391
}
@@ -452,10 +451,10 @@ const buildExtendsConfig = options => config => {
452
451
const buildPrettierConfig = ( options , prettierConfig ) => config => {
453
452
if ( options . prettier ) {
454
453
// The prettier plugin uses Prettier to format the code with `--fix`
455
- config . baseConfig . plugins = config . baseConfig . plugins . concat ( 'prettier' ) ;
454
+ config . baseConfig . plugins . push ( 'prettier' ) ;
456
455
457
456
// The prettier config overrides ESLint stylistic rules that are handled by Prettier
458
- config . baseConfig . extends = config . baseConfig . extends . concat ( 'prettier' ) ;
457
+ config . baseConfig . extends . push ( 'prettier' ) ;
459
458
460
459
// The `prettier/prettier` rule reports errors if the code is not formatted in accordance to Prettier
461
460
config . baseConfig . rules [ 'prettier/prettier' ] = [ 'error' , mergeWithPrettierConfig ( options , prettierConfig ) ] ;
@@ -464,7 +463,7 @@ const buildPrettierConfig = (options, prettierConfig) => config => {
464
463
// See https://github.com/prettier/eslint-config-prettier for the list of plugins overrrides
465
464
for ( const [ plugin , prettierConfig ] of Object . entries ( PRETTIER_CONFIG_OVERRIDE ) ) {
466
465
if ( options . cwd && resolveFrom . silent ( plugin , options . cwd ) ) {
467
- config . baseConfig . extends = config . baseConfig . extends . concat ( prettierConfig ) ;
466
+ config . baseConfig . extends . push ( prettierConfig ) ;
468
467
}
469
468
}
470
469
}
@@ -505,7 +504,7 @@ const mergeWithPrettierConfig = (options, prettierOptions) => {
505
504
506
505
const buildTSConfig = options => config => {
507
506
if ( options . ts ) {
508
- config . baseConfig . extends = config . baseConfig . extends . concat ( 'xo-typescript' ) ;
507
+ config . baseConfig . extends . push ( 'xo-typescript' ) ;
509
508
config . baseConfig . parser = require . resolve ( '@typescript-eslint/parser' ) ;
510
509
config . baseConfig . parserOptions = {
511
510
...config . baseConfig . parserOptions ,
@@ -532,7 +531,7 @@ const applyOverrides = (file, options) => {
532
531
533
532
const { applicable, hash} = findApplicableOverrides ( path . relative ( options . cwd , file ) , overrides ) ;
534
533
535
- options = mergeWith ( ... [ getEmptyXOConfig ( ) , options ] . concat ( applicable . map ( override => normalizeOptions ( override ) ) , mergeFn ) ) ;
534
+ options = mergeWith ( getEmptyXOConfig ( ) , options , ... applicable . map ( override => normalizeOptions ( override ) ) , mergeFn ) ;
536
535
delete options . files ;
537
536
return { options, hash} ;
538
537
}
0 commit comments