@borela-tech/eslint-config 2.0.0 → 2.1.0

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.
Files changed (77) hide show
  1. package/.github/workflows/ci.yml +82 -0
  2. package/README.md +67 -0
  3. package/bin/lint +2 -1
  4. package/bin/typecheck +8 -0
  5. package/dist/index.js +478 -51
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -1
  8. package/src/index.ts +9 -0
  9. package/src/lib/compare.ts +3 -0
  10. package/src/rules/__tests__/importsAndReExportsAtTop.test.ts +118 -0
  11. package/src/rules/__tests__/individualImports.test.ts +2 -2
  12. package/src/rules/__tests__/individualReExports.test.ts +62 -0
  13. package/src/rules/__tests__/sortedImports.test.ts +38 -4
  14. package/src/rules/__tests__/sortedReExports.test.ts +151 -0
  15. package/src/rules/importsAndReExportsAtTop/CategorizedStatements.ts +8 -0
  16. package/src/rules/importsAndReExportsAtTop/ReExport.ts +5 -0
  17. package/src/rules/importsAndReExportsAtTop/StatementIndices.ts +5 -0
  18. package/src/rules/importsAndReExportsAtTop/categorizeStatements.ts +27 -0
  19. package/src/rules/importsAndReExportsAtTop/findFirstIndices.ts +25 -0
  20. package/src/rules/importsAndReExportsAtTop/generateSortedText.ts +18 -0
  21. package/src/rules/importsAndReExportsAtTop/getStatementType.ts +17 -0
  22. package/src/rules/importsAndReExportsAtTop/hasViolation.ts +29 -0
  23. package/src/rules/importsAndReExportsAtTop/index.ts +45 -0
  24. package/src/rules/importsAndReExportsAtTop/statementType.ts +4 -0
  25. package/src/rules/individualImports.ts +5 -14
  26. package/src/rules/individualReExports.ts +52 -0
  27. package/src/rules/sortedImports/CategorizedImport.ts +2 -2
  28. package/src/rules/sortedImports/ImportError.ts +2 -2
  29. package/src/rules/sortedImports/ImportGroup.ts +5 -1
  30. package/src/rules/sortedImports/ImportGroupOrder.ts +8 -0
  31. package/src/rules/sortedImports/areSpecifiersSorted.ts +4 -5
  32. package/src/rules/sortedImports/categorizeImport.ts +9 -2
  33. package/src/rules/sortedImports/categorizeImports.ts +3 -3
  34. package/src/rules/sortedImports/checkAlphabeticalSorting.ts +4 -3
  35. package/src/rules/sortedImports/checkGroupOrdering.ts +2 -3
  36. package/src/rules/sortedImports/checkSpecifiersSorting.ts +2 -2
  37. package/src/rules/sortedImports/createFix/buildSortedCode.ts +4 -4
  38. package/src/rules/sortedImports/createFix/findLastImportIndex.ts +2 -2
  39. package/src/rules/sortedImports/createFix/formatNamedImport.ts +5 -8
  40. package/src/rules/sortedImports/createFix/getReplacementRange.ts +6 -18
  41. package/src/rules/sortedImports/createFix/groupImportsByType.ts +1 -0
  42. package/src/rules/sortedImports/createFix/index.ts +5 -6
  43. package/src/rules/sortedImports/createFix/sortImportGroups.ts +5 -2
  44. package/src/rules/sortedImports/getImportDeclarations.ts +3 -4
  45. package/src/rules/sortedImports/getNamedSpecifiers.ts +3 -4
  46. package/src/rules/sortedImports/getSortKey.ts +7 -7
  47. package/src/rules/sortedImports/getSpecifierName.ts +2 -2
  48. package/src/rules/sortedImports/index.ts +6 -4
  49. package/src/rules/sortedImports/sortSpecifiersText.ts +7 -6
  50. package/src/rules/sortedReExports/CategorizedNamedReExport.ts +6 -0
  51. package/src/rules/sortedReExports/CategorizedReExport.ts +15 -0
  52. package/src/rules/sortedReExports/ReExportDeclaration.ts +5 -0
  53. package/src/rules/sortedReExports/ReExportError.ts +6 -0
  54. package/src/rules/sortedReExports/ReExportGroup.ts +4 -0
  55. package/src/rules/sortedReExports/ReExportGroupOrder.ts +7 -0
  56. package/src/rules/sortedReExports/areSpecifiersSorted.ts +9 -0
  57. package/src/rules/sortedReExports/categorizeReExport.ts +17 -0
  58. package/src/rules/sortedReExports/categorizeReExports.ts +14 -0
  59. package/src/rules/sortedReExports/checkAlphabeticalSorting.ts +25 -0
  60. package/src/rules/sortedReExports/checkGroupOrdering.ts +21 -0
  61. package/src/rules/sortedReExports/checkSpecifiersSorting.ts +23 -0
  62. package/src/rules/sortedReExports/createFix/buildSortedCode.ts +28 -0
  63. package/src/rules/sortedReExports/createFix/findFirstExportIndex.ts +11 -0
  64. package/src/rules/sortedReExports/createFix/findLastExportIndex.ts +12 -0
  65. package/src/rules/sortedReExports/createFix/formatNamedReExport.ts +20 -0
  66. package/src/rules/sortedReExports/createFix/getReplacementRange.ts +22 -0
  67. package/src/rules/sortedReExports/createFix/groupReExportsByType.ts +17 -0
  68. package/src/rules/sortedReExports/createFix/index.ts +29 -0
  69. package/src/rules/sortedReExports/createFix/sortExportGroups.ts +11 -0
  70. package/src/rules/sortedReExports/getNamedSpecifiers.ts +9 -0
  71. package/src/rules/sortedReExports/getReExportDeclarations.ts +12 -0
  72. package/src/rules/sortedReExports/getSortKey.ts +16 -0
  73. package/src/rules/sortedReExports/getSpecifierName.ts +7 -0
  74. package/src/rules/sortedReExports/index.ts +54 -0
  75. package/src/rules/sortedReExports/isNamedReExport.ts +6 -0
  76. package/src/rules/sortedReExports/sortSpecifiersText.ts +15 -0
  77. /package/src/{rules/sortedImports/createFix → lib}/ReplacementRange.ts +0 -0
