@borela-tech/eslint-config 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +97 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/rules/__tests__/sortedImports.test.ts +43 -0
- package/src/rules/__tests__/sortedReExports.test.ts +43 -0
- package/src/rules/sortedImports/createFix/index.ts +26 -6
- package/src/rules/sortedImports/getImportGroups.ts +23 -0
- package/src/rules/sortedImports/index.ts +17 -11
- package/src/rules/sortedReExports/createFix/index.ts +26 -7
- package/src/rules/sortedReExports/getReExportGroups.ts +33 -0
- package/src/rules/sortedReExports/index.ts +17 -11
- package/src/rules/sortedImports/getImportDeclarations.ts +0 -8
- package/src/rules/sortedReExports/getReExportDeclarations.ts +0 -12
package/dist/index.js
CHANGED
|
@@ -345,28 +345,6 @@ function buildSortedCode(grouped, sourceCode) {
|
|
|
345
345
|
return sortedCode;
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
// src/rules/sortedImports/createFix/findLastImportIndex.ts
|
|
349
|
-
function findLastImportIndex(programBody) {
|
|
350
|
-
let lastIndex = 0;
|
|
351
|
-
for (let i = 0; i < programBody.length; i++) {
|
|
352
|
-
if (programBody[i].type === "ImportDeclaration")
|
|
353
|
-
lastIndex = i;
|
|
354
|
-
else
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
357
|
-
return lastIndex;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// src/rules/sortedImports/createFix/getReplacementRange.ts
|
|
361
|
-
function getReplacementRange(programBody) {
|
|
362
|
-
const lastIndex = findLastImportIndex(programBody);
|
|
363
|
-
const firstImport = programBody[0];
|
|
364
|
-
const lastImport = programBody[lastIndex];
|
|
365
|
-
const start = firstImport.range[0];
|
|
366
|
-
const end = lastImport.range[1];
|
|
367
|
-
return { start, end };
|
|
368
|
-
}
|
|
369
|
-
|
|
370
348
|
// src/rules/sortedImports/createFix/groupImportsByType.ts
|
|
371
349
|
function groupImportsByType(categorized) {
|
|
372
350
|
const grouped = {
|
|
@@ -389,23 +367,48 @@ function sortImportGroups(grouped) {
|
|
|
389
367
|
}
|
|
390
368
|
|
|
391
369
|
// src/rules/sortedImports/createFix/index.ts
|
|
392
|
-
function
|
|
393
|
-
|
|
370
|
+
function createFixForGroup(fixer, importDeclarations, sourceCode) {
|
|
371
|
+
if (importDeclarations.length === 0) {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
394
374
|
const categorized = categorizeImports(importDeclarations);
|
|
395
375
|
const grouped = groupImportsByType(categorized);
|
|
396
376
|
sortImportGroups(grouped);
|
|
397
377
|
const sortedCode = buildSortedCode(grouped, sourceCode).join("\n");
|
|
378
|
+
const firstImport = importDeclarations[0];
|
|
379
|
+
const lastImport = importDeclarations[importDeclarations.length - 1];
|
|
398
380
|
return fixer.replaceTextRange(
|
|
399
|
-
[range
|
|
381
|
+
[firstImport.range[0], lastImport.range[1]],
|
|
400
382
|
sortedCode
|
|
401
383
|
);
|
|
402
384
|
}
|
|
385
|
+
function createFix(fixer, importGroups, sourceCode) {
|
|
386
|
+
const fixes = [];
|
|
387
|
+
for (const group of importGroups) {
|
|
388
|
+
const fix = createFixForGroup(fixer, group, sourceCode);
|
|
389
|
+
if (fix)
|
|
390
|
+
fixes.push(fix);
|
|
391
|
+
}
|
|
392
|
+
return fixes;
|
|
393
|
+
}
|
|
403
394
|
|
|
404
|
-
// src/rules/sortedImports/
|
|
405
|
-
function
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
)
|
|
395
|
+
// src/rules/sortedImports/getImportGroups.ts
|
|
396
|
+
function getImportGroups(programBody) {
|
|
397
|
+
const groups = [];
|
|
398
|
+
let currentGroup = [];
|
|
399
|
+
for (const statement of programBody) {
|
|
400
|
+
if (statement.type === "ImportDeclaration") {
|
|
401
|
+
currentGroup.push(statement);
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (currentGroup.length > 0) {
|
|
405
|
+
groups.push(currentGroup);
|
|
406
|
+
currentGroup = [];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (currentGroup.length > 0)
|
|
410
|
+
groups.push(currentGroup);
|
|
411
|
+
return groups;
|
|
409
412
|
}
|
|
410
413
|
|
|
411
414
|
// src/rules/sortedImports/index.ts
|
|
@@ -428,22 +431,26 @@ var sortedImports = {
|
|
|
428
431
|
return {
|
|
429
432
|
Program(node) {
|
|
430
433
|
const body = node.body;
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
434
|
+
const importGroups = getImportGroups(body);
|
|
435
|
+
if (importGroups.length === 0)
|
|
433
436
|
return;
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
437
|
+
const allErrors = [];
|
|
438
|
+
for (const group of importGroups) {
|
|
439
|
+
const categorized = categorizeImports(group);
|
|
440
|
+
const errors = [
|
|
441
|
+
...checkGroupOrdering(categorized),
|
|
442
|
+
...checkAlphabeticalSorting(categorized),
|
|
443
|
+
...checkSpecifiersSorting(categorized)
|
|
444
|
+
];
|
|
445
|
+
allErrors.push(...errors);
|
|
446
|
+
}
|
|
447
|
+
for (const error of allErrors) {
|
|
441
448
|
context.report({
|
|
442
449
|
node: error.node,
|
|
443
450
|
messageId: error.messageId,
|
|
444
451
|
fix(fixer) {
|
|
445
452
|
const sourceCode = context.sourceCode;
|
|
446
|
-
return createFix(fixer,
|
|
453
|
+
return createFix(fixer, importGroups, sourceCode);
|
|
447
454
|
}
|
|
448
455
|
});
|
|
449
456
|
}
|
|
@@ -608,40 +615,6 @@ function buildSortedCode2(grouped, sourceCode) {
|
|
|
608
615
|
return sortedCode;
|
|
609
616
|
}
|
|
610
617
|
|
|
611
|
-
// src/rules/sortedReExports/createFix/findFirstExportIndex.ts
|
|
612
|
-
function findFirstExportIndex(programBody) {
|
|
613
|
-
for (let i = 0; i < programBody.length; i++) {
|
|
614
|
-
if (programBody[i].type === "ExportNamedDeclaration" || programBody[i].type === "ExportAllDeclaration") {
|
|
615
|
-
return i;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
return -1;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// src/rules/sortedReExports/createFix/findLastExportIndex.ts
|
|
622
|
-
function findLastExportIndex(programBody) {
|
|
623
|
-
let lastIndex = -1;
|
|
624
|
-
for (let i = 0; i < programBody.length; i++) {
|
|
625
|
-
if (programBody[i].type === "ExportNamedDeclaration" || programBody[i].type === "ExportAllDeclaration") {
|
|
626
|
-
lastIndex = i;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return lastIndex;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/rules/sortedReExports/createFix/getReplacementRange.ts
|
|
633
|
-
function getReplacementRange2(programBody) {
|
|
634
|
-
const firstIndex = findFirstExportIndex(programBody);
|
|
635
|
-
const lastIndex = findLastExportIndex(programBody);
|
|
636
|
-
if (firstIndex === -1 || lastIndex === -1)
|
|
637
|
-
return { start: 0, end: 0 };
|
|
638
|
-
const firstExport = programBody[firstIndex];
|
|
639
|
-
const lastExport = programBody[lastIndex];
|
|
640
|
-
const start = firstExport.range[0];
|
|
641
|
-
const end = lastExport.range[1];
|
|
642
|
-
return { start, end };
|
|
643
|
-
}
|
|
644
|
-
|
|
645
618
|
// src/rules/sortedReExports/createFix/groupReExportsByType.ts
|
|
646
619
|
function groupReExportsByType(categorized) {
|
|
647
620
|
const grouped = {
|
|
@@ -662,23 +635,51 @@ function sortExportGroups(grouped) {
|
|
|
662
635
|
}
|
|
663
636
|
|
|
664
637
|
// src/rules/sortedReExports/createFix/index.ts
|
|
665
|
-
function
|
|
666
|
-
|
|
638
|
+
function createFixForGroup2(fixer, reExportDeclarations, sourceCode) {
|
|
639
|
+
if (reExportDeclarations.length === 0) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
667
642
|
const categorized = categorizeReExports(reExportDeclarations);
|
|
668
643
|
const grouped = groupReExportsByType(categorized);
|
|
669
644
|
sortExportGroups(grouped);
|
|
670
645
|
const sortedCode = buildSortedCode2(grouped, sourceCode).join("\n");
|
|
646
|
+
const firstReExport = reExportDeclarations[0];
|
|
647
|
+
const lastReExport = reExportDeclarations[reExportDeclarations.length - 1];
|
|
671
648
|
return fixer.replaceTextRange(
|
|
672
|
-
[range
|
|
649
|
+
[firstReExport.range[0], lastReExport.range[1]],
|
|
673
650
|
sortedCode
|
|
674
651
|
);
|
|
675
652
|
}
|
|
653
|
+
function createFix2(fixer, reExportGroups, sourceCode) {
|
|
654
|
+
const fixes = [];
|
|
655
|
+
for (const group of reExportGroups) {
|
|
656
|
+
const fix = createFixForGroup2(fixer, group, sourceCode);
|
|
657
|
+
if (fix)
|
|
658
|
+
fixes.push(fix);
|
|
659
|
+
}
|
|
660
|
+
return fixes;
|
|
661
|
+
}
|
|
676
662
|
|
|
677
|
-
// src/rules/sortedReExports/
|
|
678
|
-
function
|
|
679
|
-
return
|
|
680
|
-
|
|
681
|
-
|
|
663
|
+
// src/rules/sortedReExports/getReExportGroups.ts
|
|
664
|
+
function isReExportDeclaration(statement) {
|
|
665
|
+
return statement.type === "ExportNamedDeclaration" && statement.source !== null || statement.type === "ExportAllDeclaration";
|
|
666
|
+
}
|
|
667
|
+
function getReExportGroups(programBody) {
|
|
668
|
+
const groups = [];
|
|
669
|
+
let currentGroup = [];
|
|
670
|
+
for (const statement of programBody) {
|
|
671
|
+
if (isReExportDeclaration(statement)) {
|
|
672
|
+
currentGroup.push(statement);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
if (currentGroup.length > 0) {
|
|
676
|
+
groups.push(currentGroup);
|
|
677
|
+
currentGroup = [];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (currentGroup.length > 0)
|
|
681
|
+
groups.push(currentGroup);
|
|
682
|
+
return groups;
|
|
682
683
|
}
|
|
683
684
|
|
|
684
685
|
// src/rules/sortedReExports/index.ts
|
|
@@ -701,22 +702,26 @@ var sortedReExports = {
|
|
|
701
702
|
return {
|
|
702
703
|
Program(node) {
|
|
703
704
|
const body = node.body;
|
|
704
|
-
const
|
|
705
|
-
if (
|
|
705
|
+
const reExportGroups = getReExportGroups(body);
|
|
706
|
+
if (reExportGroups.length === 0)
|
|
706
707
|
return;
|
|
707
|
-
const
|
|
708
|
-
const
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
708
|
+
const allErrors = [];
|
|
709
|
+
for (const group of reExportGroups) {
|
|
710
|
+
const categorized = categorizeReExports(group);
|
|
711
|
+
const errors = [
|
|
712
|
+
...checkGroupOrdering2(categorized),
|
|
713
|
+
...checkAlphabeticalSorting2(categorized),
|
|
714
|
+
...checkSpecifiersSorting2(categorized)
|
|
715
|
+
];
|
|
716
|
+
allErrors.push(...errors);
|
|
717
|
+
}
|
|
718
|
+
for (const error of allErrors) {
|
|
714
719
|
context.report({
|
|
715
720
|
node: error.node,
|
|
716
721
|
messageId: error.messageId,
|
|
717
722
|
fix(fixer) {
|
|
718
723
|
const sourceCode = context.sourceCode;
|
|
719
|
-
return createFix2(fixer,
|
|
724
|
+
return createFix2(fixer, reExportGroups, sourceCode);
|
|
720
725
|
}
|
|
721
726
|
});
|
|
722
727
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/rules/importsAndReExportsAtTop/getStatementType.ts","../src/rules/importsAndReExportsAtTop/categorizeStatements.ts","../src/rules/importsAndReExportsAtTop/findFirstIndices.ts","../src/rules/importsAndReExportsAtTop/generateSortedText.ts","../src/rules/importsAndReExportsAtTop/hasViolation.ts","../src/rules/importsAndReExportsAtTop/index.ts","../src/rules/individualImports.ts","../src/rules/individualReExports.ts","../src/rules/sortedImports/categorizeImport.ts","../src/rules/sortedImports/getSortKey.ts","../src/rules/sortedImports/categorizeImports.ts","../src/lib/compare.ts","../src/rules/sortedImports/ImportGroupOrder.ts","../src/rules/sortedImports/checkAlphabeticalSorting.ts","../src/rules/sortedImports/checkGroupOrdering.ts","../src/rules/sortedImports/getSpecifierName.ts","../src/rules/sortedImports/areSpecifiersSorted.ts","../src/rules/sortedImports/getNamedSpecifiers.ts","../src/rules/sortedImports/checkSpecifiersSorting.ts","../src/rules/sortedImports/sortSpecifiersText.ts","../src/rules/sortedImports/createFix/formatNamedImport.ts","../src/rules/sortedImports/createFix/buildSortedCode.ts","../src/rules/sortedImports/createFix/findLastImportIndex.ts","../src/rules/sortedImports/createFix/getReplacementRange.ts","../src/rules/sortedImports/createFix/groupImportsByType.ts","../src/rules/sortedImports/createFix/sortImportGroups.ts","../src/rules/sortedImports/createFix/index.ts","../src/rules/sortedImports/getImportDeclarations.ts","../src/rules/sortedImports/index.ts","../src/rules/sortedReExports/categorizeReExport.ts","../src/rules/sortedReExports/getSortKey.ts","../src/rules/sortedReExports/categorizeReExports.ts","../src/rules/sortedReExports/ReExportGroupOrder.ts","../src/rules/sortedReExports/checkAlphabeticalSorting.ts","../src/rules/sortedReExports/checkGroupOrdering.ts","../src/rules/sortedReExports/getSpecifierName.ts","../src/rules/sortedReExports/areSpecifiersSorted.ts","../src/rules/sortedReExports/getNamedSpecifiers.ts","../src/rules/sortedReExports/isNamedReExport.ts","../src/rules/sortedReExports/checkSpecifiersSorting.ts","../src/rules/sortedReExports/sortSpecifiersText.ts","../src/rules/sortedReExports/createFix/formatNamedReExport.ts","../src/rules/sortedReExports/createFix/buildSortedCode.ts","../src/rules/sortedReExports/createFix/findFirstExportIndex.ts","../src/rules/sortedReExports/createFix/findLastExportIndex.ts","../src/rules/sortedReExports/createFix/getReplacementRange.ts","../src/rules/sortedReExports/createFix/groupReExportsByType.ts","../src/rules/sortedReExports/createFix/sortExportGroups.ts","../src/rules/sortedReExports/createFix/index.ts","../src/rules/sortedReExports/getReExportDeclarations.ts","../src/rules/sortedReExports/index.ts"],"sourcesContent":["import eslint from '@eslint/js'\nimport react from 'eslint-plugin-react'\nimport reactHooks from 'eslint-plugin-react-hooks'\nimport stylistic from '@stylistic/eslint-plugin'\nimport typescript from 'typescript-eslint'\nimport {defineConfig} from 'eslint/config'\nimport {importsAndReExportsAtTop} from './rules/importsAndReExportsAtTop'\nimport {individualImports} from './rules/individualImports'\nimport {individualReExports} from './rules/individualReExports'\nimport {sortedImports} from './rules/sortedImports'\nimport {sortedReExports} from './rules/sortedReExports'\n\nexport const CONFIG = defineConfig([\n {\n ignores: [\n 'src/graphql/sdk.ts',\n '**/node_modules/**',\n '**/dist/**',\n ],\n },\n {\n settings: {\n react: {\n version: '19',\n },\n },\n },\n eslint.configs.recommended,\n react.configs.flat.recommended,\n stylistic.configs.recommended,\n typescript.configs.recommended,\n typescript.configs.stylistic,\n {\n plugins: {\n 'react-hooks': reactHooks,\n },\n rules: reactHooks.configs.recommended.rules,\n },\n {\n plugins: {\n '@borela-tech': {\n rules: {\n 'imports-and-re-exports-at-top': importsAndReExportsAtTop,\n 'individual-imports': individualImports,\n 'individual-re-exports': individualReExports,\n 'sorted-imports': sortedImports,\n 'sorted-re-exports': sortedReExports,\n },\n },\n },\n rules: {\n '@borela-tech/imports-and-re-exports-at-top': 'error',\n '@borela-tech/individual-imports': 'error',\n '@borela-tech/individual-re-exports': 'error',\n '@borela-tech/sorted-imports': 'error',\n '@borela-tech/sorted-re-exports': 'error',\n },\n },\n {\n rules: {\n 'capitalized-comments': [\n 'error',\n 'always',\n {ignoreConsecutiveComments: true},\n ],\n 'react/react-in-jsx-scope': 'off',\n '@stylistic/arrow-parens': [\n 'error',\n 'as-needed',\n ],\n '@stylistic/array-bracket-newline': [\n 'error',\n 'consistent',\n ],\n '@stylistic/array-bracket-spacing': [\n 'error',\n 'never',\n ],\n '@stylistic/array-element-newline': [\n 'error',\n 'consistent',\n ],\n '@stylistic/block-spacing': 'off',\n '@stylistic/brace-style': [\n 'error',\n '1tbs',\n {allowSingleLine: true},\n ],\n '@stylistic/indent': [\n 'error',\n 2,\n {ignoredNodes: ['TSMappedType > *']},\n ],\n '@stylistic/jsx-tag-spacing': [\n 'error',\n {\n afterOpening: 'never',\n beforeClosing: 'never',\n beforeSelfClosing: 'never',\n closingSlash: 'never',\n },\n ],\n '@stylistic/jsx-wrap-multilines': 'off',\n '@stylistic/lines-between-class-members': 'off',\n '@stylistic/object-curly-newline': [\n 'error',\n {consistent: true},\n ],\n '@stylistic/object-curly-spacing': [\n 'error',\n 'never',\n ],\n '@stylistic/operator-linebreak': [\n 'error',\n 'before',\n {overrides: {'=': 'after'}},\n ],\n '@stylistic/quotes': [\n 'error',\n 'single',\n {avoidEscape: true},\n ],\n '@stylistic/quote-props': [\n 'error',\n 'as-needed',\n ],\n '@stylistic/semi': [\n 'error',\n 'never',\n {beforeStatementContinuationChars: 'always'},\n ],\n '@typescript-eslint/no-empty-function': 'off',\n '@typescript-eslint/consistent-indexed-object-style': 'off',\n },\n },\n])\n","import {StatementType} from './statementType'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getStatementType(statement: TSESTree.Statement): StatementType {\n if (statement.type === 'ImportDeclaration')\n return 'import'\n\n if (statement.type === 'ExportAllDeclaration')\n return 're-export'\n\n if (statement.type === 'ExportNamedDeclaration') {\n if (statement.source !== null)\n return 're-export'\n }\n\n return 'other'\n}\n","import {getStatementType} from './getStatementType'\nimport {ReExport} from './ReExport'\nimport type {CategorizedStatements} from './CategorizedStatements'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeStatements(\n statements: TSESTree.Statement[],\n): CategorizedStatements {\n const result: CategorizedStatements = {\n imports: [],\n reExports: [],\n other: [],\n }\n\n for (const statement of statements) {\n const type = getStatementType(statement)\n\n if (type === 'import')\n result.imports.push(statement as TSESTree.ImportDeclaration)\n else if (type === 're-export')\n result.reExports.push(statement as ReExport)\n else\n result.other.push(statement)\n }\n\n return result\n}\n","import {getStatementType} from './getStatementType'\nimport type {StatementIndices} from './StatementIndices'\nimport type {StatementType} from './statementType'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function findFirstIndices(\n statements: TSESTree.Statement[],\n): StatementIndices {\n let firstImport = Infinity\n let firstReExport = Infinity\n let firstOther = -1\n\n for (let i = 0; i < statements.length; i++) {\n const type: StatementType = getStatementType(statements[i])\n\n if (type === 'import' && firstImport === Infinity)\n firstImport = i\n else if (type === 're-export' && firstReExport === Infinity)\n firstReExport = i\n else if (type === 'other' && firstOther === -1)\n firstOther = i\n }\n\n return {firstImport, firstReExport, firstOther}\n}\n","import {Rule} from 'eslint'\nimport type {CategorizedStatements} from './CategorizedStatements'\nimport type {Node as ESTreeNode} from 'estree'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function generateSortedText(\n context: Rule.RuleContext,\n categories: CategorizedStatements,\n): string {\n const allStatements: TSESTree.Node[] = [\n ...categories.imports,\n ...categories.reExports,\n ...categories.other,\n ]\n return allStatements.map(\n node => context.sourceCode.getText(node as ESTreeNode),\n ).join('\\n')\n}\n","import type {CategorizedStatements} from './CategorizedStatements'\nimport type {StatementIndices} from './StatementIndices'\n\nexport function hasViolation(\n indices: StatementIndices,\n categories: CategorizedStatements,\n): boolean {\n const {\n firstImport,\n firstReExport,\n firstOther,\n } = indices\n\n // No imports or no re-exports.\n if (categories.imports.length === 0 || categories.reExports.length === 0)\n return false\n\n const firstImportOrReExport = Math.min(firstImport, firstReExport)\n const hasOtherBeforeImportOrReExport =\n firstOther !== -1 && firstOther < firstImportOrReExport\n\n // Violation if:\n // 1. Other statements appear before imports/re-exports.\n // 2. Re-exports appear before imports.\n if (hasOtherBeforeImportOrReExport || firstImport > firstReExport)\n return true\n\n return false\n}\n","import {categorizeStatements} from './categorizeStatements'\nimport {findFirstIndices} from './findFirstIndices'\nimport {generateSortedText} from './generateSortedText'\nimport {hasViolation} from './hasViolation'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const importsAndReExportsAtTop: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Enforce imports and re-exports at the top of the file',\n recommended: false,\n },\n fixable: 'code',\n messages: {\n importsAndReExportsAtTop:\n 'Imports and re-exports should be at the top of the file.',\n },\n schema: [],\n },\n\n create(context) {\n return {\n Program(node) {\n const statements = node.body as TSESTree.Statement[]\n const categories = categorizeStatements(statements)\n const indices = findFirstIndices(statements)\n\n if (!hasViolation(indices, categories))\n return\n\n context.report({\n node,\n messageId: 'importsAndReExportsAtTop',\n\n fix(fixer) {\n const sortedText = generateSortedText(context, categories)\n return fixer.replaceText(node, sortedText)\n },\n })\n },\n }\n },\n}\n","import type {Rule} from 'eslint'\n\nexport const individualImports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce individual imports instead of grouped imports',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n individualImports: 'Use individual imports instead of grouped imports.',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n ImportDeclaration(node) {\n if (node.specifiers.length <= 1)\n return\n\n context.report({\n node,\n messageId: 'individualImports',\n fix(fixer) {\n const source = node.source.raw\n const specifiers = node.specifiers\n .filter(s => s.type === 'ImportSpecifier')\n .map(s => `import {${s.local.name}} from ${source}`)\n .join('\\n')\n return fixer.replaceText(node, specifiers)\n },\n })\n },\n }\n },\n}\n","import type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const individualReExports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce individual exports instead of grouped exports',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n individualReExports: 'Use individual exports instead of grouped exports.',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n ExportNamedDeclaration(node) {\n const exportNode = node as TSESTree.ExportNamedDeclaration\n if (!exportNode.source || exportNode.specifiers.length <= 1)\n return\n\n context.report({\n node,\n messageId: 'individualReExports',\n fix(fixer) {\n const source = exportNode.source!.value\n const typeKeyword = exportNode.exportKind === 'type'\n ? 'type '\n : ''\n const specifiers = exportNode.specifiers\n .map(s => {\n const localName = s.local.type === 'Identifier'\n ? s.local.name\n : s.local.value\n const exportedName = s.exported.type === 'Identifier'\n ? s.exported.name\n : s.exported.value\n const name = localName === exportedName\n ? localName\n : `${localName} as ${exportedName}`\n return `export ${typeKeyword}{${name}} from '${source}'`\n })\n .join('\\n')\n return fixer.replaceText(node, specifiers)\n },\n })\n },\n }\n },\n}\n","import type {ImportGroup} from './ImportGroup'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeImport(declaration: TSESTree.ImportDeclaration): ImportGroup {\n // Example: import type {Type} from 'module'\n if (declaration.importKind === 'type')\n return 'type'\n\n // Example: import 'module'\n if (declaration.specifiers.length === 0)\n return 'side-effect'\n\n // Example: import value from 'module'\n if (declaration.specifiers.some(s => s.type === 'ImportDefaultSpecifier'))\n return 'default'\n\n // Example: import {value} from 'module'\n return 'named'\n}\n","import {categorizeImport} from './categorizeImport'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSortKey(declaration: TSESTree.ImportDeclaration): string {\n const group = categorizeImport(declaration)\n\n if (group === 'side-effect')\n return declaration.source.value\n\n if (group === 'default') {\n const defaultSpecifier = declaration.specifiers.find(\n s => s.type === 'ImportDefaultSpecifier',\n ) as TSESTree.ImportDefaultSpecifier | undefined\n\n return defaultSpecifier?.local.name ?? ''\n }\n\n const specifier = declaration.specifiers[0]\n return specifier.local.name\n}\n","import {categorizeImport} from './categorizeImport'\nimport {getSortKey} from './getSortKey'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeImports(declarations: TSESTree.ImportDeclaration[]): CategorizedImport[] {\n return declarations.map(declaration => ({\n declaration,\n group: categorizeImport(declaration),\n sortKey: getSortKey(declaration),\n }))\n}\n","export function compare(a: string, b: string): number {\n return a.localeCompare(b, 'en', {sensitivity: 'case'})\n}\n","import {ImportGroup} from './ImportGroup'\n\nexport const importGroupOrder: ImportGroup[] = [\n 'side-effect',\n 'default',\n 'named',\n 'type',\n]\n","import {compare} from '../../lib/compare'\nimport {importGroupOrder} from './ImportGroupOrder'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {ImportError} from './ImportError'\n\nexport function checkAlphabeticalSorting(categorized: CategorizedImport[]): ImportError[] {\n const errors: ImportError[] = []\n\n for (const group of importGroupOrder) {\n const groupImports = categorized.filter(c => c.group === group)\n const sorted = [...groupImports].sort((a, b) => compare(a.sortKey, b.sortKey))\n for (let i = 0; i < groupImports.length; i++) {\n if (groupImports[i] !== sorted[i]) {\n errors.push({\n node: groupImports[i].declaration,\n messageId: 'sortedImports',\n })\n }\n }\n }\n\n return errors\n}\n","import {importGroupOrder} from './ImportGroupOrder'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {ImportError} from './ImportError'\n\nexport function checkGroupOrdering(categorized: CategorizedImport[]): ImportError[] {\n const errors: ImportError[] = []\n\n let currentGroupIndex = -1\n for (const {declaration, group} of categorized) {\n const groupIndex = importGroupOrder.indexOf(group)\n if (groupIndex < currentGroupIndex) {\n errors.push({\n node: declaration,\n messageId: 'wrongGroup',\n })\n } else\n currentGroupIndex = groupIndex\n }\n\n return errors\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSpecifierName(specifier: TSESTree.ImportSpecifier): string {\n return specifier.imported.type === 'Identifier'\n ? specifier.imported.name\n : String(specifier.imported.value)\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function areSpecifiersSorted(specifiers: TSESTree.ImportSpecifier[]): boolean {\n const names = specifiers.map(s => getSpecifierName(s))\n const sorted = [...names].sort((a, b) => compare(a, b))\n return names.every((name, i) => name === sorted[i])\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getNamedSpecifiers(declaration: TSESTree.ImportDeclaration): TSESTree.ImportSpecifier[] {\n return declaration.specifiers.filter(\n (s): s is TSESTree.ImportSpecifier => s.type === 'ImportSpecifier',\n )\n}\n","import {areSpecifiersSorted} from './areSpecifiersSorted'\nimport {getNamedSpecifiers} from './getNamedSpecifiers'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {ImportError} from './ImportError'\n\nexport function checkSpecifiersSorting(categorized: CategorizedImport[]): ImportError[] {\n const errors: ImportError[] = []\n const namedImports = categorized.filter(c => c.group === 'named')\n\n for (const {declaration} of namedImports) {\n const specifiers = getNamedSpecifiers(declaration)\n if (specifiers.length > 1 && !areSpecifiersSorted(specifiers)) {\n errors.push({\n node: declaration,\n messageId: 'sortedNames',\n })\n }\n }\n\n return errors\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function sortSpecifiersText(\n specifiers: TSESTree.ImportSpecifier[],\n sourceCode: {getText: (node: TSESTree.ImportSpecifier) => string},\n): string {\n const sorted = [...specifiers].sort((a, b) => {\n const nameA = getSpecifierName(a)\n const nameB = getSpecifierName(b)\n return compare(nameA, nameB)\n })\n return sorted.map(s => sourceCode.getText(s)).join(', ')\n}\n","import {areSpecifiersSorted} from '../areSpecifiersSorted'\nimport {getNamedSpecifiers} from '../getNamedSpecifiers'\nimport {sortSpecifiersText} from '../sortSpecifiersText'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function formatNamedImport(\n declaration: TSESTree.ImportDeclaration,\n sourceCode: {getText: (node?: unknown) => string},\n): string {\n const specifiers = getNamedSpecifiers(declaration)\n\n if (specifiers.length > 1 && !areSpecifiersSorted(specifiers)) {\n const sortedSpecifiers = sortSpecifiersText(specifiers, sourceCode)\n const source = declaration.source.value\n const prefix = declaration.importKind === 'type' ? 'import type ' : 'import '\n return `${prefix}{${sortedSpecifiers}} from '${source}'`\n }\n\n return sourceCode.getText(declaration)\n}\n","import {formatNamedImport} from './formatNamedImport'\nimport {importGroupOrder} from '../ImportGroupOrder'\nimport type {CategorizedImport} from '../CategorizedImport'\nimport type {ImportGroup} from '../ImportGroup'\n\nexport function buildSortedCode(\n grouped: Record<ImportGroup, CategorizedImport[]>,\n sourceCode: {getText: (node?: unknown) => string},\n): string[] {\n const sortedCode: string[] = []\n\n for (const group of importGroupOrder) {\n for (const {declaration} of grouped[group]) {\n if (group === 'named' || group === 'type')\n sortedCode.push(formatNamedImport(declaration, sourceCode))\n else\n sortedCode.push(sourceCode.getText(declaration))\n }\n }\n\n return sortedCode\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function findLastImportIndex(programBody: TSESTree.ProgramStatement[]): number {\n let lastIndex = 0\n for (let i = 0; i < programBody.length; i++) {\n if (programBody[i].type === 'ImportDeclaration')\n lastIndex = i\n else\n break\n }\n return lastIndex\n}\n","import {findLastImportIndex} from './findLastImportIndex'\nimport type {ReplacementRange} from '../../../lib/ReplacementRange'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getReplacementRange(\n programBody: TSESTree.ProgramStatement[],\n): ReplacementRange {\n const lastIndex = findLastImportIndex(programBody)\n const firstImport = programBody[0] as TSESTree.ImportDeclaration\n const lastImport = programBody[lastIndex] as TSESTree.ImportDeclaration\n const start = firstImport.range![0]\n const end = lastImport.range![1]\n return {start, end}\n}\n","import type {CategorizedImport} from '../CategorizedImport'\nimport type {ImportGroup} from '../ImportGroup'\n\nexport function groupImportsByType(\n categorized: CategorizedImport[],\n): Record<ImportGroup, CategorizedImport[]> {\n const grouped: Record<ImportGroup, CategorizedImport[]> = {\n 'side-effect': [],\n default: [],\n named: [],\n type: [],\n }\n\n for (const item of categorized)\n grouped[item.group].push(item)\n\n return grouped\n}\n","import {compare} from '../../../lib/compare'\nimport type {CategorizedImport} from '../CategorizedImport'\nimport type {ImportGroup} from '../ImportGroup'\n\nexport function sortImportGroups(\n grouped: Record<ImportGroup, CategorizedImport[]>,\n): void {\n grouped['side-effect'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['default'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['named'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['type'].sort((a, b) => compare(a.sortKey, b.sortKey))\n}\n","import {buildSortedCode} from './buildSortedCode'\nimport {categorizeImports} from '../categorizeImports'\nimport {getReplacementRange} from './getReplacementRange'\nimport {groupImportsByType} from './groupImportsByType'\nimport {sortImportGroups} from './sortImportGroups'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function createFix(\n fixer: Rule.RuleFixer,\n importDeclarations: TSESTree.ImportDeclaration[],\n sourceCode: {getText: (node?: unknown) => string},\n programBody: TSESTree.ProgramStatement[],\n) {\n const range = getReplacementRange(programBody)\n const categorized = categorizeImports(importDeclarations)\n const grouped = groupImportsByType(categorized)\n\n sortImportGroups(grouped)\n\n const sortedCode = buildSortedCode(grouped, sourceCode)\n .join('\\n')\n\n return fixer.replaceTextRange(\n [range.start, range.end],\n sortedCode,\n )\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getImportDeclarations(programBody: TSESTree.ProgramStatement[]): TSESTree.ImportDeclaration[] {\n return programBody.filter(\n (statement): statement is TSESTree.ImportDeclaration =>\n statement.type === 'ImportDeclaration',\n )\n}\n","import {categorizeImports} from './categorizeImports'\nimport {checkAlphabeticalSorting} from './checkAlphabeticalSorting'\nimport {checkGroupOrdering} from './checkGroupOrdering'\nimport {checkSpecifiersSorting} from './checkSpecifiersSorting'\nimport {createFix} from './createFix'\nimport {getImportDeclarations} from './getImportDeclarations'\nimport type {ImportError} from './ImportError'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const sortedImports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce sorted imports alphabetically',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n sortedImports: 'Imports should be sorted alphabetically',\n sortedNames: 'Named imports should be sorted alphabetically',\n wrongGroup: 'Import is in wrong group',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n Program(node) {\n const body = node.body as TSESTree.ProgramStatement[]\n const declarations = getImportDeclarations(body)\n if (declarations.length === 0)\n return\n\n const categorized = categorizeImports(declarations)\n const errors: ImportError[] = [\n ...checkGroupOrdering(categorized),\n ...checkAlphabeticalSorting(categorized),\n ...checkSpecifiersSorting(categorized),\n ]\n\n for (const error of errors) {\n context.report({\n node: error.node,\n messageId: error.messageId,\n fix(fixer) {\n const sourceCode = context.sourceCode\n return createFix(fixer, declarations, sourceCode, body)\n },\n })\n }\n },\n }\n },\n}\n","import type {ReExportGroup} from './ReExportGroup'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeReExport(\n declaration: TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration,\n): ReExportGroup {\n // Example: export * from 'module'\n if (declaration.type === 'ExportAllDeclaration')\n return 're-export-all'\n\n // Example: export type {Type} from 'module'\n if (declaration.exportKind === 'type')\n return 're-export-type'\n\n // Example: export {value} from 'module'\n return 're-export-named'\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSortKey(\n declaration: TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration,\n): string {\n if (declaration.type === 'ExportAllDeclaration')\n return declaration.source.value\n\n const specifier = declaration.specifiers[0]\n if (!specifier)\n return ''\n\n return specifier.local.type === 'Identifier'\n ? specifier.local.name\n : specifier.local.value\n}\n","import {categorizeReExport} from './categorizeReExport'\nimport {getSortKey} from './getSortKey'\nimport {ReExportDeclaration} from './ReExportDeclaration'\nimport type {CategorizedReExport} from './CategorizedReExport'\n\nexport function categorizeReExports(declarations: ReExportDeclaration[]): CategorizedReExport[] {\n return declarations.map(declaration => {\n return {\n declaration,\n group: categorizeReExport(declaration),\n sortKey: getSortKey(declaration),\n } as CategorizedReExport\n })\n}\n","import {ReExportGroup} from './ReExportGroup'\n\nexport const reExportGroupOrder: ReExportGroup[] = [\n 're-export-all',\n 're-export-named',\n 're-export-type',\n]\n","import {compare} from '../../lib/compare'\nimport {reExportGroupOrder} from './ReExportGroupOrder'\nimport type {CategorizedReExport} from './CategorizedReExport'\nimport type {ReExportError} from './ReExportError'\n\nexport function checkAlphabeticalSorting(categorized: CategorizedReExport[]): ReExportError[] {\n const errors: ReExportError[] = []\n\n for (const group of reExportGroupOrder) {\n const groupReExports = categorized.filter(c => c.group === group)\n const sorted = [...groupReExports].sort((a, b) =>\n compare(a.sortKey, b.sortKey),\n )\n for (let i = 0; i < groupReExports.length; i++) {\n if (groupReExports[i] !== sorted[i]) {\n errors.push({\n node: groupReExports[i].declaration,\n messageId: 'sortedReExports',\n })\n }\n }\n }\n\n return errors\n}\n","import {reExportGroupOrder} from './ReExportGroupOrder'\nimport type {CategorizedReExport} from './CategorizedReExport'\nimport type {ReExportError} from './ReExportError'\n\nexport function checkGroupOrdering(categorized: CategorizedReExport[]): ReExportError[] {\n const errors: ReExportError[] = []\n\n let currentGroupIndex = -1\n for (const {declaration, group} of categorized) {\n const groupIndex = reExportGroupOrder.indexOf(group)\n if (groupIndex < currentGroupIndex) {\n errors.push({\n node: declaration,\n messageId: 'wrongGroup',\n })\n } else\n currentGroupIndex = groupIndex\n }\n\n return errors\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSpecifierName(specifier: TSESTree.ExportSpecifier): string {\n return specifier.local.type === 'Identifier'\n ? specifier.local.name\n : String(specifier.local.value)\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function areSpecifiersSorted(specifiers: TSESTree.ExportSpecifier[]): boolean {\n const names = specifiers.map(s => getSpecifierName(s))\n const sorted = [...names].sort((a, b) => compare(a, b))\n return names.every((name, i) => name === sorted[i])\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getNamedSpecifiers(\n declaration: TSESTree.ExportNamedDeclaration,\n): TSESTree.ExportSpecifier[] {\n return declaration.specifiers.filter(\n s => s.type === 'ExportSpecifier' && s.local.type === 'Identifier',\n ) as TSESTree.ExportSpecifier[]\n}\n","import {CategorizedNamedReExport} from './CategorizedNamedReExport'\nimport type {CategorizedReExport} from './CategorizedReExport'\n\nexport function isNamedReExport(x: CategorizedReExport): x is CategorizedNamedReExport {\n return x.group !== 're-export-all'\n}\n","import {areSpecifiersSorted} from './areSpecifiersSorted'\nimport {getNamedSpecifiers} from './getNamedSpecifiers'\nimport {isNamedReExport} from './isNamedReExport'\nimport type {CategorizedReExport} from './CategorizedReExport'\nimport type {ReExportError} from './ReExportError'\n\nexport function checkSpecifiersSorting(categorized: CategorizedReExport[]): ReExportError[] {\n const errors: ReExportError[] = []\n const namedReExports = categorized.filter(isNamedReExport)\n\n for (const {declaration} of namedReExports) {\n const specifiers = getNamedSpecifiers(declaration)\n const isSorted = areSpecifiersSorted(specifiers)\n if (specifiers.length > 1 && !isSorted) {\n errors.push({\n node: declaration,\n messageId: 'sortedNames',\n })\n }\n }\n\n return errors\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function sortSpecifiersText(\n specifiers: TSESTree.ExportSpecifier[],\n sourceCode: {getText: (node?: unknown) => string},\n): string {\n const sorted = [...specifiers].sort((a, b) => {\n const nameA = getSpecifierName(a)\n const nameB = getSpecifierName(b)\n return compare(nameA, nameB)\n })\n return sorted.map(s => sourceCode.getText(s)).join(', ')\n}\n","import {areSpecifiersSorted} from '../areSpecifiersSorted'\nimport {getNamedSpecifiers} from '../getNamedSpecifiers'\nimport {sortSpecifiersText} from '../sortSpecifiersText'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function formatNamedReExport(\n declaration: TSESTree.ExportNamedDeclaration,\n sourceCode: {getText: (node?: unknown) => string},\n): string {\n const specifiers = getNamedSpecifiers(declaration)\n\n if (specifiers.length > 1 && !areSpecifiersSorted(specifiers)) {\n const sortedSpecifiers = sortSpecifiersText(specifiers, sourceCode)\n const source = declaration.source!.value\n const prefix = declaration.exportKind === 'type' ? 'export type ' : 'export '\n return `${prefix}{${sortedSpecifiers}} from '${source}'`\n }\n\n return sourceCode.getText(declaration)\n}\n","import {formatNamedReExport} from './formatNamedReExport'\nimport {isNamedReExport} from '../isNamedReExport'\nimport {reExportGroupOrder} from '../ReExportGroupOrder'\nimport type {CategorizedReExport} from '../CategorizedReExport'\nimport type {ReExportGroup} from '../ReExportGroup'\n\nexport function buildSortedCode(\n grouped: Record<ReExportGroup, CategorizedReExport[]>,\n sourceCode: {getText: (node?: unknown) => string},\n): string[] {\n const sortedCode: string[] = []\n\n for (const group of reExportGroupOrder) {\n for (const item of grouped[group]) {\n if (isNamedReExport(item)) {\n sortedCode.push(\n formatNamedReExport(\n item.declaration,\n sourceCode,\n ),\n )\n } else\n sortedCode.push(sourceCode.getText(item.declaration))\n }\n }\n\n return sortedCode\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function findFirstExportIndex(programBody: TSESTree.ProgramStatement[]): number {\n for (let i = 0; i < programBody.length; i++) {\n if (programBody[i].type === 'ExportNamedDeclaration'\n || programBody[i].type === 'ExportAllDeclaration') {\n return i\n }\n }\n return -1\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function findLastExportIndex(programBody: TSESTree.ProgramStatement[]): number {\n let lastIndex = -1\n for (let i = 0; i < programBody.length; i++) {\n if (programBody[i].type === 'ExportNamedDeclaration'\n || programBody[i].type === 'ExportAllDeclaration') {\n lastIndex = i\n }\n }\n return lastIndex\n}\n","import {findFirstExportIndex} from './findFirstExportIndex'\nimport {findLastExportIndex} from './findLastExportIndex'\nimport type {ReplacementRange} from '../../../lib/ReplacementRange'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getReplacementRange(\n programBody: TSESTree.ProgramStatement[],\n): ReplacementRange {\n const firstIndex = findFirstExportIndex(programBody)\n const lastIndex = findLastExportIndex(programBody)\n\n if (firstIndex === -1 || lastIndex === -1)\n return {start: 0, end: 0}\n\n const firstExport = programBody[firstIndex]\n const lastExport = programBody[lastIndex]\n\n const start = firstExport.range[0]\n const end = lastExport.range[1]\n\n return {start, end}\n}\n","import type {CategorizedReExport} from '../CategorizedReExport'\nimport type {ReExportGroup} from '../ReExportGroup'\n\nexport function groupReExportsByType(\n categorized: CategorizedReExport[],\n): Record<ReExportGroup, CategorizedReExport[]> {\n const grouped: Record<ReExportGroup, CategorizedReExport[]> = {\n 're-export-all': [],\n 're-export-named': [],\n 're-export-type': [],\n }\n\n for (const item of categorized)\n grouped[item.group].push(item)\n\n return grouped\n}\n","import {compare} from '../../../lib/compare'\nimport type {CategorizedReExport} from '../CategorizedReExport'\nimport type {ReExportGroup} from '../ReExportGroup'\n\nexport function sortExportGroups(\n grouped: Record<ReExportGroup, CategorizedReExport[]>,\n): void {\n grouped['re-export-all'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['re-export-named'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['re-export-type'].sort((a, b) => compare(a.sortKey, b.sortKey))\n}\n","import {buildSortedCode} from './buildSortedCode'\nimport {categorizeReExports} from '../categorizeReExports'\nimport {getReplacementRange} from './getReplacementRange'\nimport {groupReExportsByType} from './groupReExportsByType'\nimport {ReExportDeclaration} from '../ReExportDeclaration'\nimport {sortExportGroups} from './sortExportGroups'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function createFix(\n fixer: Rule.RuleFixer,\n reExportDeclarations: ReExportDeclaration[],\n sourceCode: {getText: (node?: unknown) => string},\n programBody: TSESTree.ProgramStatement[],\n) {\n const range = getReplacementRange(programBody)\n const categorized = categorizeReExports(reExportDeclarations)\n const grouped = groupReExportsByType(categorized)\n\n sortExportGroups(grouped)\n\n const sortedCode = buildSortedCode(grouped, sourceCode)\n .join('\\n')\n\n return fixer.replaceTextRange(\n [range.start, range.end],\n sortedCode,\n )\n}\n","import type {ReExportDeclaration} from './ReExportDeclaration'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getReExportDeclarations(\n programBody: TSESTree.ProgramStatement[],\n): ReExportDeclaration[] {\n return programBody.filter(\n (statement): statement is ReExportDeclaration =>\n (statement.type === 'ExportNamedDeclaration' && statement.source !== null)\n || statement.type === 'ExportAllDeclaration',\n )\n}\n","import {categorizeReExports} from './categorizeReExports'\nimport {checkAlphabeticalSorting} from './checkAlphabeticalSorting'\nimport {checkGroupOrdering} from './checkGroupOrdering'\nimport {checkSpecifiersSorting} from './checkSpecifiersSorting'\nimport {createFix} from './createFix'\nimport {getReExportDeclarations} from './getReExportDeclarations'\nimport type {ReExportError} from './ReExportError'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const sortedReExports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce sorted exports alphabetically',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n sortedReExports: 'Exports should be sorted alphabetically',\n sortedNames: 'Named exports should be sorted alphabetically',\n wrongGroup: 'Export is in wrong group',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n Program(node) {\n const body = node.body as TSESTree.ProgramStatement[]\n const declarations = getReExportDeclarations(body)\n if (declarations.length === 0)\n return\n\n const categorized = categorizeReExports(declarations)\n const errors: ReExportError[] = [\n ...checkGroupOrdering(categorized),\n ...checkAlphabeticalSorting(categorized),\n ...checkSpecifiersSorting(categorized),\n ]\n\n for (const error of errors) {\n context.report({\n node: error.node,\n messageId: error.messageId,\n fix(fixer) {\n const sourceCode = context.sourceCode\n return createFix(fixer, declarations, sourceCode, body)\n },\n })\n }\n },\n }\n },\n}\n"],"mappings":";AAAA,OAAO,YAAY;AACnB,OAAO,WAAW;AAClB,OAAO,gBAAgB;AACvB,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB,SAAQ,oBAAmB;;;ACFpB,SAAS,iBAAiB,WAA8C;AAC7E,MAAI,UAAU,SAAS;AACrB,WAAO;AAET,MAAI,UAAU,SAAS;AACrB,WAAO;AAET,MAAI,UAAU,SAAS,0BAA0B;AAC/C,QAAI,UAAU,WAAW;AACvB,aAAO;AAAA,EACX;AAEA,SAAO;AACT;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A;AAAA,MACF;AAAA,MACA,oCAAoC;AAAA,QAClC;AAAA,QACA;AAAA,MACF;AAAA,MACA,4BAA4B;AAAA,MAC5B,0BAA0B;AAAA,QACxB;AAAA,QACA;AAAA,QACA,EAAC,iBAAiB,KAAI;AAAA,MACxB;AAAA,MACA,qBAAqB;AAAA,QACnB;AAAA,QACA;AAAA,QACA,EAAC,cAAc,CAAC,kBAAkB,EAAC;AAAA,MACrC;AAAA,MACA,8BAA8B;AAAA,QAC5B;AAAA,QACA;AAAA,UACE,cAAc;AAAA,UACd,eAAe;AAAA,UACf,mBAAmB;AAAA,UACnB,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,MACA,kCAAkC;AAAA,MAClC,0CAA0C;AAAA,MAC1C,mCAAmC;AAAA,QACjC;AAAA,QACA,EAAC,YAAY,KAAI;AAAA,MACnB;AAAA,MACA,mCAAmC;AAAA,QACjC;AAAA,QACA;AAAA,MACF;AAAA,MACA,iCAAiC;AAAA,QAC/B;AAAA,QACA;AAAA,QACA,EAAC,WAAW,EAAC,KAAK,QAAO,EAAC;AAAA,MAC5B;AAAA,MACA,qBAAqB;AAAA,QACnB;AAAA,QACA;AAAA,QACA,EAAC,aAAa,KAAI;AAAA,MACpB;AAAA,MACA,0BAA0B;AAAA,QACxB;AAAA,QACA;AAAA,MACF;AAAA,MACA,mBAAmB;AAAA,QACjB;AAAA,QACA;AAAA,QACA,EAAC,kCAAkC,SAAQ;AAAA,MAC7C;AAAA,MACA,wCAAwC;AAAA,MACxC,sDAAsD;AAAA,IACxD;AAAA,EACF;AACF,CAAC;","names":["getSortKey","getSortKey","checkAlphabeticalSorting","checkGroupOrdering","getSpecifierName","areSpecifiersSorted","getSpecifierName","getNamedSpecifiers","checkSpecifiersSorting","getNamedSpecifiers","areSpecifiersSorted","sortSpecifiersText","getSpecifierName","getNamedSpecifiers","areSpecifiersSorted","sortSpecifiersText","buildSortedCode","getReplacementRange","createFix","getReplacementRange","buildSortedCode","checkGroupOrdering","checkAlphabeticalSorting","checkSpecifiersSorting","createFix"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rules/importsAndReExportsAtTop/getStatementType.ts","../src/rules/importsAndReExportsAtTop/categorizeStatements.ts","../src/rules/importsAndReExportsAtTop/findFirstIndices.ts","../src/rules/importsAndReExportsAtTop/generateSortedText.ts","../src/rules/importsAndReExportsAtTop/hasViolation.ts","../src/rules/importsAndReExportsAtTop/index.ts","../src/rules/individualImports.ts","../src/rules/individualReExports.ts","../src/rules/sortedImports/categorizeImport.ts","../src/rules/sortedImports/getSortKey.ts","../src/rules/sortedImports/categorizeImports.ts","../src/lib/compare.ts","../src/rules/sortedImports/ImportGroupOrder.ts","../src/rules/sortedImports/checkAlphabeticalSorting.ts","../src/rules/sortedImports/checkGroupOrdering.ts","../src/rules/sortedImports/getSpecifierName.ts","../src/rules/sortedImports/areSpecifiersSorted.ts","../src/rules/sortedImports/getNamedSpecifiers.ts","../src/rules/sortedImports/checkSpecifiersSorting.ts","../src/rules/sortedImports/sortSpecifiersText.ts","../src/rules/sortedImports/createFix/formatNamedImport.ts","../src/rules/sortedImports/createFix/buildSortedCode.ts","../src/rules/sortedImports/createFix/groupImportsByType.ts","../src/rules/sortedImports/createFix/sortImportGroups.ts","../src/rules/sortedImports/createFix/index.ts","../src/rules/sortedImports/getImportGroups.ts","../src/rules/sortedImports/index.ts","../src/rules/sortedReExports/categorizeReExport.ts","../src/rules/sortedReExports/getSortKey.ts","../src/rules/sortedReExports/categorizeReExports.ts","../src/rules/sortedReExports/ReExportGroupOrder.ts","../src/rules/sortedReExports/checkAlphabeticalSorting.ts","../src/rules/sortedReExports/checkGroupOrdering.ts","../src/rules/sortedReExports/getSpecifierName.ts","../src/rules/sortedReExports/areSpecifiersSorted.ts","../src/rules/sortedReExports/getNamedSpecifiers.ts","../src/rules/sortedReExports/isNamedReExport.ts","../src/rules/sortedReExports/checkSpecifiersSorting.ts","../src/rules/sortedReExports/sortSpecifiersText.ts","../src/rules/sortedReExports/createFix/formatNamedReExport.ts","../src/rules/sortedReExports/createFix/buildSortedCode.ts","../src/rules/sortedReExports/createFix/groupReExportsByType.ts","../src/rules/sortedReExports/createFix/sortExportGroups.ts","../src/rules/sortedReExports/createFix/index.ts","../src/rules/sortedReExports/getReExportGroups.ts","../src/rules/sortedReExports/index.ts"],"sourcesContent":["import eslint from '@eslint/js'\nimport react from 'eslint-plugin-react'\nimport reactHooks from 'eslint-plugin-react-hooks'\nimport stylistic from '@stylistic/eslint-plugin'\nimport typescript from 'typescript-eslint'\nimport {defineConfig} from 'eslint/config'\nimport {importsAndReExportsAtTop} from './rules/importsAndReExportsAtTop'\nimport {individualImports} from './rules/individualImports'\nimport {individualReExports} from './rules/individualReExports'\nimport {sortedImports} from './rules/sortedImports'\nimport {sortedReExports} from './rules/sortedReExports'\n\nexport const CONFIG = defineConfig([\n {\n ignores: [\n 'src/graphql/sdk.ts',\n '**/node_modules/**',\n '**/dist/**',\n ],\n },\n {\n settings: {\n react: {\n version: '19',\n },\n },\n },\n eslint.configs.recommended,\n react.configs.flat.recommended,\n stylistic.configs.recommended,\n typescript.configs.recommended,\n typescript.configs.stylistic,\n {\n plugins: {\n 'react-hooks': reactHooks,\n },\n rules: reactHooks.configs.recommended.rules,\n },\n {\n plugins: {\n '@borela-tech': {\n rules: {\n 'imports-and-re-exports-at-top': importsAndReExportsAtTop,\n 'individual-imports': individualImports,\n 'individual-re-exports': individualReExports,\n 'sorted-imports': sortedImports,\n 'sorted-re-exports': sortedReExports,\n },\n },\n },\n rules: {\n '@borela-tech/imports-and-re-exports-at-top': 'error',\n '@borela-tech/individual-imports': 'error',\n '@borela-tech/individual-re-exports': 'error',\n '@borela-tech/sorted-imports': 'error',\n '@borela-tech/sorted-re-exports': 'error',\n },\n },\n {\n rules: {\n 'capitalized-comments': [\n 'error',\n 'always',\n {ignoreConsecutiveComments: true},\n ],\n 'react/react-in-jsx-scope': 'off',\n '@stylistic/arrow-parens': [\n 'error',\n 'as-needed',\n ],\n '@stylistic/array-bracket-newline': [\n 'error',\n 'consistent',\n ],\n '@stylistic/array-bracket-spacing': [\n 'error',\n 'never',\n ],\n '@stylistic/array-element-newline': [\n 'error',\n 'consistent',\n ],\n '@stylistic/block-spacing': 'off',\n '@stylistic/brace-style': [\n 'error',\n '1tbs',\n {allowSingleLine: true},\n ],\n '@stylistic/indent': [\n 'error',\n 2,\n {ignoredNodes: ['TSMappedType > *']},\n ],\n '@stylistic/jsx-tag-spacing': [\n 'error',\n {\n afterOpening: 'never',\n beforeClosing: 'never',\n beforeSelfClosing: 'never',\n closingSlash: 'never',\n },\n ],\n '@stylistic/jsx-wrap-multilines': 'off',\n '@stylistic/lines-between-class-members': 'off',\n '@stylistic/object-curly-newline': [\n 'error',\n {consistent: true},\n ],\n '@stylistic/object-curly-spacing': [\n 'error',\n 'never',\n ],\n '@stylistic/operator-linebreak': [\n 'error',\n 'before',\n {overrides: {'=': 'after'}},\n ],\n '@stylistic/quotes': [\n 'error',\n 'single',\n {avoidEscape: true},\n ],\n '@stylistic/quote-props': [\n 'error',\n 'as-needed',\n ],\n '@stylistic/semi': [\n 'error',\n 'never',\n {beforeStatementContinuationChars: 'always'},\n ],\n '@typescript-eslint/no-empty-function': 'off',\n '@typescript-eslint/consistent-indexed-object-style': 'off',\n },\n },\n])\n","import {StatementType} from './statementType'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getStatementType(statement: TSESTree.Statement): StatementType {\n if (statement.type === 'ImportDeclaration')\n return 'import'\n\n if (statement.type === 'ExportAllDeclaration')\n return 're-export'\n\n if (statement.type === 'ExportNamedDeclaration') {\n if (statement.source !== null)\n return 're-export'\n }\n\n return 'other'\n}\n","import {getStatementType} from './getStatementType'\nimport {ReExport} from './ReExport'\nimport type {CategorizedStatements} from './CategorizedStatements'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeStatements(\n statements: TSESTree.Statement[],\n): CategorizedStatements {\n const result: CategorizedStatements = {\n imports: [],\n reExports: [],\n other: [],\n }\n\n for (const statement of statements) {\n const type = getStatementType(statement)\n\n if (type === 'import')\n result.imports.push(statement as TSESTree.ImportDeclaration)\n else if (type === 're-export')\n result.reExports.push(statement as ReExport)\n else\n result.other.push(statement)\n }\n\n return result\n}\n","import {getStatementType} from './getStatementType'\nimport type {StatementIndices} from './StatementIndices'\nimport type {StatementType} from './statementType'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function findFirstIndices(\n statements: TSESTree.Statement[],\n): StatementIndices {\n let firstImport = Infinity\n let firstReExport = Infinity\n let firstOther = -1\n\n for (let i = 0; i < statements.length; i++) {\n const type: StatementType = getStatementType(statements[i])\n\n if (type === 'import' && firstImport === Infinity)\n firstImport = i\n else if (type === 're-export' && firstReExport === Infinity)\n firstReExport = i\n else if (type === 'other' && firstOther === -1)\n firstOther = i\n }\n\n return {firstImport, firstReExport, firstOther}\n}\n","import {Rule} from 'eslint'\nimport type {CategorizedStatements} from './CategorizedStatements'\nimport type {Node as ESTreeNode} from 'estree'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function generateSortedText(\n context: Rule.RuleContext,\n categories: CategorizedStatements,\n): string {\n const allStatements: TSESTree.Node[] = [\n ...categories.imports,\n ...categories.reExports,\n ...categories.other,\n ]\n return allStatements.map(\n node => context.sourceCode.getText(node as ESTreeNode),\n ).join('\\n')\n}\n","import type {CategorizedStatements} from './CategorizedStatements'\nimport type {StatementIndices} from './StatementIndices'\n\nexport function hasViolation(\n indices: StatementIndices,\n categories: CategorizedStatements,\n): boolean {\n const {\n firstImport,\n firstReExport,\n firstOther,\n } = indices\n\n // No imports or no re-exports.\n if (categories.imports.length === 0 || categories.reExports.length === 0)\n return false\n\n const firstImportOrReExport = Math.min(firstImport, firstReExport)\n const hasOtherBeforeImportOrReExport =\n firstOther !== -1 && firstOther < firstImportOrReExport\n\n // Violation if:\n // 1. Other statements appear before imports/re-exports.\n // 2. Re-exports appear before imports.\n if (hasOtherBeforeImportOrReExport || firstImport > firstReExport)\n return true\n\n return false\n}\n","import {categorizeStatements} from './categorizeStatements'\nimport {findFirstIndices} from './findFirstIndices'\nimport {generateSortedText} from './generateSortedText'\nimport {hasViolation} from './hasViolation'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const importsAndReExportsAtTop: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Enforce imports and re-exports at the top of the file',\n recommended: false,\n },\n fixable: 'code',\n messages: {\n importsAndReExportsAtTop:\n 'Imports and re-exports should be at the top of the file.',\n },\n schema: [],\n },\n\n create(context) {\n return {\n Program(node) {\n const statements = node.body as TSESTree.Statement[]\n const categories = categorizeStatements(statements)\n const indices = findFirstIndices(statements)\n\n if (!hasViolation(indices, categories))\n return\n\n context.report({\n node,\n messageId: 'importsAndReExportsAtTop',\n\n fix(fixer) {\n const sortedText = generateSortedText(context, categories)\n return fixer.replaceText(node, sortedText)\n },\n })\n },\n }\n },\n}\n","import type {Rule} from 'eslint'\n\nexport const individualImports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce individual imports instead of grouped imports',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n individualImports: 'Use individual imports instead of grouped imports.',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n ImportDeclaration(node) {\n if (node.specifiers.length <= 1)\n return\n\n context.report({\n node,\n messageId: 'individualImports',\n fix(fixer) {\n const source = node.source.raw\n const specifiers = node.specifiers\n .filter(s => s.type === 'ImportSpecifier')\n .map(s => `import {${s.local.name}} from ${source}`)\n .join('\\n')\n return fixer.replaceText(node, specifiers)\n },\n })\n },\n }\n },\n}\n","import type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const individualReExports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce individual exports instead of grouped exports',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n individualReExports: 'Use individual exports instead of grouped exports.',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n ExportNamedDeclaration(node) {\n const exportNode = node as TSESTree.ExportNamedDeclaration\n if (!exportNode.source || exportNode.specifiers.length <= 1)\n return\n\n context.report({\n node,\n messageId: 'individualReExports',\n fix(fixer) {\n const source = exportNode.source!.value\n const typeKeyword = exportNode.exportKind === 'type'\n ? 'type '\n : ''\n const specifiers = exportNode.specifiers\n .map(s => {\n const localName = s.local.type === 'Identifier'\n ? s.local.name\n : s.local.value\n const exportedName = s.exported.type === 'Identifier'\n ? s.exported.name\n : s.exported.value\n const name = localName === exportedName\n ? localName\n : `${localName} as ${exportedName}`\n return `export ${typeKeyword}{${name}} from '${source}'`\n })\n .join('\\n')\n return fixer.replaceText(node, specifiers)\n },\n })\n },\n }\n },\n}\n","import type {ImportGroup} from './ImportGroup'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeImport(declaration: TSESTree.ImportDeclaration): ImportGroup {\n // Example: import type {Type} from 'module'\n if (declaration.importKind === 'type')\n return 'type'\n\n // Example: import 'module'\n if (declaration.specifiers.length === 0)\n return 'side-effect'\n\n // Example: import value from 'module'\n if (declaration.specifiers.some(s => s.type === 'ImportDefaultSpecifier'))\n return 'default'\n\n // Example: import {value} from 'module'\n return 'named'\n}\n","import {categorizeImport} from './categorizeImport'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSortKey(declaration: TSESTree.ImportDeclaration): string {\n const group = categorizeImport(declaration)\n\n if (group === 'side-effect')\n return declaration.source.value\n\n if (group === 'default') {\n const defaultSpecifier = declaration.specifiers.find(\n s => s.type === 'ImportDefaultSpecifier',\n ) as TSESTree.ImportDefaultSpecifier | undefined\n\n return defaultSpecifier?.local.name ?? ''\n }\n\n const specifier = declaration.specifiers[0]\n return specifier.local.name\n}\n","import {categorizeImport} from './categorizeImport'\nimport {getSortKey} from './getSortKey'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeImports(declarations: TSESTree.ImportDeclaration[]): CategorizedImport[] {\n return declarations.map(declaration => ({\n declaration,\n group: categorizeImport(declaration),\n sortKey: getSortKey(declaration),\n }))\n}\n","export function compare(a: string, b: string): number {\n return a.localeCompare(b, 'en', {sensitivity: 'case'})\n}\n","import {ImportGroup} from './ImportGroup'\n\nexport const importGroupOrder: ImportGroup[] = [\n 'side-effect',\n 'default',\n 'named',\n 'type',\n]\n","import {compare} from '../../lib/compare'\nimport {importGroupOrder} from './ImportGroupOrder'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {ImportError} from './ImportError'\n\nexport function checkAlphabeticalSorting(categorized: CategorizedImport[]): ImportError[] {\n const errors: ImportError[] = []\n\n for (const group of importGroupOrder) {\n const groupImports = categorized.filter(c => c.group === group)\n const sorted = [...groupImports].sort((a, b) => compare(a.sortKey, b.sortKey))\n for (let i = 0; i < groupImports.length; i++) {\n if (groupImports[i] !== sorted[i]) {\n errors.push({\n node: groupImports[i].declaration,\n messageId: 'sortedImports',\n })\n }\n }\n }\n\n return errors\n}\n","import {importGroupOrder} from './ImportGroupOrder'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {ImportError} from './ImportError'\n\nexport function checkGroupOrdering(categorized: CategorizedImport[]): ImportError[] {\n const errors: ImportError[] = []\n\n let currentGroupIndex = -1\n for (const {declaration, group} of categorized) {\n const groupIndex = importGroupOrder.indexOf(group)\n if (groupIndex < currentGroupIndex) {\n errors.push({\n node: declaration,\n messageId: 'wrongGroup',\n })\n } else\n currentGroupIndex = groupIndex\n }\n\n return errors\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSpecifierName(specifier: TSESTree.ImportSpecifier): string {\n return specifier.imported.type === 'Identifier'\n ? specifier.imported.name\n : String(specifier.imported.value)\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function areSpecifiersSorted(specifiers: TSESTree.ImportSpecifier[]): boolean {\n const names = specifiers.map(s => getSpecifierName(s))\n const sorted = [...names].sort((a, b) => compare(a, b))\n return names.every((name, i) => name === sorted[i])\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getNamedSpecifiers(declaration: TSESTree.ImportDeclaration): TSESTree.ImportSpecifier[] {\n return declaration.specifiers.filter(\n (s): s is TSESTree.ImportSpecifier => s.type === 'ImportSpecifier',\n )\n}\n","import {areSpecifiersSorted} from './areSpecifiersSorted'\nimport {getNamedSpecifiers} from './getNamedSpecifiers'\nimport type {CategorizedImport} from './CategorizedImport'\nimport type {ImportError} from './ImportError'\n\nexport function checkSpecifiersSorting(categorized: CategorizedImport[]): ImportError[] {\n const errors: ImportError[] = []\n const namedImports = categorized.filter(c => c.group === 'named')\n\n for (const {declaration} of namedImports) {\n const specifiers = getNamedSpecifiers(declaration)\n if (specifiers.length > 1 && !areSpecifiersSorted(specifiers)) {\n errors.push({\n node: declaration,\n messageId: 'sortedNames',\n })\n }\n }\n\n return errors\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function sortSpecifiersText(\n specifiers: TSESTree.ImportSpecifier[],\n sourceCode: {getText: (node: TSESTree.ImportSpecifier) => string},\n): string {\n const sorted = [...specifiers].sort((a, b) => {\n const nameA = getSpecifierName(a)\n const nameB = getSpecifierName(b)\n return compare(nameA, nameB)\n })\n return sorted.map(s => sourceCode.getText(s)).join(', ')\n}\n","import {areSpecifiersSorted} from '../areSpecifiersSorted'\nimport {getNamedSpecifiers} from '../getNamedSpecifiers'\nimport {sortSpecifiersText} from '../sortSpecifiersText'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function formatNamedImport(\n declaration: TSESTree.ImportDeclaration,\n sourceCode: {getText: (node?: unknown) => string},\n): string {\n const specifiers = getNamedSpecifiers(declaration)\n\n if (specifiers.length > 1 && !areSpecifiersSorted(specifiers)) {\n const sortedSpecifiers = sortSpecifiersText(specifiers, sourceCode)\n const source = declaration.source.value\n const prefix = declaration.importKind === 'type' ? 'import type ' : 'import '\n return `${prefix}{${sortedSpecifiers}} from '${source}'`\n }\n\n return sourceCode.getText(declaration)\n}\n","import {formatNamedImport} from './formatNamedImport'\nimport {importGroupOrder} from '../ImportGroupOrder'\nimport type {CategorizedImport} from '../CategorizedImport'\nimport type {ImportGroup} from '../ImportGroup'\n\nexport function buildSortedCode(\n grouped: Record<ImportGroup, CategorizedImport[]>,\n sourceCode: {getText: (node?: unknown) => string},\n): string[] {\n const sortedCode: string[] = []\n\n for (const group of importGroupOrder) {\n for (const {declaration} of grouped[group]) {\n if (group === 'named' || group === 'type')\n sortedCode.push(formatNamedImport(declaration, sourceCode))\n else\n sortedCode.push(sourceCode.getText(declaration))\n }\n }\n\n return sortedCode\n}\n","import type {CategorizedImport} from '../CategorizedImport'\nimport type {ImportGroup} from '../ImportGroup'\n\nexport function groupImportsByType(\n categorized: CategorizedImport[],\n): Record<ImportGroup, CategorizedImport[]> {\n const grouped: Record<ImportGroup, CategorizedImport[]> = {\n 'side-effect': [],\n default: [],\n named: [],\n type: [],\n }\n\n for (const item of categorized)\n grouped[item.group].push(item)\n\n return grouped\n}\n","import {compare} from '../../../lib/compare'\nimport type {CategorizedImport} from '../CategorizedImport'\nimport type {ImportGroup} from '../ImportGroup'\n\nexport function sortImportGroups(\n grouped: Record<ImportGroup, CategorizedImport[]>,\n): void {\n grouped['side-effect'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['default'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['named'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['type'].sort((a, b) => compare(a.sortKey, b.sortKey))\n}\n","import {buildSortedCode} from './buildSortedCode'\nimport {categorizeImports} from '../categorizeImports'\nimport {groupImportsByType} from './groupImportsByType'\nimport {sortImportGroups} from './sortImportGroups'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nfunction createFixForGroup(\n fixer: Rule.RuleFixer,\n importDeclarations: TSESTree.ImportDeclaration[],\n sourceCode: {getText: (node?: unknown) => string},\n): Rule.Fix | null {\n if (importDeclarations.length === 0) {\n return null\n }\n\n const categorized = categorizeImports(importDeclarations)\n const grouped = groupImportsByType(categorized)\n\n sortImportGroups(grouped)\n\n const sortedCode = buildSortedCode(grouped, sourceCode)\n .join('\\n')\n\n const firstImport = importDeclarations[0]\n const lastImport = importDeclarations[importDeclarations.length - 1]\n\n return fixer.replaceTextRange(\n [firstImport.range![0], lastImport.range![1]],\n sortedCode,\n )\n}\n\nexport function createFix(\n fixer: Rule.RuleFixer,\n importGroups: TSESTree.ImportDeclaration[][],\n sourceCode: {getText: (node?: unknown) => string},\n): Rule.Fix[] {\n const fixes: Rule.Fix[] = []\n\n for (const group of importGroups) {\n const fix = createFixForGroup(fixer, group, sourceCode)\n if (fix)\n fixes.push(fix)\n }\n\n return fixes\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getImportGroups(programBody: TSESTree.ProgramStatement[]): TSESTree.ImportDeclaration[][] {\n const groups: TSESTree.ImportDeclaration[][] = []\n let currentGroup: TSESTree.ImportDeclaration[] = []\n\n for (const statement of programBody) {\n if (statement.type === 'ImportDeclaration') {\n currentGroup.push(statement)\n continue\n }\n\n if (currentGroup.length > 0) {\n groups.push(currentGroup)\n currentGroup = []\n }\n }\n\n if (currentGroup.length > 0)\n groups.push(currentGroup)\n\n return groups\n}\n","import {categorizeImports} from './categorizeImports'\nimport {checkAlphabeticalSorting} from './checkAlphabeticalSorting'\nimport {checkGroupOrdering} from './checkGroupOrdering'\nimport {checkSpecifiersSorting} from './checkSpecifiersSorting'\nimport {createFix} from './createFix'\nimport {getImportGroups} from './getImportGroups'\nimport type {ImportError} from './ImportError'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const sortedImports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce sorted imports alphabetically',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n sortedImports: 'Imports should be sorted alphabetically',\n sortedNames: 'Named imports should be sorted alphabetically',\n wrongGroup: 'Import is in wrong group',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n Program(node) {\n const body = node.body as TSESTree.ProgramStatement[]\n const importGroups = getImportGroups(body)\n if (importGroups.length === 0)\n return\n\n const allErrors: ImportError[] = []\n\n // Check each import group independently\n for (const group of importGroups) {\n const categorized = categorizeImports(group)\n const errors: ImportError[] = [\n ...checkGroupOrdering(categorized),\n ...checkAlphabeticalSorting(categorized),\n ...checkSpecifiersSorting(categorized),\n ]\n allErrors.push(...errors)\n }\n\n for (const error of allErrors) {\n context.report({\n node: error.node,\n messageId: error.messageId,\n fix(fixer) {\n const sourceCode = context.sourceCode\n return createFix(fixer, importGroups, sourceCode)\n },\n })\n }\n },\n }\n },\n}\n","import type {ReExportGroup} from './ReExportGroup'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function categorizeReExport(\n declaration: TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration,\n): ReExportGroup {\n // Example: export * from 'module'\n if (declaration.type === 'ExportAllDeclaration')\n return 're-export-all'\n\n // Example: export type {Type} from 'module'\n if (declaration.exportKind === 'type')\n return 're-export-type'\n\n // Example: export {value} from 'module'\n return 're-export-named'\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSortKey(\n declaration: TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration,\n): string {\n if (declaration.type === 'ExportAllDeclaration')\n return declaration.source.value\n\n const specifier = declaration.specifiers[0]\n if (!specifier)\n return ''\n\n return specifier.local.type === 'Identifier'\n ? specifier.local.name\n : specifier.local.value\n}\n","import {categorizeReExport} from './categorizeReExport'\nimport {getSortKey} from './getSortKey'\nimport {ReExportDeclaration} from './ReExportDeclaration'\nimport type {CategorizedReExport} from './CategorizedReExport'\n\nexport function categorizeReExports(declarations: ReExportDeclaration[]): CategorizedReExport[] {\n return declarations.map(declaration => {\n return {\n declaration,\n group: categorizeReExport(declaration),\n sortKey: getSortKey(declaration),\n } as CategorizedReExport\n })\n}\n","import {ReExportGroup} from './ReExportGroup'\n\nexport const reExportGroupOrder: ReExportGroup[] = [\n 're-export-all',\n 're-export-named',\n 're-export-type',\n]\n","import {compare} from '../../lib/compare'\nimport {reExportGroupOrder} from './ReExportGroupOrder'\nimport type {CategorizedReExport} from './CategorizedReExport'\nimport type {ReExportError} from './ReExportError'\n\nexport function checkAlphabeticalSorting(categorized: CategorizedReExport[]): ReExportError[] {\n const errors: ReExportError[] = []\n\n for (const group of reExportGroupOrder) {\n const groupReExports = categorized.filter(c => c.group === group)\n const sorted = [...groupReExports].sort((a, b) =>\n compare(a.sortKey, b.sortKey),\n )\n for (let i = 0; i < groupReExports.length; i++) {\n if (groupReExports[i] !== sorted[i]) {\n errors.push({\n node: groupReExports[i].declaration,\n messageId: 'sortedReExports',\n })\n }\n }\n }\n\n return errors\n}\n","import {reExportGroupOrder} from './ReExportGroupOrder'\nimport type {CategorizedReExport} from './CategorizedReExport'\nimport type {ReExportError} from './ReExportError'\n\nexport function checkGroupOrdering(categorized: CategorizedReExport[]): ReExportError[] {\n const errors: ReExportError[] = []\n\n let currentGroupIndex = -1\n for (const {declaration, group} of categorized) {\n const groupIndex = reExportGroupOrder.indexOf(group)\n if (groupIndex < currentGroupIndex) {\n errors.push({\n node: declaration,\n messageId: 'wrongGroup',\n })\n } else\n currentGroupIndex = groupIndex\n }\n\n return errors\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getSpecifierName(specifier: TSESTree.ExportSpecifier): string {\n return specifier.local.type === 'Identifier'\n ? specifier.local.name\n : String(specifier.local.value)\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function areSpecifiersSorted(specifiers: TSESTree.ExportSpecifier[]): boolean {\n const names = specifiers.map(s => getSpecifierName(s))\n const sorted = [...names].sort((a, b) => compare(a, b))\n return names.every((name, i) => name === sorted[i])\n}\n","import type {TSESTree} from '@typescript-eslint/types'\n\nexport function getNamedSpecifiers(\n declaration: TSESTree.ExportNamedDeclaration,\n): TSESTree.ExportSpecifier[] {\n return declaration.specifiers.filter(\n s => s.type === 'ExportSpecifier' && s.local.type === 'Identifier',\n ) as TSESTree.ExportSpecifier[]\n}\n","import {CategorizedNamedReExport} from './CategorizedNamedReExport'\nimport type {CategorizedReExport} from './CategorizedReExport'\n\nexport function isNamedReExport(x: CategorizedReExport): x is CategorizedNamedReExport {\n return x.group !== 're-export-all'\n}\n","import {areSpecifiersSorted} from './areSpecifiersSorted'\nimport {getNamedSpecifiers} from './getNamedSpecifiers'\nimport {isNamedReExport} from './isNamedReExport'\nimport type {CategorizedReExport} from './CategorizedReExport'\nimport type {ReExportError} from './ReExportError'\n\nexport function checkSpecifiersSorting(categorized: CategorizedReExport[]): ReExportError[] {\n const errors: ReExportError[] = []\n const namedReExports = categorized.filter(isNamedReExport)\n\n for (const {declaration} of namedReExports) {\n const specifiers = getNamedSpecifiers(declaration)\n const isSorted = areSpecifiersSorted(specifiers)\n if (specifiers.length > 1 && !isSorted) {\n errors.push({\n node: declaration,\n messageId: 'sortedNames',\n })\n }\n }\n\n return errors\n}\n","import {compare} from '../../lib/compare'\nimport {getSpecifierName} from './getSpecifierName'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function sortSpecifiersText(\n specifiers: TSESTree.ExportSpecifier[],\n sourceCode: {getText: (node?: unknown) => string},\n): string {\n const sorted = [...specifiers].sort((a, b) => {\n const nameA = getSpecifierName(a)\n const nameB = getSpecifierName(b)\n return compare(nameA, nameB)\n })\n return sorted.map(s => sourceCode.getText(s)).join(', ')\n}\n","import {areSpecifiersSorted} from '../areSpecifiersSorted'\nimport {getNamedSpecifiers} from '../getNamedSpecifiers'\nimport {sortSpecifiersText} from '../sortSpecifiersText'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport function formatNamedReExport(\n declaration: TSESTree.ExportNamedDeclaration,\n sourceCode: {getText: (node?: unknown) => string},\n): string {\n const specifiers = getNamedSpecifiers(declaration)\n\n if (specifiers.length > 1 && !areSpecifiersSorted(specifiers)) {\n const sortedSpecifiers = sortSpecifiersText(specifiers, sourceCode)\n const source = declaration.source!.value\n const prefix = declaration.exportKind === 'type' ? 'export type ' : 'export '\n return `${prefix}{${sortedSpecifiers}} from '${source}'`\n }\n\n return sourceCode.getText(declaration)\n}\n","import {formatNamedReExport} from './formatNamedReExport'\nimport {isNamedReExport} from '../isNamedReExport'\nimport {reExportGroupOrder} from '../ReExportGroupOrder'\nimport type {CategorizedReExport} from '../CategorizedReExport'\nimport type {ReExportGroup} from '../ReExportGroup'\n\nexport function buildSortedCode(\n grouped: Record<ReExportGroup, CategorizedReExport[]>,\n sourceCode: {getText: (node?: unknown) => string},\n): string[] {\n const sortedCode: string[] = []\n\n for (const group of reExportGroupOrder) {\n for (const item of grouped[group]) {\n if (isNamedReExport(item)) {\n sortedCode.push(\n formatNamedReExport(\n item.declaration,\n sourceCode,\n ),\n )\n } else\n sortedCode.push(sourceCode.getText(item.declaration))\n }\n }\n\n return sortedCode\n}\n","import type {CategorizedReExport} from '../CategorizedReExport'\nimport type {ReExportGroup} from '../ReExportGroup'\n\nexport function groupReExportsByType(\n categorized: CategorizedReExport[],\n): Record<ReExportGroup, CategorizedReExport[]> {\n const grouped: Record<ReExportGroup, CategorizedReExport[]> = {\n 're-export-all': [],\n 're-export-named': [],\n 're-export-type': [],\n }\n\n for (const item of categorized)\n grouped[item.group].push(item)\n\n return grouped\n}\n","import {compare} from '../../../lib/compare'\nimport type {CategorizedReExport} from '../CategorizedReExport'\nimport type {ReExportGroup} from '../ReExportGroup'\n\nexport function sortExportGroups(\n grouped: Record<ReExportGroup, CategorizedReExport[]>,\n): void {\n grouped['re-export-all'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['re-export-named'].sort((a, b) => compare(a.sortKey, b.sortKey))\n grouped['re-export-type'].sort((a, b) => compare(a.sortKey, b.sortKey))\n}\n","import {buildSortedCode} from './buildSortedCode'\nimport {categorizeReExports} from '../categorizeReExports'\nimport {groupReExportsByType} from './groupReExportsByType'\nimport {ReExportDeclaration} from '../ReExportDeclaration'\nimport {sortExportGroups} from './sortExportGroups'\nimport type {Rule} from 'eslint'\n\nfunction createFixForGroup(\n fixer: Rule.RuleFixer,\n reExportDeclarations: ReExportDeclaration[],\n sourceCode: {getText: (node?: unknown) => string},\n): Rule.Fix | null {\n if (reExportDeclarations.length === 0) {\n return null\n }\n\n const categorized = categorizeReExports(reExportDeclarations)\n const grouped = groupReExportsByType(categorized)\n\n sortExportGroups(grouped)\n\n const sortedCode = buildSortedCode(grouped, sourceCode)\n .join('\\n')\n\n const firstReExport = reExportDeclarations[0]\n const lastReExport = reExportDeclarations[reExportDeclarations.length - 1]\n\n return fixer.replaceTextRange(\n [firstReExport.range![0], lastReExport.range![1]],\n sortedCode,\n )\n}\n\nexport function createFix(\n fixer: Rule.RuleFixer,\n reExportGroups: ReExportDeclaration[][],\n sourceCode: {getText: (node?: unknown) => string},\n): Rule.Fix[] {\n const fixes: Rule.Fix[] = []\n\n for (const group of reExportGroups) {\n const fix = createFixForGroup(fixer, group, sourceCode)\n if (fix)\n fixes.push(fix)\n }\n\n return fixes\n}\n","import type {ReExportDeclaration} from './ReExportDeclaration'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nfunction isReExportDeclaration(\n statement: TSESTree.ProgramStatement,\n): statement is ReExportDeclaration {\n return (statement.type === 'ExportNamedDeclaration' && statement.source !== null)\n || statement.type === 'ExportAllDeclaration'\n}\n\nexport function getReExportGroups(\n programBody: TSESTree.ProgramStatement[],\n): ReExportDeclaration[][] {\n const groups: ReExportDeclaration[][] = []\n let currentGroup: ReExportDeclaration[] = []\n\n for (const statement of programBody) {\n if (isReExportDeclaration(statement)) {\n currentGroup.push(statement)\n continue\n }\n\n if (currentGroup.length > 0) {\n groups.push(currentGroup)\n currentGroup = []\n }\n }\n\n if (currentGroup.length > 0)\n groups.push(currentGroup)\n\n return groups\n}\n","import {categorizeReExports} from './categorizeReExports'\nimport {checkAlphabeticalSorting} from './checkAlphabeticalSorting'\nimport {checkGroupOrdering} from './checkGroupOrdering'\nimport {checkSpecifiersSorting} from './checkSpecifiersSorting'\nimport {createFix} from './createFix'\nimport {getReExportGroups} from './getReExportGroups'\nimport type {ReExportError} from './ReExportError'\nimport type {Rule} from 'eslint'\nimport type {TSESTree} from '@typescript-eslint/types'\n\nexport const sortedReExports: Rule.RuleModule = {\n meta: {\n docs: {\n description: 'Enforce sorted exports alphabetically',\n recommended: true,\n },\n fixable: 'code',\n messages: {\n sortedReExports: 'Exports should be sorted alphabetically',\n sortedNames: 'Named exports should be sorted alphabetically',\n wrongGroup: 'Export is in wrong group',\n },\n schema: [],\n type: 'suggestion',\n },\n create(context) {\n return {\n Program(node) {\n const body = node.body as TSESTree.ProgramStatement[]\n const reExportGroups = getReExportGroups(body)\n if (reExportGroups.length === 0)\n return\n\n const allErrors: ReExportError[] = []\n\n // Check each re-export group independently\n for (const group of reExportGroups) {\n const categorized = categorizeReExports(group)\n const errors: ReExportError[] = [\n ...checkGroupOrdering(categorized),\n ...checkAlphabeticalSorting(categorized),\n ...checkSpecifiersSorting(categorized),\n ]\n allErrors.push(...errors)\n }\n\n for (const error of allErrors) {\n context.report({\n node: error.node,\n messageId: error.messageId,\n fix(fixer) {\n const sourceCode = context.sourceCode\n return createFix(fixer, reExportGroups, sourceCode)\n },\n })\n }\n },\n }\n },\n}\n"],"mappings":";AAAA,OAAO,YAAY;AACnB,OAAO,WAAW;AAClB,OAAO,gBAAgB;AACvB,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB,SAAQ,oBAAmB;;;ACFpB,SAAS,iBAAiB,WAA8C;AAC7E,MAAI,UAAU,SAAS;AACrB,WAAO;AAET,MAAI,UAAU,SAAS;AACrB,WAAO;AAET,MAAI,UAAU,SAAS,0BAA0B;AAC/C,QAAI,UAAU,WAAW;AACvB,aAAO;AAAA,EACX;AAE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AAC,2BAA2B,KAAI;AAAA,MAClC;AAAA,MACA,4BAA4B;AAAA,MAC5B,2BAA2B;AAAA,QACzB;AAAA,QACA;AAAA,MACF;AAAA,MACA,oCAAoC;AAAA,QAClC;AAAA,QACA;AAAA,MACF;AAAA,MACA,oCAAoC;AAAA,QAClC;AAAA,QACA;AAAA,MACF;AAAA,MACA,oCAAoC;AAAA,QAClC;AAAA,QACA;AAAA,MACF;AAAA,MACA,4BAA4B;AAAA,MAC5B,0BAA0B;AAAA,QACxB;AAAA,QACA;AAAA,QACA,EAAC,iBAAiB,KAAI;AAAA,MACxB;AAAA,MACA,qBAAqB;AAAA,QACnB;AAAA,QACA;AAAA,QACA,EAAC,cAAc,CAAC,kBAAkB,EAAC;AAAA,MACrC;AAAA,MACA,8BAA8B;AAAA,QAC5B;AAAA,QACA;AAAA,UACE,cAAc;AAAA,UACd,eAAe;AAAA,UACf,mBAAmB;AAAA,UACnB,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,MACA,kCAAkC;AAAA,MAClC,0CAA0C;AAAA,MAC1C,mCAAmC;AAAA,QACjC;AAAA,QACA,EAAC,YAAY,KAAI;AAAA,MACnB;AAAA,MACA,mCAAmC;AAAA,QACjC;AAAA,QACA;AAAA,MACF;AAAA,MACA,iCAAiC;AAAA,QAC/B;AAAA,QACA;AAAA,QACA,EAAC,WAAW,EAAC,KAAK,QAAO,EAAC;AAAA,MAC5B;AAAA,MACA,qBAAqB;AAAA,QACnB;AAAA,QACA;AAAA,QACA,EAAC,aAAa,KAAI;AAAA,MACpB;AAAA,MACA,0BAA0B;AAAA,QACxB;AAAA,QACA;AAAA,MACF;AAAA,MACA,mBAAmB;AAAA,QACjB;AAAA,QACA;AAAA,QACA,EAAC,kCAAkC,SAAQ;AAAA,MAC7C;AAAA,MACA,wCAAwC;AAAA,MACxC,sDAAsD;AAAA,IACxD;AAAA,EACF;AACF,CAAC;","names":["getSortKey","getSortKey","checkAlphabeticalSorting","checkGroupOrdering","getSpecifierName","areSpecifiersSorted","getSpecifierName","getNamedSpecifiers","checkSpecifiersSorting","getNamedSpecifiers","areSpecifiersSorted","sortSpecifiersText","getSpecifierName","getNamedSpecifiers","areSpecifiersSorted","sortSpecifiersText","buildSortedCode","createFixForGroup","buildSortedCode","createFix","checkGroupOrdering","checkAlphabeticalSorting","checkSpecifiersSorting","createFix"]}
|
package/package.json
CHANGED
|
@@ -56,6 +56,49 @@ ruleTester.run('sorted-imports', sortedImports, {
|
|
|
56
56
|
output: dedent`
|
|
57
57
|
import {a, b, c} from 'bar'
|
|
58
58
|
`,
|
|
59
|
+
}, {
|
|
60
|
+
code: dedent`
|
|
61
|
+
import {b} from 'b'
|
|
62
|
+
const x = 1
|
|
63
|
+
import {c} from 'c'
|
|
64
|
+
import {a} from 'a'
|
|
65
|
+
`,
|
|
66
|
+
errors: [{messageId: 'sortedImports'}, {messageId: 'sortedImports'}],
|
|
67
|
+
output: dedent`
|
|
68
|
+
import {b} from 'b'
|
|
69
|
+
const x = 1
|
|
70
|
+
import {a} from 'a'
|
|
71
|
+
import {c} from 'c'
|
|
72
|
+
`,
|
|
73
|
+
}, {
|
|
74
|
+
code: dedent`
|
|
75
|
+
import {b} from 'b'
|
|
76
|
+
import {a} from 'a'
|
|
77
|
+
const x = 1
|
|
78
|
+
import {d} from 'd'
|
|
79
|
+
import {c} from 'c'
|
|
80
|
+
const y = 2
|
|
81
|
+
import {f} from 'f'
|
|
82
|
+
import {e} from 'e'
|
|
83
|
+
`,
|
|
84
|
+
errors: [
|
|
85
|
+
{messageId: 'sortedImports'},
|
|
86
|
+
{messageId: 'sortedImports'},
|
|
87
|
+
{messageId: 'sortedImports'},
|
|
88
|
+
{messageId: 'sortedImports'},
|
|
89
|
+
{messageId: 'sortedImports'},
|
|
90
|
+
{messageId: 'sortedImports'},
|
|
91
|
+
],
|
|
92
|
+
output: dedent`
|
|
93
|
+
import {a} from 'a'
|
|
94
|
+
import {b} from 'b'
|
|
95
|
+
const x = 1
|
|
96
|
+
import {c} from 'c'
|
|
97
|
+
import {d} from 'd'
|
|
98
|
+
const y = 2
|
|
99
|
+
import {e} from 'e'
|
|
100
|
+
import {f} from 'f'
|
|
101
|
+
`,
|
|
59
102
|
}, {
|
|
60
103
|
code: dedent`
|
|
61
104
|
import {z, a} from 'bar'
|
|
@@ -89,6 +89,49 @@ ruleTester.run('sorted-re-exports', sortedReExports, {
|
|
|
89
89
|
output: dedent`
|
|
90
90
|
export {a, b, c} from 'bar'
|
|
91
91
|
`,
|
|
92
|
+
}, {
|
|
93
|
+
code: dedent`
|
|
94
|
+
export {b} from 'b'
|
|
95
|
+
const x = 1
|
|
96
|
+
export {c} from 'c'
|
|
97
|
+
export {a} from 'a'
|
|
98
|
+
`,
|
|
99
|
+
errors: [{messageId: 'sortedReExports'}, {messageId: 'sortedReExports'}],
|
|
100
|
+
output: dedent`
|
|
101
|
+
export {b} from 'b'
|
|
102
|
+
const x = 1
|
|
103
|
+
export {a} from 'a'
|
|
104
|
+
export {c} from 'c'
|
|
105
|
+
`,
|
|
106
|
+
}, {
|
|
107
|
+
code: dedent`
|
|
108
|
+
export {b} from 'b'
|
|
109
|
+
export {a} from 'a'
|
|
110
|
+
const x = 1
|
|
111
|
+
export {d} from 'd'
|
|
112
|
+
export {c} from 'c'
|
|
113
|
+
const y = 2
|
|
114
|
+
export {f} from 'f'
|
|
115
|
+
export {e} from 'e'
|
|
116
|
+
`,
|
|
117
|
+
errors: [
|
|
118
|
+
{messageId: 'sortedReExports'},
|
|
119
|
+
{messageId: 'sortedReExports'},
|
|
120
|
+
{messageId: 'sortedReExports'},
|
|
121
|
+
{messageId: 'sortedReExports'},
|
|
122
|
+
{messageId: 'sortedReExports'},
|
|
123
|
+
{messageId: 'sortedReExports'},
|
|
124
|
+
],
|
|
125
|
+
output: dedent`
|
|
126
|
+
export {a} from 'a'
|
|
127
|
+
export {b} from 'b'
|
|
128
|
+
const x = 1
|
|
129
|
+
export {c} from 'c'
|
|
130
|
+
export {d} from 'd'
|
|
131
|
+
const y = 2
|
|
132
|
+
export {e} from 'e'
|
|
133
|
+
export {f} from 'f'
|
|
134
|
+
`,
|
|
92
135
|
}, {
|
|
93
136
|
code: dedent`
|
|
94
137
|
export {z, a} from 'bar'
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {buildSortedCode} from './buildSortedCode'
|
|
2
2
|
import {categorizeImports} from '../categorizeImports'
|
|
3
|
-
import {getReplacementRange} from './getReplacementRange'
|
|
4
3
|
import {groupImportsByType} from './groupImportsByType'
|
|
5
4
|
import {sortImportGroups} from './sortImportGroups'
|
|
6
5
|
import type {Rule} from 'eslint'
|
|
7
6
|
import type {TSESTree} from '@typescript-eslint/types'
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
function createFixForGroup(
|
|
10
9
|
fixer: Rule.RuleFixer,
|
|
11
10
|
importDeclarations: TSESTree.ImportDeclaration[],
|
|
12
11
|
sourceCode: {getText: (node?: unknown) => string},
|
|
13
|
-
|
|
14
|
-
) {
|
|
15
|
-
|
|
12
|
+
): Rule.Fix | null {
|
|
13
|
+
if (importDeclarations.length === 0) {
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
16
|
+
|
|
16
17
|
const categorized = categorizeImports(importDeclarations)
|
|
17
18
|
const grouped = groupImportsByType(categorized)
|
|
18
19
|
|
|
@@ -21,8 +22,27 @@ export function createFix(
|
|
|
21
22
|
const sortedCode = buildSortedCode(grouped, sourceCode)
|
|
22
23
|
.join('\n')
|
|
23
24
|
|
|
25
|
+
const firstImport = importDeclarations[0]
|
|
26
|
+
const lastImport = importDeclarations[importDeclarations.length - 1]
|
|
27
|
+
|
|
24
28
|
return fixer.replaceTextRange(
|
|
25
|
-
[range
|
|
29
|
+
[firstImport.range![0], lastImport.range![1]],
|
|
26
30
|
sortedCode,
|
|
27
31
|
)
|
|
28
32
|
}
|
|
33
|
+
|
|
34
|
+
export function createFix(
|
|
35
|
+
fixer: Rule.RuleFixer,
|
|
36
|
+
importGroups: TSESTree.ImportDeclaration[][],
|
|
37
|
+
sourceCode: {getText: (node?: unknown) => string},
|
|
38
|
+
): Rule.Fix[] {
|
|
39
|
+
const fixes: Rule.Fix[] = []
|
|
40
|
+
|
|
41
|
+
for (const group of importGroups) {
|
|
42
|
+
const fix = createFixForGroup(fixer, group, sourceCode)
|
|
43
|
+
if (fix)
|
|
44
|
+
fixes.push(fix)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return fixes
|
|
48
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {TSESTree} from '@typescript-eslint/types'
|
|
2
|
+
|
|
3
|
+
export function getImportGroups(programBody: TSESTree.ProgramStatement[]): TSESTree.ImportDeclaration[][] {
|
|
4
|
+
const groups: TSESTree.ImportDeclaration[][] = []
|
|
5
|
+
let currentGroup: TSESTree.ImportDeclaration[] = []
|
|
6
|
+
|
|
7
|
+
for (const statement of programBody) {
|
|
8
|
+
if (statement.type === 'ImportDeclaration') {
|
|
9
|
+
currentGroup.push(statement)
|
|
10
|
+
continue
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (currentGroup.length > 0) {
|
|
14
|
+
groups.push(currentGroup)
|
|
15
|
+
currentGroup = []
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (currentGroup.length > 0)
|
|
20
|
+
groups.push(currentGroup)
|
|
21
|
+
|
|
22
|
+
return groups
|
|
23
|
+
}
|
|
@@ -3,7 +3,7 @@ import {checkAlphabeticalSorting} from './checkAlphabeticalSorting'
|
|
|
3
3
|
import {checkGroupOrdering} from './checkGroupOrdering'
|
|
4
4
|
import {checkSpecifiersSorting} from './checkSpecifiersSorting'
|
|
5
5
|
import {createFix} from './createFix'
|
|
6
|
-
import {
|
|
6
|
+
import {getImportGroups} from './getImportGroups'
|
|
7
7
|
import type {ImportError} from './ImportError'
|
|
8
8
|
import type {Rule} from 'eslint'
|
|
9
9
|
import type {TSESTree} from '@typescript-eslint/types'
|
|
@@ -27,24 +27,30 @@ export const sortedImports: Rule.RuleModule = {
|
|
|
27
27
|
return {
|
|
28
28
|
Program(node) {
|
|
29
29
|
const body = node.body as TSESTree.ProgramStatement[]
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
30
|
+
const importGroups = getImportGroups(body)
|
|
31
|
+
if (importGroups.length === 0)
|
|
32
32
|
return
|
|
33
33
|
|
|
34
|
-
const
|
|
35
|
-
const errors: ImportError[] = [
|
|
36
|
-
...checkGroupOrdering(categorized),
|
|
37
|
-
...checkAlphabeticalSorting(categorized),
|
|
38
|
-
...checkSpecifiersSorting(categorized),
|
|
39
|
-
]
|
|
34
|
+
const allErrors: ImportError[] = []
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
// Check each import group independently
|
|
37
|
+
for (const group of importGroups) {
|
|
38
|
+
const categorized = categorizeImports(group)
|
|
39
|
+
const errors: ImportError[] = [
|
|
40
|
+
...checkGroupOrdering(categorized),
|
|
41
|
+
...checkAlphabeticalSorting(categorized),
|
|
42
|
+
...checkSpecifiersSorting(categorized),
|
|
43
|
+
]
|
|
44
|
+
allErrors.push(...errors)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const error of allErrors) {
|
|
42
48
|
context.report({
|
|
43
49
|
node: error.node,
|
|
44
50
|
messageId: error.messageId,
|
|
45
51
|
fix(fixer) {
|
|
46
52
|
const sourceCode = context.sourceCode
|
|
47
|
-
return createFix(fixer,
|
|
53
|
+
return createFix(fixer, importGroups, sourceCode)
|
|
48
54
|
},
|
|
49
55
|
})
|
|
50
56
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {buildSortedCode} from './buildSortedCode'
|
|
2
2
|
import {categorizeReExports} from '../categorizeReExports'
|
|
3
|
-
import {getReplacementRange} from './getReplacementRange'
|
|
4
3
|
import {groupReExportsByType} from './groupReExportsByType'
|
|
5
4
|
import {ReExportDeclaration} from '../ReExportDeclaration'
|
|
6
5
|
import {sortExportGroups} from './sortExportGroups'
|
|
7
6
|
import type {Rule} from 'eslint'
|
|
8
|
-
import type {TSESTree} from '@typescript-eslint/types'
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
function createFixForGroup(
|
|
11
9
|
fixer: Rule.RuleFixer,
|
|
12
10
|
reExportDeclarations: ReExportDeclaration[],
|
|
13
11
|
sourceCode: {getText: (node?: unknown) => string},
|
|
14
|
-
|
|
15
|
-
) {
|
|
16
|
-
|
|
12
|
+
): Rule.Fix | null {
|
|
13
|
+
if (reExportDeclarations.length === 0) {
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
17
|
const categorized = categorizeReExports(reExportDeclarations)
|
|
18
18
|
const grouped = groupReExportsByType(categorized)
|
|
19
19
|
|
|
@@ -22,8 +22,27 @@ export function createFix(
|
|
|
22
22
|
const sortedCode = buildSortedCode(grouped, sourceCode)
|
|
23
23
|
.join('\n')
|
|
24
24
|
|
|
25
|
+
const firstReExport = reExportDeclarations[0]
|
|
26
|
+
const lastReExport = reExportDeclarations[reExportDeclarations.length - 1]
|
|
27
|
+
|
|
25
28
|
return fixer.replaceTextRange(
|
|
26
|
-
[range
|
|
29
|
+
[firstReExport.range![0], lastReExport.range![1]],
|
|
27
30
|
sortedCode,
|
|
28
31
|
)
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
export function createFix(
|
|
35
|
+
fixer: Rule.RuleFixer,
|
|
36
|
+
reExportGroups: ReExportDeclaration[][],
|
|
37
|
+
sourceCode: {getText: (node?: unknown) => string},
|
|
38
|
+
): Rule.Fix[] {
|
|
39
|
+
const fixes: Rule.Fix[] = []
|
|
40
|
+
|
|
41
|
+
for (const group of reExportGroups) {
|
|
42
|
+
const fix = createFixForGroup(fixer, group, sourceCode)
|
|
43
|
+
if (fix)
|
|
44
|
+
fixes.push(fix)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return fixes
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {ReExportDeclaration} from './ReExportDeclaration'
|
|
2
|
+
import type {TSESTree} from '@typescript-eslint/types'
|
|
3
|
+
|
|
4
|
+
function isReExportDeclaration(
|
|
5
|
+
statement: TSESTree.ProgramStatement,
|
|
6
|
+
): statement is ReExportDeclaration {
|
|
7
|
+
return (statement.type === 'ExportNamedDeclaration' && statement.source !== null)
|
|
8
|
+
|| statement.type === 'ExportAllDeclaration'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getReExportGroups(
|
|
12
|
+
programBody: TSESTree.ProgramStatement[],
|
|
13
|
+
): ReExportDeclaration[][] {
|
|
14
|
+
const groups: ReExportDeclaration[][] = []
|
|
15
|
+
let currentGroup: ReExportDeclaration[] = []
|
|
16
|
+
|
|
17
|
+
for (const statement of programBody) {
|
|
18
|
+
if (isReExportDeclaration(statement)) {
|
|
19
|
+
currentGroup.push(statement)
|
|
20
|
+
continue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (currentGroup.length > 0) {
|
|
24
|
+
groups.push(currentGroup)
|
|
25
|
+
currentGroup = []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (currentGroup.length > 0)
|
|
30
|
+
groups.push(currentGroup)
|
|
31
|
+
|
|
32
|
+
return groups
|
|
33
|
+
}
|
|
@@ -3,7 +3,7 @@ import {checkAlphabeticalSorting} from './checkAlphabeticalSorting'
|
|
|
3
3
|
import {checkGroupOrdering} from './checkGroupOrdering'
|
|
4
4
|
import {checkSpecifiersSorting} from './checkSpecifiersSorting'
|
|
5
5
|
import {createFix} from './createFix'
|
|
6
|
-
import {
|
|
6
|
+
import {getReExportGroups} from './getReExportGroups'
|
|
7
7
|
import type {ReExportError} from './ReExportError'
|
|
8
8
|
import type {Rule} from 'eslint'
|
|
9
9
|
import type {TSESTree} from '@typescript-eslint/types'
|
|
@@ -27,24 +27,30 @@ export const sortedReExports: Rule.RuleModule = {
|
|
|
27
27
|
return {
|
|
28
28
|
Program(node) {
|
|
29
29
|
const body = node.body as TSESTree.ProgramStatement[]
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
30
|
+
const reExportGroups = getReExportGroups(body)
|
|
31
|
+
if (reExportGroups.length === 0)
|
|
32
32
|
return
|
|
33
33
|
|
|
34
|
-
const
|
|
35
|
-
const errors: ReExportError[] = [
|
|
36
|
-
...checkGroupOrdering(categorized),
|
|
37
|
-
...checkAlphabeticalSorting(categorized),
|
|
38
|
-
...checkSpecifiersSorting(categorized),
|
|
39
|
-
]
|
|
34
|
+
const allErrors: ReExportError[] = []
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
// Check each re-export group independently
|
|
37
|
+
for (const group of reExportGroups) {
|
|
38
|
+
const categorized = categorizeReExports(group)
|
|
39
|
+
const errors: ReExportError[] = [
|
|
40
|
+
...checkGroupOrdering(categorized),
|
|
41
|
+
...checkAlphabeticalSorting(categorized),
|
|
42
|
+
...checkSpecifiersSorting(categorized),
|
|
43
|
+
]
|
|
44
|
+
allErrors.push(...errors)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const error of allErrors) {
|
|
42
48
|
context.report({
|
|
43
49
|
node: error.node,
|
|
44
50
|
messageId: error.messageId,
|
|
45
51
|
fix(fixer) {
|
|
46
52
|
const sourceCode = context.sourceCode
|
|
47
|
-
return createFix(fixer,
|
|
53
|
+
return createFix(fixer, reExportGroups, sourceCode)
|
|
48
54
|
},
|
|
49
55
|
})
|
|
50
56
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type {TSESTree} from '@typescript-eslint/types'
|
|
2
|
-
|
|
3
|
-
export function getImportDeclarations(programBody: TSESTree.ProgramStatement[]): TSESTree.ImportDeclaration[] {
|
|
4
|
-
return programBody.filter(
|
|
5
|
-
(statement): statement is TSESTree.ImportDeclaration =>
|
|
6
|
-
statement.type === 'ImportDeclaration',
|
|
7
|
-
)
|
|
8
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type {ReExportDeclaration} from './ReExportDeclaration'
|
|
2
|
-
import type {TSESTree} from '@typescript-eslint/types'
|
|
3
|
-
|
|
4
|
-
export function getReExportDeclarations(
|
|
5
|
-
programBody: TSESTree.ProgramStatement[],
|
|
6
|
-
): ReExportDeclaration[] {
|
|
7
|
-
return programBody.filter(
|
|
8
|
-
(statement): statement is ReExportDeclaration =>
|
|
9
|
-
(statement.type === 'ExportNamedDeclaration' && statement.source !== null)
|
|
10
|
-
|| statement.type === 'ExportAllDeclaration',
|
|
11
|
-
)
|
|
12
|
-
}
|