1+ import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'
2+ import type { TSESTree } from '@typescript-eslint/types'
3+
4+ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
5+
16import type { Options } from './sort-export-attributes/types'
27
8+ import {
9+ buildUseConfigurationIfJsonSchema ,
10+ matchesAstSelectorJsonSchema ,
11+ buildCommonJsonSchemas ,
12+ } from '../utils/json-schemas/common-json-schemas'
313import {
414 partitionByCommentJsonSchema ,
515 partitionByNewLineJsonSchema ,
@@ -12,7 +22,7 @@ import {
1222} from '../utils/report-errors'
1323import { sortImportOrExportAttributes } from './sort-import-attributes/sort-import-or-export-attributes'
1424import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas'
15- import { buildCommonJsonSchemas } from '../utils/json-schemas/common-json-schemas '
25+ import { buildAstListeners } from '../utils/build-ast-listeners '
1626import { createEslintRule } from '../utils/create-eslint-rule'
1727
1828const ORDER_ERROR_ID = 'unexpectedExportAttributesOrder'
@@ -33,6 +43,7 @@ let defaultOptions: Required<Options[0]> = {
3343 partitionByComment : false ,
3444 partitionByNewLine : false ,
3545 newlinesBetween : 'ignore' ,
46+ useConfigurationIf : { } ,
3647 type : 'alphabetical' ,
3748 ignoreCase : true ,
3849 customGroups : [ ] ,
@@ -49,6 +60,11 @@ export default createEslintRule<Options, MessageId>({
4960 properties : {
5061 ...buildCommonJsonSchemas ( ) ,
5162 ...buildCommonGroupsJsonSchemas ( ) ,
63+ useConfigurationIf : buildUseConfigurationIfJsonSchema ( {
64+ additionalProperties : {
65+ matchesAstSelector : matchesAstSelectorJsonSchema ,
66+ } ,
67+ } ) ,
5268 partitionByComment : partitionByCommentJsonSchema ,
5369 partitionByNewLine : partitionByNewLineJsonSchema ,
5470 } ,
@@ -72,20 +88,35 @@ export default createEslintRule<Options, MessageId>({
7288 type : 'suggestion' ,
7389 fixable : 'code' ,
7490 } ,
75- create : context => ( {
76- ExportNamedDeclaration : node =>
77- sortImportOrExportAttributes ( {
78- availableMessageIds : {
79- missedSpacingBetweenMembers : MISSED_SPACING_ERROR_ID ,
80- extraSpacingBetweenMembers : EXTRA_SPACING_ERROR_ID ,
81- unexpectedGroupOrder : GROUP_ORDER_ERROR_ID ,
82- unexpectedOrder : ORDER_ERROR_ID ,
83- } ,
84- defaultOptions,
85- context,
86- node,
87- } ) ,
88- } ) ,
91+ create : context =>
92+ buildAstListeners ( {
93+ nodeTypes : [ AST_NODE_TYPES . ExportNamedDeclaration ] ,
94+ sorter : sortExportAttributes ,
95+ context,
96+ } ) ,
8997 defaultOptions : [ defaultOptions ] ,
9098 name : 'sort-export-attributes' ,
9199} )
100+
101+ function sortExportAttributes ( {
102+ matchedAstSelectors,
103+ context,
104+ node,
105+ } : {
106+ context : Readonly < RuleContext < MessageId , Options > >
107+ matchedAstSelectors : ReadonlySet < string >
108+ node : TSESTree . ExportNamedDeclaration
109+ } ) : void {
110+ sortImportOrExportAttributes < MessageId > ( {
111+ availableMessageIds : {
112+ missedSpacingBetweenMembers : MISSED_SPACING_ERROR_ID ,
113+ extraSpacingBetweenMembers : EXTRA_SPACING_ERROR_ID ,
114+ unexpectedGroupOrder : GROUP_ORDER_ERROR_ID ,
115+ unexpectedOrder : ORDER_ERROR_ID ,
116+ } ,
117+ matchedAstSelectors,
118+ defaultOptions,
119+ context,
120+ node,
121+ } )
122+ }
0 commit comments