11"use strict" ;
22
3- module . exports = {
3+ var presetRulesConfig = {
4+ "getify-says" : {
5+ "@getify/proper-arrows/params" : [ "error" , { "unused" : "trailing" , "count" : 2 , "length" : 3 , "allowed" : [ "e" , "v" , "cb" , "fn" , "pr" , ] , } , ] ,
6+ "@getify/proper-arrows/name" : "error" ,
7+ "@getify/proper-arrows/return" : [ "error" , { "ternary" : 1 , } , ] ,
8+ "@getify/proper-arrows/where" : "error" ,
9+ "@getify/proper-arrows/this" : [ "error" , "nested" , { "no-global" : true , } , ] ,
10+ }
11+ } ;
12+
13+ var plugin = {
414 configs : {
515 "getify-says" : {
616 plugins : [ "@getify/proper-arrows" , ] ,
7- rules : {
8- "@getify/proper-arrows/params" : [ "error" , { "unused" : "trailing" , "count" : 2 , "length" : 3 , "allowed" : [ "e" , "v" , "cb" , "fn" , "pr" , ] , } , ] ,
9- "@getify/proper-arrows/name" : "error" ,
10- "@getify/proper-arrows/return" : [ "error" , { "ternary" : 1 , } , ] ,
11- "@getify/proper-arrows/where" : "error" ,
12- "@getify/proper-arrows/this" : [ "error" , "nested" , { "no-global" : true , } , ] ,
13- } ,
14- } ,
17+ rules : presetRulesConfig [ "getify-says" ] ,
18+ }
1519 } ,
1620 rules : {
1721 "params" : {
@@ -110,7 +114,8 @@ module.exports = {
110114
111115 // handle "unused" mode
112116 if ( ! noneUnusedMode ) {
113- let scope = context . getScope ( ) ;
117+ let sourceCode = getSourceCode ( context ) ;
118+ let scope = getScope ( context , sourceCode , node ) ;
114119 let checkParamNames = checkParamIds . map ( function getName ( paramId ) {
115120 return paramId . name ;
116121 } ) ;
@@ -301,7 +306,9 @@ module.exports = {
301306 return ;
302307 }
303308
304- var globalArrow = currentlyInGlobalScope ( context . parserOptions , context . getScope ( ) ) ;
309+ var sourceCode = getSourceCode ( context ) ;
310+ var scope = getScope ( context , sourceCode , node ) ;
311+ var globalArrow = currentlyInGlobalScope ( context . parserOptions , scope ) ;
305312 var globalArrowDeclaration = (
306313 globalArrow &&
307314 node . parent . type == "VariableDeclarator"
@@ -414,12 +421,13 @@ module.exports = {
414421 var sequenceMode = defaultsOnly || ! ( "sequence" in extraOptions ) || extraOptions . sequence === true ;
415422 var ignoreTrivial = ! ( extraOptions && extraOptions . trivial === true ) ;
416423
417- var sourceCode = context . getSourceCode ( ) ;
424+ var sourceCode = getSourceCode ( context ) ;
418425 var ternaryBodyStack = new Map ( ) ;
419426
420427 return {
421428 "ConditionalExpression:exit" : function exit ( node ) {
422- var parentArrow = getParentArrowFunction ( context . getAncestors ( ) , /*onlyFromBody=*/ true ) ;
429+ var ancestors = getAncestors ( context , sourceCode , node ) ;
430+ var parentArrow = getParentArrowFunction ( ancestors , /*onlyFromBody=*/ true ) ;
423431 if ( parentArrow ) {
424432 if ( ! ternaryBodyStack . has ( parentArrow ) ) {
425433 ternaryBodyStack . set ( parentArrow , [ ] ) ;
@@ -562,7 +570,9 @@ module.exports = {
562570
563571 return {
564572 "ThisExpression" : function enter ( node ) {
565- var parentArrow = getParentArrowFunction ( context . getAncestors ( ) ) ;
573+ var sourceCode = getSourceCode ( context ) ;
574+ var ancestors = getAncestors ( context , sourceCode , node ) ;
575+ var parentArrow = getParentArrowFunction ( ancestors ) ;
566576 thisFoundIn . add ( parentArrow ) ;
567577 } ,
568578 "ArrowFunctionExpression:exit" : function exit ( node ) {
@@ -571,7 +581,9 @@ module.exports = {
571581 return ;
572582 }
573583
574- var globalArrow = currentlyInGlobalScope ( context . parserOptions , context . getScope ( ) ) ;
584+ var sourceCode = getSourceCode ( context ) ;
585+ var scope = getScope ( context , sourceCode , node ) ;
586+ var globalArrow = currentlyInGlobalScope ( context . parserOptions , scope ) ;
575587 var foundThis = thisFoundIn . has ( node ) ;
576588
577589 // `this` found in arrow function?
@@ -605,7 +617,8 @@ module.exports = {
605617
606618 // need to track nested `this`?
607619 if ( nestedThis || neverGlobalThis ) {
608- let parentArrow = getParentArrowFunction ( context . getAncestors ( ) ) ;
620+ let ancestors = getAncestors ( context , sourceCode , node ) ;
621+ let parentArrow = getParentArrowFunction ( ancestors ) ;
609622 if ( parentArrow ) {
610623 thisFoundIn . add ( parentArrow ) ;
611624 }
@@ -627,6 +640,16 @@ module.exports = {
627640 } ,
628641} ;
629642
643+ plugin . flatConfigs = {
644+ "getify-says" : {
645+ name : "getify-says" ,
646+ plugins : {
647+ "@getify/proper-arrows" : plugin
648+ } ,
649+ rules : presetRulesConfig [ "getify-says" ] ,
650+ }
651+ }
652+
630653
631654// ***************************
632655
@@ -801,3 +824,32 @@ function currentlyInGlobalScope(parserOptions,scope) {
801824 )
802825 ) ;
803826}
827+
828+ var getSourceCode = context => {
829+ getSourceCode = (
830+ context . sourceCode ?
831+ context => context . sourceCode :
832+ context => context . getSourceCode ( )
833+ ) ;
834+ return getSourceCode ( context ) ;
835+ } ;
836+
837+ var getScope = ( context , sourceCode , node ) => {
838+ getScope = (
839+ sourceCode . getScope ?
840+ ( context , sourceCode , node ) => sourceCode . getScope ( node ) :
841+ ( context , sourceCode , node ) => context . getScope ( )
842+ ) ;
843+ return getScope ( context , sourceCode , node ) ;
844+ } ;
845+
846+ var getAncestors = ( context , sourceCode , node ) => {
847+ getAncestors = (
848+ sourceCode . getAncestors ?
849+ ( context , sourceCode , node ) => sourceCode . getAncestors ( node ) :
850+ ( context , sourceCode , node ) => context . getAncestors ( )
851+ ) ;
852+ return getAncestors ( context , sourceCode , node ) ;
853+ } ;
854+
855+ module . exports = plugin ;
0 commit comments