@@ -5,7 +5,7 @@ function getTraverser() {
5
5
try {
6
6
// eslint-disable-next-line node/no-unpublished-require
7
7
traverser = require ( 'eslint/lib/shared/traverser' ) ; // eslint >= 6
8
- } catch ( e ) {
8
+ } catch ( error ) {
9
9
// eslint-disable-next-line node/no-unpublished-require, node/no-missing-require
10
10
traverser = require ( 'eslint/lib/util/traverser' ) ; // eslint < 6
11
11
}
@@ -402,7 +402,7 @@ module.exports = {
402
402
)
403
403
)
404
404
. reduce ( ( keys , key ) => {
405
- if ( keys . indexOf ( key ) < 0 ) {
405
+ if ( ! keys . includes ( key ) ) {
406
406
keys . push ( key ) ;
407
407
}
408
408
return keys ;
@@ -457,6 +457,10 @@ module.exports = {
457
457
} ,
458
458
} ;
459
459
460
+ function isBare ( key ) {
461
+ return ! key . includes ( '.' ) || key . endsWith ( '[]' ) ;
462
+ }
463
+
460
464
/**
461
465
* Collapse dependency keys with braces if possible.
462
466
*
@@ -468,11 +472,7 @@ module.exports = {
468
472
* @returns string
469
473
*/
470
474
function collapseKeys ( keys ) {
471
- const uniqueKeys = Array . from ( new Set ( keys ) ) ;
472
-
473
- function isBare ( key ) {
474
- return key . indexOf ( '.' ) === - 1 || key . endsWith ( '[]' ) ;
475
- }
475
+ const uniqueKeys = [ ...new Set ( keys ) ] ;
476
476
477
477
const bareKeys = uniqueKeys . filter ( isBare ) ;
478
478
const rest = uniqueKeys . filter ( key => ! isBare ( key ) ) ;
@@ -487,7 +487,7 @@ function collapseKeys(keys) {
487
487
return mapByParent ;
488
488
} , new Map ( ) ) ;
489
489
490
- const joined = Array . from ( mapByParent . keys ( ) ) . map ( parent => {
490
+ const joined = [ ... mapByParent . keys ( ) ] . map ( parent => {
491
491
const children = mapByParent . get ( parent ) ;
492
492
if ( children . length > 1 ) {
493
493
return `${ parent } .{${ children . sort ( ) . join ( ',' ) } }` ;
@@ -505,7 +505,7 @@ function collapseKeys(keys) {
505
505
*/
506
506
function expandKeys ( keys ) {
507
507
// aka flat map
508
- return [ ] . concat ( ...keys . map ( expandKey ) ) ;
508
+ return [ ] . concat ( ...keys . map ( expandKey ) ) ; // eslint-disable-line unicorn/prefer-flat-map
509
509
}
510
510
511
511
/**
@@ -522,9 +522,9 @@ function expandKey(key) {
522
522
if ( key . includes ( '{' ) ) {
523
523
// key = "foo.{bar,baz}"
524
524
const keyParts = key . split ( '{' ) ; // ["foo", "{bar,baz}"]
525
- const keyBeforeCurly = keyParts [ 0 ] . substring ( 0 , keyParts [ 0 ] . length - 1 ) ; // "foo"
525
+ const keyBeforeCurly = keyParts [ 0 ] . slice ( 0 , Math . max ( 0 , keyParts [ 0 ] . length - 1 ) ) ; // "foo"
526
526
const keyAfterCurly = keyParts [ 1 ] ; // "{bar,baz}"
527
- const keyAfterCurlySplitByCommas = keyAfterCurly . replace ( / \{ | \ }/ g, '' ) . split ( ',' ) ; // ["bar", "baz"]
527
+ const keyAfterCurlySplitByCommas = keyAfterCurly . replace ( / { | } / g, '' ) . split ( ',' ) ; // ["bar", "baz"]
528
528
const keyRecombined = [ [ keyBeforeCurly ] , keyAfterCurlySplitByCommas ] ; // [["foo"], ["baz", "baz"]]
529
529
return keyRecombined
530
530
. reduce (
0 commit comments