@@ -35,7 +35,7 @@ type Imported = { name: string; rank: number; node: NodeOrToken };
3535
3636function reverse ( array : Imported [ ] ) {
3737 return array
38- . map ( function ( v ) {
38+ . map ( function ( v ) {
3939 return {
4040 name : v . name ,
4141 rank : - v . rank ,
@@ -102,7 +102,7 @@ function findOutOfOrder(imported) {
102102 return [ ] ;
103103 }
104104 let maxSeenRankNode = imported [ 0 ] ;
105- return imported . filter ( function ( importedModule ) {
105+ return imported . filter ( function ( importedModule ) {
106106 const res = importedModule . rank < maxSeenRankNode . rank ;
107107 if ( maxSeenRankNode . rank < importedModule . rank ) {
108108 maxSeenRankNode = importedModule ;
@@ -121,7 +121,7 @@ function findRootNode(node) {
121121
122122function findEndOfLineWithComments ( sourceCode , node ) {
123123 const tokensToEndOfLine = takeTokensAfterWhile ( sourceCode , node , commentOnSameLineAs ( node ) ) ;
124- let endOfTokens =
124+ const endOfTokens =
125125 tokensToEndOfLine . length > 0 ? tokensToEndOfLine [ tokensToEndOfLine . length - 1 ] . range [ 1 ] : node . range [ 1 ] ;
126126 let result = endOfTokens ;
127127 for ( let i = endOfTokens ; i < sourceCode . text . length ; i ++ ) {
@@ -146,7 +146,7 @@ function commentOnSameLineAs(node): (token: NodeOrToken) => boolean {
146146
147147function findStartOfLineWithComments ( sourceCode , node ) {
148148 const tokensToEndOfLine = takeTokensBeforeWhile ( sourceCode , node , commentOnSameLineAs ( node ) ) ;
149- let startOfTokens = tokensToEndOfLine . length > 0 ? tokensToEndOfLine [ 0 ] . range [ 0 ] : node . range [ 0 ] ;
149+ const startOfTokens = tokensToEndOfLine . length > 0 ? tokensToEndOfLine [ 0 ] . range [ 0 ] : node . range [ 0 ] ;
150150 let result = startOfTokens ;
151151 for ( let i = startOfTokens - 1 ; i > 0 ; i -- ) {
152152 if ( sourceCode . text [ i ] !== ' ' && sourceCode . text [ i ] !== '\t' ) {
@@ -192,7 +192,7 @@ function canReorderItems(firstNode: NodeOrToken, secondNode: NodeOrToken): boole
192192 const firstIndex = parent . body . indexOf ( firstNode ) ;
193193 const secondIndex = parent . body . indexOf ( secondNode ) ;
194194 const nodesBetween = parent . body . slice ( firstIndex , secondIndex + 1 ) ;
195- for ( var nodeBetween of nodesBetween ) {
195+ for ( const nodeBetween of nodesBetween ) {
196196 if ( ! canCrossNodeWhileReorder ( nodeBetween ) ) {
197197 return false ;
198198 }
@@ -247,7 +247,7 @@ function fixOutOfOrder(context, firstNode: NodeOrToken, secondNode: NodeOrToken,
247247}
248248
249249function reportOutOfOrder ( context , imported : Imported [ ] , outOfOrder , order : 'before' | 'after' ) : void {
250- outOfOrder . forEach ( function ( imp ) {
250+ outOfOrder . forEach ( function ( imp ) {
251251 const found = imported . find ( function hasHigherRank ( importedItem ) {
252252 return importedItem . rank > imp . rank ;
253253 } ) ;
@@ -271,7 +271,7 @@ function makeOutOfOrderReport(context, imported: Imported[]) {
271271}
272272
273273function mutateRanksToAlphabetize ( imported , order , ignoreCase ) {
274- const groupedByRanks = imported . reduce ( function ( acc , importedItem ) {
274+ const groupedByRanks = imported . reduce ( function ( acc , importedItem ) {
275275 acc [ importedItem . rank ] = acc [ importedItem . rank ] || [ ] ;
276276 acc [ importedItem . rank ] . push ( importedItem . name ) ;
277277 return acc ;
@@ -280,8 +280,8 @@ function mutateRanksToAlphabetize(imported, order, ignoreCase) {
280280 const groupRanks = Object . keys ( groupedByRanks ) ;
281281
282282 // sort imports locally within their group
283- groupRanks . forEach ( function ( groupRank ) {
284- groupedByRanks [ groupRank ] . sort ( function ( importA , importB ) {
283+ groupRanks . forEach ( function ( groupRank ) {
284+ groupedByRanks [ groupRank ] . sort ( function ( importA , importB ) {
285285 return ignoreCase ? importA . localeCompare ( importB ) : importA < importB ? - 1 : importA === importB ? 0 : 1 ;
286286 } ) ;
287287
@@ -291,15 +291,15 @@ function mutateRanksToAlphabetize(imported, order, ignoreCase) {
291291 } ) ;
292292
293293 // add decimal ranking to sort within the group
294- const alphabetizedRanks = groupRanks . sort ( ) . reduce ( function ( acc , groupRank ) {
295- groupedByRanks [ groupRank ] . forEach ( function ( importedItemName , index ) {
294+ const alphabetizedRanks = groupRanks . sort ( ) . reduce ( function ( acc , groupRank ) {
295+ groupedByRanks [ groupRank ] . forEach ( function ( importedItemName , index ) {
296296 acc [ importedItemName ] = + groupRank + index / MAX_GROUP_SIZE ;
297297 } ) ;
298298 return acc ;
299299 } , { } ) ;
300300
301301 // mutate the original group-rank with alphabetized-rank
302- imported . forEach ( function ( importedItem ) {
302+ imported . forEach ( function ( importedItem ) {
303303 importedItem . rank = alphabetizedRanks [ importedItem . name ] ;
304304 } ) ;
305305}
@@ -333,9 +333,9 @@ const knownTypes: KnownImportType[] = ['absolute', 'module', 'parent', 'sibling'
333333// Example: { index: 0, sibling: 1, parent: 1, module: 2 }
334334// Will throw an error if it: contains a type that does not exist in the list, does not start and end with '/', or has a duplicate
335335function convertGroupsToRanks ( groups : Groups ) : Ranks {
336- const rankObject = groups . reduce ( function ( res , group , index ) {
336+ const rankObject = groups . reduce ( function ( res , group , index ) {
337337 if ( typeof group === 'string' ) group = [ group ] ; // wrap them all in arrays
338- group . forEach ( function ( groupItem : ValidImportType ) {
338+ group . forEach ( function ( groupItem : ValidImportType ) {
339339 if ( ! isRegularExpressionGroup ( groupItem ) && knownTypes . indexOf ( groupItem as KnownImportType ) === - 1 ) {
340340 throw new Error (
341341 `Incorrect configuration of the rule: Unknown type ${ JSON . stringify (
@@ -351,11 +351,11 @@ function convertGroupsToRanks(groups: Groups): Ranks {
351351 return res ;
352352 } , { } ) ;
353353
354- const omittedTypes = knownTypes . filter ( function ( type ) {
354+ const omittedTypes = knownTypes . filter ( function ( type ) {
355355 return rankObject [ type ] === undefined ;
356356 } ) ;
357357
358- return omittedTypes . reduce ( function ( res , type ) {
358+ return omittedTypes . reduce ( function ( res , type ) {
359359 res [ type ] = groups . length ;
360360 return res ;
361361 } , rankObject ) ;
@@ -400,7 +400,7 @@ function makeNewlinesBetweenReport(
400400 } ;
401401 let previousImport = imported [ 0 ] ;
402402
403- imported . slice ( 1 ) . forEach ( function ( currentImport ) {
403+ imported . slice ( 1 ) . forEach ( function ( currentImport ) {
404404 const emptyLinesBetween : number = getNumberOfEmptyLinesBetween ( currentImport , previousImport ) ;
405405
406406 const currentGroupRank = Math . floor ( currentImport . rank ) ; // each group rank is a whole number, within a group, decimals indicate subranking. yeah, not great.
@@ -479,7 +479,7 @@ function getAlphabetizeConfig(options: RuleOptions): AlphabetizeConfig {
479479 return { order, ignoreCase } ;
480480}
481481
482- module . exports = {
482+ export default {
483483 meta : {
484484 type : 'suggestion' ,
485485 docs : {
@@ -531,8 +531,8 @@ module.exports = {
531531 } catch ( error ) {
532532 // Malformed configuration
533533 return {
534- Program : function ( node ) {
535- context . report ( node , error . message ) ;
534+ Program : function ( node ) {
535+ context . report ( { node, message : error . message } ) ;
536536 } ,
537537 } ;
538538 }
0 commit comments