@@ -0,0 +1,82 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ lint:
13
+ name: Lint
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Setup Node.js
19
+ uses: actions/setup-node@v4
20
+ with:
21
+ node-version-file: '.node-version'
22
+ cache: 'npm'
23
+
24
+ - name: Install dependencies
25
+ run: npm ci
26
+
27
+ - name: Run lint
28
+ run: ./bin/lint
29
+
30
+ typecheck:
31
+ name: Typecheck
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Setup Node.js
37
+ uses: actions/setup-node@v4
38
+ with:
39
+ node-version-file: '.node-version'
40
+ cache: 'npm'
41
+
42
+ - name: Install dependencies
43
+ run: npm ci
44
+
45
+ - name: Run typecheck
46
+ run: ./bin/typecheck
47
+
48
+ test:
49
+ name: Test
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+
54
+ - name: Setup Node.js
55
+ uses: actions/setup-node@v4
56
+ with:
57
+ node-version-file: '.node-version'
58
+ cache: 'npm'
59
+
60
+ - name: Install dependencies
61
+ run: npm ci
62
+
63
+ - name: Run tests
64
+ run: ./bin/test
65
+
66
+ build:
67
+ name: Build
68
+ runs-on: ubuntu-latest
69
+ steps:
70
+ - uses: actions/checkout@v4
71
+
72
+ - name: Setup Node.js
73
+ uses: actions/setup-node@v4
74
+ with:
75
+ node-version-file: '.node-version'
76
+ cache: 'npm'
77
+
78
+ - name: Install dependencies
79
+ run: npm ci
80
+
81
+ - name: Run build
82
+ run: ./bin/build
package/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # @borela-tech/eslint-config
2
2
 
