@borela-tech/eslint-config 2.1.1 → 2.2.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 (75) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.js +291 -58
  3. package/dist/index.js.map +1 -1
  4. package/package.json +3 -2
  5. package/src/index.ts +18 -5
  6. package/src/rules/__tests__/importsAndReExportsAtTop.test.ts +3 -33
  7. package/src/rules/__tests__/individualImports.test.ts +3 -1
  8. package/src/rules/__tests__/individualReExports.test.ts +3 -1
  9. package/src/rules/__tests__/multilineUnionTypes.test.ts +75 -0
  10. package/src/rules/__tests__/singleLineImports.test.ts +129 -0
  11. package/src/rules/__tests__/singleLineReExports.test.ts +100 -0
  12. package/src/rules/__tests__/sortedImports.test.ts +37 -1
  13. package/src/rules/__tests__/sortedReExports.test.ts +27 -1
  14. package/src/rules/importsAndReExportsAtTop/CategorizedStatements.ts +2 -2
  15. package/src/rules/importsAndReExportsAtTop/StatementIndices.ts +3 -3
  16. package/src/rules/importsAndReExportsAtTop/categorizeStatements.ts +7 -6
  17. package/src/rules/importsAndReExportsAtTop/findStatementIndices.ts +25 -0
  18. package/src/rules/importsAndReExportsAtTop/generateSortedText.ts +4 -6
  19. package/src/rules/importsAndReExportsAtTop/getStatementType.ts +1 -1
  20. package/src/rules/importsAndReExportsAtTop/hasViolation.ts +13 -17
  21. package/src/rules/importsAndReExportsAtTop/index.ts +7 -7
  22. package/src/rules/importsAndReExportsAtTop/isImportDeclaration.ts +7 -0
  23. package/src/rules/importsAndReExportsAtTop/isReExport.ts +12 -0
  24. package/src/rules/individualImports.ts +4 -3
  25. package/src/rules/individualReExports.ts +8 -9
  26. package/src/rules/multilineUnionTypes/createFix.ts +13 -0
  27. package/src/rules/multilineUnionTypes/index.ts +52 -0
  28. package/src/rules/multilineUnionTypes/isMultiline.ts +6 -0
  29. package/src/rules/singleLineImports/createFix.ts +23 -0
  30. package/src/rules/singleLineImports/formatAttributes.ts +20 -0
  31. package/src/rules/singleLineImports/formatNamed.ts +9 -0
  32. package/src/rules/singleLineImports/formatSpecifiers.ts +32 -0
  33. package/src/rules/singleLineImports/index.ts +34 -0
  34. package/src/rules/singleLineImports/isMultiline.ts +6 -0
  35. package/src/rules/singleLineReExports/createFix.ts +29 -0
  36. package/src/rules/singleLineReExports/index.ts +48 -0
  37. package/src/rules/singleLineReExports/isMultiline.ts +6 -0
  38. package/src/rules/sortedImports/ImportError.ts +4 -1
  39. package/src/rules/sortedImports/ImportGroup.ts +2 -1
  40. package/src/rules/sortedImports/ImportGroupOrder.ts +2 -1
  41. package/src/rules/sortedImports/areSpecifiersSorted.ts +1 -1
  42. package/src/rules/sortedImports/categorizeImport.ts +4 -0
  43. package/src/rules/sortedImports/checkAlphabeticalSorting.ts +1 -1
  44. package/src/rules/sortedImports/createFix/buildSortedCode.ts +2 -1
  45. package/src/rules/sortedImports/createFix/formatNamedImport.ts +3 -2
  46. package/src/rules/sortedImports/createFix/getReplacementRange.ts +3 -3
  47. package/src/rules/sortedImports/createFix/groupImportsByType.ts +1 -0
  48. package/src/rules/sortedImports/createFix/index.ts +10 -11
  49. package/src/rules/sortedImports/createFix/sortImportGroups.ts +2 -1
  50. package/src/rules/sortedImports/getSortKey.ts +8 -2
  51. package/src/rules/sortedImports/index.ts +8 -5
  52. package/src/rules/sortedImports/sortSpecifiersText.ts +4 -3
  53. package/src/rules/sortedReExports/CategorizedReExport.ts +14 -3
  54. package/src/rules/sortedReExports/ReExportError.ts +5 -2
  55. package/src/rules/sortedReExports/ReExportGroup.ts +1 -0
  56. package/src/rules/sortedReExports/ReExportGroupOrder.ts +2 -1
  57. package/src/rules/sortedReExports/areSpecifiersSorted.ts +1 -1
  58. package/src/rules/sortedReExports/categorizeReExport.ts +8 -4
  59. package/src/rules/sortedReExports/categorizeReExports.ts +1 -1
  60. package/src/rules/sortedReExports/checkAlphabeticalSorting.ts +1 -1
  61. package/src/rules/sortedReExports/createFix/buildSortedCode.ts +2 -1
  62. package/src/rules/sortedReExports/createFix/formatNamedReExport.ts +3 -2
  63. package/src/rules/sortedReExports/createFix/getReplacementRange.ts +1 -1
  64. package/src/rules/sortedReExports/createFix/groupReExportsByType.ts +1 -0
  65. package/src/rules/sortedReExports/createFix/index.ts +10 -11
  66. package/src/rules/sortedReExports/createFix/sortExportGroups.ts +2 -1
  67. package/src/rules/sortedReExports/getNamedSpecifiers.ts +1 -1
  68. package/src/rules/sortedReExports/getReExportGroups.ts +1 -1
  69. package/src/rules/sortedReExports/getSortKey.ts +11 -5
  70. package/src/rules/sortedReExports/index.ts +8 -5
  71. package/src/rules/sortedReExports/isNamedReExport.ts +2 -2
  72. package/src/rules/sortedReExports/sortSpecifiersText.ts +4 -3
  73. package/src/rules/importsAndReExportsAtTop/ReExport.ts +0 -5
  74. package/src/rules/importsAndReExportsAtTop/findFirstIndices.ts +0 -25
  75. /package/src/{rules/sortedReExports → lib}/ReExportDeclaration.ts +0 -0
