@borela-tech/eslint-config 2.0.1 → 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/.github/workflows/ci.yml +82 -0
- package/README.md +67 -0
- package/dist/index.js +511 -78
- package/dist/index.js.map +1 -1
- package/package.json +8 -1
- package/src/index.ts +9 -0
- package/src/lib/compare.ts +3 -0
- package/src/rules/__tests__/importsAndReExportsAtTop.test.ts +118 -0
- package/src/rules/__tests__/individualReExports.test.ts +62 -0
- package/src/rules/__tests__/sortedImports.test.ts +46 -3
- package/src/rules/__tests__/sortedReExports.test.ts +194 -0
- package/src/rules/importsAndReExportsAtTop/CategorizedStatements.ts +8 -0
- package/src/rules/importsAndReExportsAtTop/ReExport.ts +5 -0
- package/src/rules/importsAndReExportsAtTop/StatementIndices.ts +5 -0
- package/src/rules/importsAndReExportsAtTop/categorizeStatements.ts +27 -0
- package/src/rules/importsAndReExportsAtTop/findFirstIndices.ts +25 -0
- package/src/rules/importsAndReExportsAtTop/generateSortedText.ts +18 -0
- package/src/rules/importsAndReExportsAtTop/getStatementType.ts +17 -0
- package/src/rules/importsAndReExportsAtTop/hasViolation.ts +29 -0
- package/src/rules/importsAndReExportsAtTop/index.ts +45 -0
- package/src/rules/importsAndReExportsAtTop/statementType.ts +4 -0
- package/src/rules/individualImports.ts +5 -14
- package/src/rules/individualReExports.ts +52 -0
- package/src/rules/sortedImports/CategorizedImport.ts +2 -2
- package/src/rules/sortedImports/ImportError.ts +2 -2
- package/src/rules/sortedImports/ImportGroup.ts +5 -1
- package/src/rules/sortedImports/ImportGroupOrder.ts +8 -0
- package/src/rules/sortedImports/areSpecifiersSorted.ts +4 -5
- package/src/rules/sortedImports/categorizeImport.ts +4 -0
- package/src/rules/sortedImports/checkAlphabeticalSorting.ts +4 -3
- package/src/rules/sortedImports/checkGroupOrdering.ts +2 -3
- package/src/rules/sortedImports/createFix/buildSortedCode.ts +2 -2
- package/src/rules/sortedImports/createFix/formatNamedImport.ts +5 -8
- package/src/rules/sortedImports/createFix/getReplacementRange.ts +1 -1
- package/src/rules/sortedImports/createFix/index.ts +26 -6
- package/src/rules/sortedImports/createFix/sortImportGroups.ts +5 -4
- package/src/rules/sortedImports/getImportGroups.ts +23 -0
- package/src/rules/sortedImports/getNamedSpecifiers.ts +3 -4
- package/src/rules/sortedImports/getSortKey.ts +3 -3
- package/src/rules/sortedImports/getSpecifierName.ts +2 -2
- package/src/rules/sortedImports/index.ts +17 -11
- package/src/rules/sortedImports/sortSpecifiersText.ts +7 -6
- package/src/rules/sortedReExports/CategorizedNamedReExport.ts +6 -0
- package/src/rules/sortedReExports/CategorizedReExport.ts +15 -0
- package/src/rules/sortedReExports/ReExportDeclaration.ts +5 -0
- package/src/rules/sortedReExports/ReExportError.ts +6 -0
- package/src/rules/sortedReExports/ReExportGroup.ts +4 -0
- package/src/rules/sortedReExports/ReExportGroupOrder.ts +7 -0
- package/src/rules/sortedReExports/areSpecifiersSorted.ts +9 -0
- package/src/rules/sortedReExports/categorizeReExport.ts +17 -0
- package/src/rules/sortedReExports/categorizeReExports.ts +14 -0
- package/src/rules/sortedReExports/checkAlphabeticalSorting.ts +25 -0
- package/src/rules/sortedReExports/checkGroupOrdering.ts +21 -0
- package/src/rules/sortedReExports/checkSpecifiersSorting.ts +23 -0
- package/src/rules/sortedReExports/createFix/buildSortedCode.ts +28 -0
- package/src/rules/sortedReExports/createFix/findFirstExportIndex.ts +11 -0
- package/src/rules/sortedReExports/createFix/findLastExportIndex.ts +12 -0
- package/src/rules/sortedReExports/createFix/formatNamedReExport.ts +20 -0
- package/src/rules/sortedReExports/createFix/getReplacementRange.ts +22 -0
- package/src/rules/sortedReExports/createFix/groupReExportsByType.ts +17 -0
- package/src/rules/sortedReExports/createFix/index.ts +48 -0
- package/src/rules/sortedReExports/createFix/sortExportGroups.ts +11 -0
- package/src/rules/sortedReExports/getNamedSpecifiers.ts +9 -0
- package/src/rules/sortedReExports/getReExportGroups.ts +33 -0
- package/src/rules/sortedReExports/getSortKey.ts +16 -0
- package/src/rules/sortedReExports/getSpecifierName.ts +7 -0
- package/src/rules/sortedReExports/index.ts +60 -0
- package/src/rules/sortedReExports/isNamedReExport.ts +6 -0
- package/src/rules/sortedReExports/sortSpecifiersText.ts +15 -0
- package/src/rules/sortedImports/getImportDeclarations.ts +0 -8
- /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
|
+
[](https://github.com/borela-tech/eslint-config/actions/workflows/ci.yml)
|
|
4
|
+
[](https://badge.fury.io/js/@borela-tech%2Feslint-config)
|
|
5
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
|
+

|
|
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
|
+
```
|