3
+ [![CI](https://github.com/borela-tech/eslint-config/actions/workflows/ci.yml/badge.svg)](https://github.com/borela-tech/eslint-config/actions/workflows/ci.yml)
4
+ [![npm version](https://badge.fury.io/js/@borela-tech%2Feslint-config.svg)](https://badge.fury.io/js/@borela-tech%2Feslint-config)
5
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+ ![Node Version](https://img.shields.io/badge/node-v24.1.0-brightgreen)
7
+
3
8
  Shared ESLint configuration for Borela Tech projects.
4
9
 
5
10
  ## Features
@@ -9,6 +14,7 @@ Shared ESLint configuration for Borela Tech projects.
9
14
  - ESLint
10
15
  - TypeScript
11
16
  - React (if applicable)
17
+ - Custom rules for consistent import/export organization
12
18
 
13
19
  ## Installation
14
20
 
@@ -25,3 +31,64 @@ following code:
25
31
  import {CONFIG} from '@borela-tech/eslint-config'
26
32
  export default CONFIG
27
33
  ```
34
+
35
+ ## Custom Rules
36
+
37
+ This package includes several custom ESLint rules to enforce consistent import and export organization. All rules are auto-fixable.
38
+
39
+ ### `sorted-imports`
40
+
41
+ Enforces imports are sorted alphabetically within their respective groups:
42
+
43
+ 1. **Side-effect imports** (e.g., `import 'module'`)
44
+ 2. **Default imports** (e.g., `import React from 'react'`)
45
+ 3. **Named imports** (e.g., `import { useState } from 'react'`)
46
+ 4. **Type imports** (e.g., `import type { Config } from 'module'`)
47
+
48
+ Within each group, imports are sorted alphabetically by module source. Named import specifiers within each import are also sorted alphabetically.
49
+
50
+ ### `sorted-re-exports`
51
+
52
+ Enforces re-exports are sorted alphabetically within their respective groups:
53
+
54
+ 1. **Re-export all** (e.g., `export * from 'module'`)
55
+ 2. **Re-export named** (e.g., `export { foo, bar } from 'module'`)
56
+ 3. **Re-export type** (e.g., `export type { Type1, Type2 } from 'module'`)
57
+
58
+ Within each group, re-exports are sorted alphabetically by module source. Named export specifiers are also sorted alphabetically.
59
+
60
+ ### `imports-and-re-exports-at-top`
61
+
62
+ Ensures all imports and re-exports appear at the top of the file before any other statements.
63
+
64
+ ### `individual-imports`
65
+
66
+ Enforces one import per statement instead of grouped imports:
67
+
68
+ **Bad:**
69
+ ```typescript
70
+ import {foo, bar, baz} from 'module'
71
+ ```
72
+
73
+ **Good:**
74
+ ```typescript
75
+ import {foo} from 'module'
76
+ import {bar} from 'module'
77
+ import {baz} from 'module'
78
+ ```
79
+
80
+ ### `individual-re-exports`
81
+
82
+ Enforces one re-export per statement instead of grouped re-exports:
83
+
84
+ **Bad:**
85
+ ```typescript
86
+ export {foo, bar, baz} from 'module'
87
+ ```
88
+
89
+ **Good:**
90
+ ```typescript
91
+ export {foo} from 'module'
92
+ export {bar} from 'module'
93
+ export {baz} from 'module'
94
+ ```
package/bin/lint CHANGED
@@ -8,6 +8,7 @@ npx eslint \
8
8
  --ext ts \
9
9
  --max-warnings 0 \
10
10
  --report-unused-disable-directives \
11
- .
11
+ . \
12
+ $@
12
13
 
13
14
  popd > /dev/null
package/bin/typecheck ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env -S bash -e -o pipefail
2
+
3
+ SCRIPT_DIR=$(dirname -- "${BASH_SOURCE[0]}")
4
+ pushd "$SCRIPT_DIR/.." > /dev/null
5
+
6
+ npx tsc --noEmit
7
+
8
+ popd > /dev/null