@@ -62,47 +62,50 @@ import { complete } from '../utils/complete'
6262 */
6363let cachedGroupsByModifiersAndSelectors = new Map < string , string [ ] > ( )
6464
65- let defaultGroups = [
66- 'type-import' ,
67- [ 'value-builtin' , 'value-external' ] ,
68- 'type-internal' ,
69- 'value-internal' ,
70- [ 'type-parent' , 'type-sibling' , 'type-index' ] ,
71- [ 'value-parent' , 'value-sibling' , 'value-index' ] ,
72- 'ts-equals-import' ,
73- 'unknown' ,
74- ]
75-
7665export type MESSAGE_ID =
7766 | 'unexpectedImportsDependencyOrder'
7867 | 'missedSpacingBetweenImports'
7968 | 'unexpectedImportsGroupOrder'
8069 | 'extraSpacingBetweenImports'
8170 | 'unexpectedImportsOrder'
8271
72+ let defaultOptions : Required <
73+ Omit < Options [ 0 ] , 'tsconfigRootDir' | 'maxLineLength' | 'tsconfig' >
74+ > &
75+ Pick < Options [ 0 ] , 'tsconfigRootDir' | 'maxLineLength' | 'tsconfig' > = {
76+ groups : [
77+ 'type-import' ,
78+ [ 'value-builtin' , 'value-external' ] ,
79+ 'type-internal' ,
80+ 'value-internal' ,
81+ [ 'type-parent' , 'type-sibling' , 'type-index' ] ,
82+ [ 'value-parent' , 'value-sibling' , 'value-index' ] ,
83+ 'ts-equals-import' ,
84+ 'unknown' ,
85+ ] ,
86+ internalPattern : [ '^~/.+' , '^@/.+' ] ,
87+ fallbackSort : { type : 'unsorted' } ,
88+ partitionByComment : false ,
89+ partitionByNewLine : false ,
90+ newlinesBetween : 'always' ,
91+ specialCharacters : 'keep' ,
92+ sortSideEffects : false ,
93+ type : 'alphabetical' ,
94+ environment : 'node' ,
95+ customGroups : [ ] ,
96+ ignoreCase : true ,
97+ locales : 'en-US' ,
98+ alphabet : '' ,
99+ order : 'asc' ,
100+ }
101+
83102export default createEslintRule < Options , MESSAGE_ID > ( {
84103 create : context => {
85104 let settings = getSettings ( context . settings )
86105
87106 let userOptions = context . options . at ( 0 )
88107 let options = getOptionsWithCleanGroups (
89- complete ( userOptions , settings , {
90- internalPattern : [ '^~/.+' , '^@/.+' ] ,
91- fallbackSort : { type : 'unsorted' } ,
92- partitionByComment : false ,
93- partitionByNewLine : false ,
94- newlinesBetween : 'always' ,
95- specialCharacters : 'keep' ,
96- sortSideEffects : false ,
97- groups : defaultGroups ,
98- type : 'alphabetical' ,
99- environment : 'node' ,
100- customGroups : [ ] ,
101- ignoreCase : true ,
102- locales : 'en-US' ,
103- alphabet : '' ,
104- order : 'asc' ,
105- } as const ) ,
108+ complete ( userOptions , settings , defaultOptions ) ,
106109 )
107110
108111 validateGeneratedGroupsConfiguration ( {
@@ -122,9 +125,12 @@ export default createEslintRule<Options, MESSAGE_ID>({
122125 validateNewlinesAndPartitionConfiguration ( options )
123126 validateSideEffectsConfiguration ( options )
124127
125- let tsConfigOutput = options . tsconfigRootDir
128+ let tsconfigRootDirectory =
129+ options . tsconfig ?. rootDir ?? options . tsconfigRootDir
130+ let tsConfigOutput = tsconfigRootDirectory
126131 ? readClosestTsConfigByPath ( {
127- tsconfigRootDir : options . tsconfigRootDir ,
132+ tsconfigFilename : options . tsconfig ?. filename ?? 'tsconfig.json' ,
133+ tsconfigRootDir : tsconfigRootDirectory ,
128134 filePath : context . physicalFilename ,
129135 contextCwd : context . cwd ,
130136 } )
@@ -439,6 +445,21 @@ export default createEslintRule<Options, MESSAGE_ID>({
439445 buildCustomGroupsArrayJsonSchema ( { singleCustomGroupJsonSchema } ) ,
440446 ] ,
441447 } ,
448+ tsconfig : {
449+ properties : {
450+ rootDir : {
451+ description : 'Specifies the tsConfig root directory.' ,
452+ type : 'string' ,
453+ } ,
454+ filename : {
455+ description : 'Specifies the tsConfig filename.' ,
456+ type : 'string' ,
457+ } ,
458+ } ,
459+ additionalProperties : false ,
460+ required : [ 'rootDir' ] ,
461+ type : 'object' ,
462+ } ,
442463 maxLineLength : {
443464 description : 'Specifies the maximum line length.' ,
444465 exclusiveMinimum : true ,
@@ -486,24 +507,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
486507 type : 'suggestion' ,
487508 fixable : 'code' ,
488509 } ,
489- defaultOptions : [
490- {
491- customGroups : { value : { } , type : { } } ,
492- internalPattern : [ '^~/.+' , '^@/.+' ] ,
493- partitionByComment : false ,
494- partitionByNewLine : false ,
495- specialCharacters : 'keep' ,
496- newlinesBetween : 'always' ,
497- sortSideEffects : false ,
498- groups : defaultGroups ,
499- type : 'alphabetical' ,
500- environment : 'node' ,
501- ignoreCase : true ,
502- locales : 'en-US' ,
503- alphabet : '' ,
504- order : 'asc' ,
505- } ,
506- ] ,
510+ defaultOptions : [ defaultOptions ] ,
507511 name : 'sort-imports' ,
508512} )
509513
@@ -594,7 +598,7 @@ let computeGroupExceptUnknown = ({
594598} : {
595599 options : Omit <
596600 Required < Options [ 0 ] > ,
597- 'tsconfigRootDir' | 'maxLineLength' | 'customGroups'
601+ 'tsconfigRootDir' | 'maxLineLength' | 'customGroups' | 'tsconfig'
598602 >
599603 customGroups : DeprecatedCustomGroupsOption | CustomGroupsOption | undefined
600604 selectors ?: Selector [ ]
0 commit comments