@@ -1,18 +1,17 @@
1
1
  import {buildSortedCode} from './buildSortedCode'
2
2
  import {categorizeReExports} from '../categorizeReExports'
3
3
  import {groupReExportsByType} from './groupReExportsByType'
4
- import {ReExportDeclaration} from '../ReExportDeclaration'
5
4
  import {sortExportGroups} from './sortExportGroups'
6
- import type {Rule} from 'eslint'
5
+ import type {ReExportDeclaration} from '@lib/ReExportDeclaration'
6
+ import type {TSESLint} from '@typescript-eslint/utils'
7
7
 
8
8
  function createFixForGroup(
9
- fixer: Rule.RuleFixer,
9
+ fixer: TSESLint.RuleFixer,
10
10
  reExportDeclarations: ReExportDeclaration[],
11
- sourceCode: {getText: (node?: unknown) => string},
12
- ): Rule.Fix | null {
13
- if (reExportDeclarations.length === 0) {
11
+ sourceCode: TSESLint.SourceCode,
12
+ ) {
13
+ if (reExportDeclarations.length === 0)
14
14
  return null
15
- }
16
15
 
17
16
  const categorized = categorizeReExports(reExportDeclarations)
18
17
  const grouped = groupReExportsByType(categorized)
@@ -32,11 +31,11 @@ function createFixForGroup(
32
31
  }
33
32
 
34
33
  export function createFix(
35
- fixer: Rule.RuleFixer,
34
+ fixer: TSESLint.RuleFixer,
36
35
  reExportGroups: ReExportDeclaration[][],
37
- sourceCode: {getText: (node?: unknown) => string},
38
- ): Rule.Fix[] {
39
- const fixes: Rule.Fix[] = []
36
+ sourceCode: TSESLint.SourceCode,
37
+ ): TSESLint.RuleFix[] {
38
+ const fixes: TSESLint.RuleFix[] = []
40
39
 
41
40
  for (const group of reExportGroups) {
42
41
  const fix = createFixForGroup(fixer, group, sourceCode)
@@ -1,4 +1,4 @@
1
- import {compare} from '../../../lib/compare'
1
+ import {compare} from '@lib/compare'
2
2
  import type {CategorizedReExport} from '../CategorizedReExport'
3
3
  import type {ReExportGroup} from '../ReExportGroup'
4
4
 
@@ -6,6 +6,7 @@ export function sortExportGroups(
6
6
  grouped: Record<ReExportGroup, CategorizedReExport[]>,
7
7
  ): void {
8
8
  grouped['re-export-all'].sort((a, b) => compare(a.sortKey, b.sortKey))
9
+ grouped['re-export-namespace'].sort((a, b) => compare(a.sortKey, b.sortKey))
9
10
  grouped['re-export-named'].sort((a, b) => compare(a.sortKey, b.sortKey))
10
11
  grouped['re-export-type'].sort((a, b) => compare(a.sortKey, b.sortKey))
11
12
  }
@@ -5,5 +5,5 @@ export function getNamedSpecifiers(
5
5
  ): TSESTree.ExportSpecifier[] {
6
6
  return declaration.specifiers.filter(
7
7
  s => s.type === 'ExportSpecifier' && s.local.type === 'Identifier',
8
- ) as TSESTree.ExportSpecifier[]
8
+ )
9
9
  }
@@ -1,4 +1,4 @@
1
- import type {ReExportDeclaration} from './ReExportDeclaration'
1
+ import type {ReExportDeclaration} from '@lib/ReExportDeclaration'
2
2
  import type {TSESTree} from '@typescript-eslint/types'
3
3
 
4
4
  function isReExportDeclaration(
@@ -1,10 +1,16 @@
1
- import type {TSESTree} from '@typescript-eslint/types'
1
+ import {categorizeReExport} from './categorizeReExport'
2
+ import type {ReExportDeclaration} from '@lib/ReExportDeclaration'
2
3
 
3
- export function getSortKey(
4
- declaration: TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration,
5
- ): string {
6
- if (declaration.type === 'ExportAllDeclaration')
4
+ export function getSortKey(declaration: ReExportDeclaration): string {
5
+ const group = categorizeReExport(declaration)
6
+
7
+ if (declaration.type === 'ExportAllDeclaration') {
8
+ if (group === 're-export-namespace') {
9
+ if (declaration.exported?.type === 'Identifier')
10
+ return `*${declaration.exported.name}`
11
+ }
7
12
  return declaration.source.value
13
+ }
8
14
 
9
15
  const specifier = declaration.specifiers[0]
10
16
  if (!specifier)
@@ -5,14 +5,17 @@ import {checkSpecifiersSorting} from './checkSpecifiersSorting'
5
5
  import {createFix} from './createFix'
6
6
  import {getReExportGroups} from './getReExportGroups'
7
7
  import type {ReExportError} from './ReExportError'
8
- import type {Rule} from 'eslint'
9
- import type {TSESTree} from '@typescript-eslint/types'
8
+ import type {TSESLint} from '@typescript-eslint/utils'
10
9
 
11
- export const sortedReExports: Rule.RuleModule = {
10
+ type MessageIds =
11
+ | 'sortedReExports'
12
+ | 'sortedNames'
13
+ | 'wrongGroup'
14
+
15
+ export const sortedReExports: TSESLint.RuleModule<MessageIds, []> = {
12
16
  meta: {
13
17
  docs: {
14
18
  description: 'Enforce sorted exports alphabetically',
15
- recommended: true,
16
19
  },
17
20
  fixable: 'code',
18
21
  messages: {
@@ -26,7 +29,7 @@ export const sortedReExports: Rule.RuleModule = {
26
29
  create(context) {
27
30
  return {
28
31
  Program(node) {
29
- const body = node.body as TSESTree.ProgramStatement[]
32
+ const body = node.body
30
33
  const reExportGroups = getReExportGroups(body)
31
34
  if (reExportGroups.length === 0)
32
35
  return
@@ -1,6 +1,6 @@
1
- import {CategorizedNamedReExport} from './CategorizedNamedReExport'
1
+ import type {CategorizedNamedReExport} from './CategorizedNamedReExport'
2
2
  import type {CategorizedReExport} from './CategorizedReExport'
3
3
 
4
4
  export function isNamedReExport(x: CategorizedReExport): x is CategorizedNamedReExport {
5
- return x.group !== 're-export-all'
5
+ return x.group !== 're-export-all' && x.group !== 're-export-namespace'
6
6
  }
@@ -1,10 +1,11 @@
1
- import {compare} from '../../lib/compare'
1
+ import {compare} from '@lib/compare'
2
2
  import {getSpecifierName} from './getSpecifierName'
3
- import type {TSESTree} from '@typescript-eslint/types'
3
+ import type {TSESLint} from '@typescript-eslint/utils'
4
+ import type {TSESTree} from '@typescript-eslint/utils'
4
5
 
5
6
  export function sortSpecifiersText(
6
7
  specifiers: TSESTree.ExportSpecifier[],
7
- sourceCode: {getText: (node?: unknown) => string},
8
+ sourceCode: TSESLint.SourceCode,
8
9
  ): string {
9
10
  const sorted = [...specifiers].sort((a, b) => {
10
11
  const nameA = getSpecifierName(a)
@@ -1,5 +0,0 @@
1
- import type {TSESTree} from '@typescript-eslint/types'
2
-
3
- export type ReExport =
4
- | TSESTree.ExportAllDeclaration
5
- | TSESTree.ExportNamedDeclaration
@@ -1,25 +0,0 @@
1
- import {getStatementType} from './getStatementType'
2
- import type {StatementIndices} from './StatementIndices'
3
- import type {StatementType} from './statementType'
4
- import type {TSESTree} from '@typescript-eslint/types'
5
-
6
- export function findFirstIndices(
7
- statements: TSESTree.Statement[],
8
- ): StatementIndices {
9
- let firstImport = Infinity
10
- let firstReExport = Infinity
11
- let firstOther = -1
12
-
13
- for (let i = 0; i < statements.length; i++) {
14
- const type: StatementType = getStatementType(statements[i])
15
-
16
- if (type === 'import' && firstImport === Infinity)
17
- firstImport = i
18
- else if (type === 're-export' && firstReExport === Infinity)
19
- firstReExport = i
20
- else if (type === 'other' && firstOther === -1)
21
- firstOther = i
22
- }
23
-
24
- return {firstImport, firstReExport, firstOther}
25
- }