1- import { TSESTree } from '@typescript-eslint/utils'
2-
31import { getOptions } from './common/options'
42import { getFixerFunction } from './fixer'
53import { reportBodyNodes , reportParentNode } from './report'
6- import { AllRuleOptions , CreateReporterArgs , NodePositionInfo , TSType } from './types'
4+ import {
5+ AllRuleOptions ,
6+ CreateReporterArgs ,
7+ Declaration ,
8+ NodeOrToken ,
9+ NodePositionInfo ,
10+ } from './types'
711import { getPropertyIsOptional , getPropertyName } from './utils/ast'
812import { compareFn } from './utils/compare'
913import { memoize } from './utils/memo'
@@ -13,9 +17,9 @@ import { getUnsortedInfo } from './utils/reportUtils'
1317 * Returns the body sorted according to the options and sorting function.
1418 */
1519function getSortedBody (
16- body : TSType [ ] ,
20+ body : NodeOrToken [ ] ,
1721 isRequiredFirst : boolean ,
18- sortFunction : ( a : TSType , b : TSType ) => number ,
22+ sortFunction : ( a : NodeOrToken , b : NodeOrToken ) => number ,
1923) {
2024 return isRequiredFirst
2125 ? [
@@ -39,11 +43,11 @@ export function createReporter(
3943 createReporterArgs . context ,
4044 )
4145 const compare = compareFn ( isAscending , isInsensitive , isNatural )
42- const sortFunction = ( a : TSType , b : TSType ) =>
46+ const sortFunction = ( a : NodeOrToken , b : NodeOrToken ) =>
4347 compare ( getPropertyName ( a ) , getPropertyName ( b ) )
4448
4549 // Reporter function
46- return ( bodyParent : TSESTree . Node , body : TSType [ ] ) => {
50+ return ( bodyParent : Declaration , body : NodeOrToken [ ] ) => {
4751 if ( body . length < 2 ) {
4852 return
4953 }
@@ -56,13 +60,13 @@ export function createReporter(
5660 source : sourceCode . getText ( ) , // Disambiguator when same body on both a type and interface
5761 } )
5862
59- const sortedBody : TSType [ ] = memoize ( `sortedBody_${ baseMemoKey } ` , ( ) =>
63+ const sortedBody = memoize ( `sortedBody_${ baseMemoKey } ` , ( ) =>
6064 getSortedBody ( body , isRequiredFirst , sortFunction ) ,
6165 )
62- const nodePositions : Map < TSType , NodePositionInfo > = memoize (
66+ const nodePositions : Map < NodeOrToken , NodePositionInfo > = memoize (
6367 `nodePositions_${ baseMemoKey } ` ,
6468 ( ) =>
65- new Map < TSType , NodePositionInfo > (
69+ new Map < NodeOrToken , NodePositionInfo > (
6670 body . map ( ( n , index ) => [
6771 n ,
6872 { initialIndex : index , finalIndex : sortedBody . indexOf ( n ) } ,
@@ -80,14 +84,9 @@ export function createReporter(
8084 const fixerFunction = memoize ( fixerFunctionMemoKey , ( ) =>
8185 getFixerFunction ( baseMemoKey , createReporterArgs , body , sortedBody ) ,
8286 )
83- reportParentNode ( createReporterArgs , bodyParent , unsortedCount , fixerFunction )
84- reportBodyNodes (
85- createReporterArgs ,
86- nodePositions ,
87- sortedBody ,
88- finalIndicesToReport ,
89- fixerFunction ,
90- )
87+
88+ reportParentNode ( createReporterArgs , bodyParent . loc , unsortedCount , fixerFunction )
89+ reportBodyNodes ( createReporterArgs , nodePositions , sortedBody , finalIndicesToReport )
9190 }
9291 }
9392}
0 commit comments