@borela-tech/eslint-config 2.2.1 → 2.3.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 (107) hide show
  1. package/README.md +308 -19
  2. package/dist/index.d.ts +5 -0
  3. package/dist/index.mjs +3589 -811
  4. package/dist/index.mjs.map +1 -1
  5. package/jest.config.ts +19 -0
  6. package/package.json +17 -8
  7. package/vite.config.ts +41 -0
  8. package/bin/build +0 -9
  9. package/bin/lint +0 -14
  10. package/bin/publish +0 -12
  11. package/bin/test +0 -12
  12. package/bin/typecheck +0 -8
  13. package/dist/index.d.mts +0 -5226
  14. package/src/index.ts +0 -149
  15. package/src/lib/ReExportDeclaration.ts +0 -5
  16. package/src/lib/ReplacementRange.ts +0 -4
  17. package/src/lib/compare.ts +0 -3
  18. package/src/rules/__tests__/dedent/countLeadingSpaces.ts +0 -4
  19. package/src/rules/__tests__/dedent/findMinIndent.ts +0 -7
  20. package/src/rules/__tests__/dedent/index.ts +0 -17
  21. package/src/rules/__tests__/dedent/interpolate.ts +0 -11
  22. package/src/rules/__tests__/dedent/removeEmptyPrefix.ts +0 -6
  23. package/src/rules/__tests__/dedent/removeEmptySuffix.ts +0 -6
  24. package/src/rules/__tests__/dedent/removeIndent.ts +0 -3
  25. package/src/rules/__tests__/importsAndReExportsAtTop.test.ts +0 -88
  26. package/src/rules/__tests__/individualImports.test.ts +0 -44
  27. package/src/rules/__tests__/individualReExports.test.ts +0 -64
  28. package/src/rules/__tests__/multilineUnionTypes.test.ts +0 -75
  29. package/src/rules/__tests__/singleLineImports.test.ts +0 -129
  30. package/src/rules/__tests__/singleLineReExports.test.ts +0 -100
  31. package/src/rules/__tests__/sortedImports.test.ts +0 -227
  32. package/src/rules/__tests__/sortedReExports.test.ts +0 -220
  33. package/src/rules/importsAndReExportsAtTop/CategorizedStatements.ts +0 -8
  34. package/src/rules/importsAndReExportsAtTop/StatementIndices.ts +0 -5
  35. package/src/rules/importsAndReExportsAtTop/categorizeStatements.ts +0 -28
  36. package/src/rules/importsAndReExportsAtTop/findStatementIndices.ts +0 -25
  37. package/src/rules/importsAndReExportsAtTop/generateSortedText.ts +0 -16
  38. package/src/rules/importsAndReExportsAtTop/getStatementType.ts +0 -17
  39. package/src/rules/importsAndReExportsAtTop/hasViolation.ts +0 -25
  40. package/src/rules/importsAndReExportsAtTop/index.ts +0 -45
  41. package/src/rules/importsAndReExportsAtTop/isImportDeclaration.ts +0 -7
  42. package/src/rules/importsAndReExportsAtTop/isReExport.ts +0 -12
  43. package/src/rules/importsAndReExportsAtTop/statementType.ts +0 -4
  44. package/src/rules/individualImports.ts +0 -38
  45. package/src/rules/individualReExports.ts +0 -51
  46. package/src/rules/multilineUnionTypes/createFix.ts +0 -13
  47. package/src/rules/multilineUnionTypes/index.ts +0 -52
  48. package/src/rules/multilineUnionTypes/isMultiline.ts +0 -6
  49. package/src/rules/singleLineImports/createFix.ts +0 -23
  50. package/src/rules/singleLineImports/formatAttributes.ts +0 -20
  51. package/src/rules/singleLineImports/formatNamed.ts +0 -9
  52. package/src/rules/singleLineImports/formatSpecifiers.ts +0 -32
  53. package/src/rules/singleLineImports/index.ts +0 -34
  54. package/src/rules/singleLineImports/isMultiline.ts +0 -6
  55. package/src/rules/singleLineReExports/createFix.ts +0 -29
  56. package/src/rules/singleLineReExports/index.ts +0 -48
  57. package/src/rules/singleLineReExports/isMultiline.ts +0 -6
  58. package/src/rules/sortedImports/CategorizedImport.ts +0 -8
  59. package/src/rules/sortedImports/ImportError.ts +0 -9
  60. package/src/rules/sortedImports/ImportGroup.ts +0 -6
  61. package/src/rules/sortedImports/ImportGroupOrder.ts +0 -9
  62. package/src/rules/sortedImports/areSpecifiersSorted.ts +0 -9
  63. package/src/rules/sortedImports/categorizeImport.ts +0 -23
  64. package/src/rules/sortedImports/categorizeImports.ts +0 -12
  65. package/src/rules/sortedImports/checkAlphabeticalSorting.ts +0 -23
  66. package/src/rules/sortedImports/checkGroupOrdering.ts +0 -21
  67. package/src/rules/sortedImports/checkSpecifiersSorting.ts +0 -21
  68. package/src/rules/sortedImports/createFix/buildSortedCode.ts +0 -23
  69. package/src/rules/sortedImports/createFix/findLastImportIndex.ts +0 -12
  70. package/src/rules/sortedImports/createFix/formatNamedImport.ts +0 -21
  71. package/src/rules/sortedImports/createFix/getReplacementRange.ts +0 -14
  72. package/src/rules/sortedImports/createFix/groupImportsByType.ts +0 -19
  73. package/src/rules/sortedImports/createFix/index.ts +0 -47
  74. package/src/rules/sortedImports/createFix/sortImportGroups.ts +0 -13
  75. package/src/rules/sortedImports/getImportGroups.ts +0 -23
  76. package/src/rules/sortedImports/getNamedSpecifiers.ts +0 -7
  77. package/src/rules/sortedImports/getSortKey.ts +0 -26
  78. package/src/rules/sortedImports/getSpecifierName.ts +0 -7
  79. package/src/rules/sortedImports/index.ts +0 -63
  80. package/src/rules/sortedImports/sortSpecifiersText.ts +0 -16
  81. package/src/rules/sortedReExports/CategorizedNamedReExport.ts +0 -6
  82. package/src/rules/sortedReExports/CategorizedReExport.ts +0 -26
  83. package/src/rules/sortedReExports/ReExportError.ts +0 -9
  84. package/src/rules/sortedReExports/ReExportGroup.ts +0 -5
  85. package/src/rules/sortedReExports/ReExportGroupOrder.ts +0 -8
  86. package/src/rules/sortedReExports/areSpecifiersSorted.ts +0 -9
  87. package/src/rules/sortedReExports/categorizeReExport.ts +0 -21
  88. package/src/rules/sortedReExports/categorizeReExports.ts +0 -14
  89. package/src/rules/sortedReExports/checkAlphabeticalSorting.ts +0 -25
  90. package/src/rules/sortedReExports/checkGroupOrdering.ts +0 -21
  91. package/src/rules/sortedReExports/checkSpecifiersSorting.ts +0 -23
  92. package/src/rules/sortedReExports/createFix/buildSortedCode.ts +0 -29
  93. package/src/rules/sortedReExports/createFix/findFirstExportIndex.ts +0 -11
  94. package/src/rules/sortedReExports/createFix/findLastExportIndex.ts +0 -12
  95. package/src/rules/sortedReExports/createFix/formatNamedReExport.ts +0 -21
  96. package/src/rules/sortedReExports/createFix/getReplacementRange.ts +0 -22
  97. package/src/rules/sortedReExports/createFix/groupReExportsByType.ts +0 -18
  98. package/src/rules/sortedReExports/createFix/index.ts +0 -47
  99. package/src/rules/sortedReExports/createFix/sortExportGroups.ts +0 -12
  100. package/src/rules/sortedReExports/getNamedSpecifiers.ts +0 -9
  101. package/src/rules/sortedReExports/getReExportGroups.ts +0 -33
  102. package/src/rules/sortedReExports/getSortKey.ts +0 -22
  103. package/src/rules/sortedReExports/getSpecifierName.ts +0 -7
  104. package/src/rules/sortedReExports/index.ts +0 -63
  105. package/src/rules/sortedReExports/isNamedReExport.ts +0 -6
  106. package/src/rules/sortedReExports/sortSpecifiersText.ts +0 -16
  107. package/tsdown.config.ts +0 -19
package/src/index.ts DELETED
@@ -1,149 +0,0 @@
1
- import eslint from '@eslint/js'
2
- import react from 'eslint-plugin-react'
3
- import reactHooks from 'eslint-plugin-react-hooks'
4
- import stylistic from '@stylistic/eslint-plugin'
5
- import typescript from 'typescript-eslint'
6
- import {importsAndReExportsAtTop} from './rules/importsAndReExportsAtTop'
7
- import {individualImports} from './rules/individualImports'
8
- import {individualReExports} from './rules/individualReExports'
9
- import {multilineUnionTypes} from './rules/multilineUnionTypes'
10
- import {singleLineImports} from './rules/singleLineImports'
11
- import {singleLineReExports} from './rules/singleLineReExports'
12
- import {sortedImports} from './rules/sortedImports'
13
- import {sortedReExports} from './rules/sortedReExports'
14
- import type {TSESLint} from '@typescript-eslint/utils'
15
-
16
- export const CONFIG: TSESLint.FlatConfig.ConfigArray = [
17
- {
18
- ignores: [
19
- 'src/graphql/sdk.ts',
20
- '**/node_modules/**',
21
- '**/dist/**',
22
- ],
23
- },
24
- {
25
- settings: {
26
- react: {
27
- version: '19',
28
- },
29
- },
30
- },
31
- eslint.configs.recommended,
32
- react.configs.flat.recommended,
33
- stylistic.configs.recommended,
34
- ...typescript.configs.recommended,
35
- ...typescript.configs.stylistic,
36
- {
37
- plugins: {
38
- 'react-hooks': reactHooks,
39
- },
40
- rules: reactHooks.configs.recommended.rules,
41
- },
42
- {
43
- plugins: {
44
- '@borela-tech': {
45
- rules: {
46
- 'imports-and-re-exports-at-top': importsAndReExportsAtTop,
47
- 'individual-imports': individualImports,
48
- 'individual-re-exports': individualReExports,
49
- 'multiline-union-types': multilineUnionTypes,
50
- 'single-line-imports': singleLineImports,
51
- 'single-line-re-exports': singleLineReExports,
52
- 'sorted-imports': sortedImports,
53
- 'sorted-re-exports': sortedReExports,
54
- },
55
- },
56
- },
57
- rules: {
58
- '@borela-tech/imports-and-re-exports-at-top': 'error',
59
- '@borela-tech/individual-imports': 'error',
60
- '@borela-tech/individual-re-exports': 'error',
61
- '@borela-tech/multiline-union-types': 'error',
62
- '@borela-tech/single-line-imports': 'error',
63
- '@borela-tech/single-line-re-exports': 'error',
64
- '@borela-tech/sorted-imports': 'error',
65
- '@borela-tech/sorted-re-exports': 'error',
66
- },
67
- },
68
- {
69
- rules: {
70
- 'capitalized-comments': [
71
- 'error',
72
- 'always',
73
- {ignoreConsecutiveComments: true},
74
- ],
75
- 'react/react-in-jsx-scope': 'off',
76
- '@stylistic/arrow-parens': [
77
- 'error',
78
- 'as-needed',
79
- ],
80
- '@stylistic/array-bracket-newline': [
81
- 'error',
82
- 'consistent',
83
- ],
84
- '@stylistic/array-bracket-spacing': [
85
- 'error',
86
- 'never',
87
- ],
88
- '@stylistic/array-element-newline': [
89
- 'error',
90
- 'consistent',
91
- ],
92
- '@stylistic/block-spacing': 'off',
93
- '@stylistic/brace-style': [
94
- 'error',
95
- '1tbs',
96
- {allowSingleLine: true},
97
- ],
98
- '@stylistic/indent': [
99
- 'error',
100
- 2,
101
- {ignoredNodes: ['TSMappedType > *']},
102
- ],
103
- '@stylistic/jsx-tag-spacing': [
104
- 'error',
105
- {
106
- afterOpening: 'never',
107
- beforeClosing: 'never',
108
- beforeSelfClosing: 'never',
109
- closingSlash: 'never',
110
- },
111
- ],
112
- '@stylistic/jsx-wrap-multilines': 'off',
113
- '@stylistic/lines-between-class-members': 'off',
114
- '@stylistic/object-curly-newline': [
115
- 'error',
116
- {consistent: true},
117
- ],
118
- '@stylistic/object-curly-spacing': [
119
- 'error',
120
- 'never',
121
- ],
122
- '@stylistic/operator-linebreak': [
123
- 'error',
124
- 'before',
125
- {overrides: {'=': 'after'}},
126
- ],
127
- '@stylistic/quotes': [
128
- 'error',
129
- 'single',
130
- {avoidEscape: true},
131
- ],
132
- '@stylistic/quote-props': [
133
- 'error',
134
- 'as-needed',
135
- ],
136
- '@stylistic/semi': [
137
- 'error',
138
- 'never',
139
- {beforeStatementContinuationChars: 'always'},
140
- ],
141
- '@typescript-eslint/no-empty-function': 'off',
142
- '@typescript-eslint/consistent-indexed-object-style': 'off',
143
- '@typescript-eslint/consistent-type-imports': [
144
- 'error',
145
- {fixStyle: 'separate-type-imports'},
146
- ],
147
- },
148
- },
149
- ]
@@ -1,5 +0,0 @@
1
- import type {TSESTree} from '@typescript-eslint/types'
2
-
3
- export type ReExportDeclaration =
4
- | TSESTree.ExportAllDeclaration
5
- | TSESTree.ExportNamedDeclaration
@@ -1,4 +0,0 @@
1
- export interface ReplacementRange {
2
- start: number
3
- end: number
4
- }
@@ -1,3 +0,0 @@
1
- export function compare(a: string, b: string): number {
2
- return a.localeCompare(b, 'en', {sensitivity: 'case'})
3
- }
@@ -1,4 +0,0 @@
1
- export function countLeadingSpaces(line: string): number {
2
- const match = line.match(/^(\s*)/)
3
- return match ? match[1].length : 0
4
- }
@@ -1,7 +0,0 @@
1
- import {countLeadingSpaces} from './countLeadingSpaces'
2
-
3
- export function findMinIndent(lines: string[]): number {
4
- const nonEmptyLines = lines.filter(line => line.trim().length > 0)
5
- const indents = nonEmptyLines.map(line => countLeadingSpaces(line))
6
- return Math.min(...indents)
7
- }
@@ -1,17 +0,0 @@
1
- import {findMinIndent} from './findMinIndent'
2
- import {interpolate} from './interpolate'
3
- import {removeEmptyPrefix} from './removeEmptyPrefix'
4
- import {removeEmptySuffix} from './removeEmptySuffix'
5
- import {removeIndent} from './removeIndent'
6
-
7
- export function dedent(
8
- strings: TemplateStringsArray,
9
- ...values: unknown[]
10
- ): string {
11
- const raw = interpolate(strings, values)
12
- const lines = raw.split('\n')
13
- const withoutPrefix = removeEmptyPrefix(lines)
14
- const trimmed = removeEmptySuffix(withoutPrefix)
15
- const indentSize = findMinIndent(trimmed)
16
- return removeIndent(trimmed, indentSize)
17
- }
@@ -1,11 +0,0 @@
1
- export function interpolate(
2
- strings: TemplateStringsArray,
3
- values: unknown[],
4
- ): string {
5
- let result = ''
6
- for (let i = 0; i < strings.length; i++) {
7
- result += strings[i]
8
- if (i < values.length) result += String(values[i])
9
- }
10
- return result
11
- }
@@ -1,6 +0,0 @@
1
- export function removeEmptyPrefix(lines: string[]): string[] {
2
- const copy = [...lines]
3
- while (copy.length > 0 && copy[0].trim() === '')
4
- copy.shift()
5
- return copy
6
- }
@@ -1,6 +0,0 @@
1
- export function removeEmptySuffix(lines: string[]): string[] {
2
- const copy = [...lines]
3
- while (copy.length > 0 && copy[copy.length - 1].trim() === '')
4
- copy.pop()
5
- return copy
6
- }
@@ -1,3 +0,0 @@
1
- export function removeIndent(lines: string[], indentSize: number): string {
2
- return lines.map(line => line.slice(indentSize)).join('\n')
3
- }
@@ -1,88 +0,0 @@
1
- import typescript from 'typescript-eslint'
2
- import {dedent} from './dedent'
3
- import {importsAndReExportsAtTop} from '../importsAndReExportsAtTop'
4
- import {RuleTester} from 'eslint'
5
- import type {Rule} from 'eslint'
6
-
7
- const rule = importsAndReExportsAtTop as unknown as Rule.RuleModule
8
- const ruleTester = new RuleTester({
9
- languageOptions: {
10
- parser: typescript.parser,
11
- parserOptions: {
12
- ecmaVersion: 2020,
13
- sourceType: 'module',
14
- },
15
- },
16
- })
17
-
18
- ruleTester.run('imports-and-re-exports-at-top', rule, {
19
- valid: [{
20
- code: dedent`
21
- import {a} from 'aaa'
22
- export {a} from 'aaa'
23
- const c = 1
24
- `,
25
- }, {
26
- code: dedent`
27
- import {a} from 'aaa'
28
- import {b} from 'bbb'
29
- export {c} from 'ccc'
30
- `,
31
- }, {
32
- code: dedent`
33
- import {a} from 'aaa'
34
- const c = 1
35
- function foo() {}
36
- `,
37
- }, {
38
- code: dedent`
39
- export {a} from 'aaa'
40
- export * from 'bbb'
41
- const c = 1
42
- `,
43
- }, {
44
- code: dedent`
45
- const c = 1
46
- function foo() {}
47
- `,
48
- }, {
49
- code: dedent`
50
- import {a} from 'aaa'
51
- `,
52
- }, {
53
- code: dedent`
54
- export {a} from 'aaa'
55
- `,
56
- }, {
57
- code: '',
58
- }],
59
- invalid: [{
60
- code: dedent`
61
- export {z} from 'zzz'
62
- const c = 1
63
- import {a} from 'aaa'
64
- function foo() {}
65
- export {b} from 'bbb'
66
- `,
67
- errors: [{messageId: 'importsAndReExportsAtTop'}],
68
- output: dedent`
69
- import {a} from 'aaa'
70
- export {z} from 'zzz'
71
- export {b} from 'bbb'
72
- const c = 1
73
- function foo() {}
74
- `,
75
- }, {
76
- code: dedent`
77
- const a = 1
78
- import {b} from 'bbb'
79
- export {c} from 'ccc'
80
- `,
81
- errors: [{messageId: 'importsAndReExportsAtTop'}],
82
- output: dedent`
83
- import {b} from 'bbb'
84
- export {c} from 'ccc'
85
- const a = 1
86
- `,
87
- }],
88
- })
@@ -1,44 +0,0 @@
1
- import typescript from 'typescript-eslint'
2
- import {dedent} from './dedent'
3
- import {individualImports} from '../individualImports'
4
- import {RuleTester} from 'eslint'
5
- import type {Rule} from 'eslint'
6
-
7
- const rule = individualImports as unknown as Rule.RuleModule
8
- const ruleTester = new RuleTester({
9
- languageOptions: {
10
- parser: typescript.parser,
11
- parserOptions: {
12
- ecmaVersion: 2020,
13
- sourceType: 'module',
14
- },
15
- },
16
- })
17
-
18
- ruleTester.run('individual-imports', rule, {
19
- valid: [{
20
- code: "import {foo} from 'bar'",
21
- }, {
22
- code: "import foo from 'bar'",
23
- }, {
24
- code: "import * as foo from 'bar'",
25
- }, {
26
- code: "import 'bar'",
27
- }],
28
- invalid: [{
29
- code: "import {foo, bar} from 'baz'",
30
- errors: [{messageId: 'individualImports'}],
31
- output: dedent`
32
- import {foo} from 'baz'
33
- import {bar} from 'baz'
34
- `,
35
- }, {
36
- code: "import {foo, bar, baz} from 'qux'",
37
- errors: [{messageId: 'individualImports'}],
38
- output: dedent`
39
- import {foo} from 'qux'
40
- import {bar} from 'qux'
41
- import {baz} from 'qux'
42
- `,
43
- }],
44
- })
@@ -1,64 +0,0 @@
1
- import typescript from 'typescript-eslint'
2
- import {dedent} from './dedent'
3
- import {individualReExports} from '../individualReExports'
4
- import {RuleTester} from 'eslint'
5
- import type {Rule} from 'eslint'
6
-
7
- const rule = individualReExports as unknown as Rule.RuleModule
8
- const ruleTester = new RuleTester({
9
- languageOptions: {
10
- parser: typescript.parser,
11
- parserOptions: {
12
- ecmaVersion: 2020,
13
- sourceType: 'module',
14
- },
15
- },
16
- })
17
-
18
- ruleTester.run('individual-re-exports', rule, {
19
- valid: [{
20
- code: "export {foo} from 'bar'",
21
- }, {
22
- code: "export {foo as bar} from 'baz'",
23
- }, {
24
- code: "export * from 'bar'",
25
- }, {
26
- code: "export default 'bar'",
27
- }, {
28
- code: 'export const foo = 1',
29
- }, {
30
- code: 'export function foo() {}',
31
- }, {
32
- code: 'export class Foo {}',
33
- }],
34
- invalid: [{
35
- code: "export type {foo, bar} from 'baz'",
36
- errors: [{messageId: 'individualReExports'}],
37
- output: dedent`
38
- export type {foo} from 'baz'
39
- export type {bar} from 'baz'
40
- `,
41
- }, {
42
- code: "export {foo, bar} from 'baz'",
43
- errors: [{messageId: 'individualReExports'}],
44
- output: dedent`
45
- export {foo} from 'baz'
46
- export {bar} from 'baz'
47
- `,
48
- }, {
49
- code: "export {foo, bar, baz} from 'qux'",
50
- errors: [{messageId: 'individualReExports'}],
51
- output: dedent`
52
- export {foo} from 'qux'
53
- export {bar} from 'qux'
54
- export {baz} from 'qux'
55
- `,
56
- }, {
57
- code: "export {foo as bar, baz as qux} from 'qux'",
58
- errors: [{messageId: 'individualReExports'}],
59
- output: dedent`
60
- export {foo as bar} from 'qux'
61
- export {baz as qux} from 'qux'
62
- `,
63
- }],
64
- })
@@ -1,75 +0,0 @@
1
- import typescript from 'typescript-eslint'
2
- import {dedent} from './dedent'
3
- import {multilineUnionTypes} from '../multilineUnionTypes'
4
- import {RuleTester} from 'eslint'
5
- import type {Rule} from 'eslint'
6
-
7
- const rule = multilineUnionTypes as unknown as Rule.RuleModule
8
- const ruleTester = new RuleTester({
9
- languageOptions: {
10
- parser: typescript.parser,
11
- parserOptions: {
12
- ecmaVersion: 2020,
13
- sourceType: 'module',
14
- },
15
- },
16
- })
17
-
18
- ruleTester.run('multiline-union-types', rule, {
19
- valid: [{
20
- code: 'type A = B',
21
- }, {
22
- code: dedent`
23
- type A =
24
- | B
25
- | C
26
- `,
27
- }, {
28
- code: dedent`
29
- export type A =
30
- | B
31
- | C
32
- | D
33
- `,
34
- }],
35
- invalid: [{
36
- code: 'type A = B | C | D',
37
- errors: [{messageId: 'singleLine'}],
38
- output: dedent`
39
- type A =
40
- | B
41
- | C
42
- | D
43
- `,
44
- }, {
45
- code: dedent`
46
- type A = B |
47
- C |
48
- D
49
- `,
50
- errors: [{messageId: 'missingPipes'}],
51
- output: dedent`
52
- type A =
53
- | B
54
- | C
55
- | D
56
- `,
57
- }, {
58
- code: 'type A = string | number | boolean',
59
- errors: [{messageId: 'singleLine'}],
60
- output: dedent`
61
- type A =
62
- | string
63
- | number
64
- | boolean
65
- `,
66
- }, {
67
- code: 'export type Foo = Bar | Baz',
68
- errors: [{messageId: 'singleLine'}],
69
- output: dedent`
70
- export type Foo =
71
- | Bar
72
- | Baz
73
- `,
74
- }],
75
- })
@@ -1,129 +0,0 @@
1
- import typescript from 'typescript-eslint'
2
- import {dedent} from './dedent'
3
- import {RuleTester} from 'eslint'
4
- import {singleLineImports} from '../singleLineImports'
5
- import type {Rule} from 'eslint'
6
-
7
- const rule = singleLineImports as unknown as Rule.RuleModule
8
- const ruleTester = new RuleTester({
9
- languageOptions: {
10
- parser: typescript.parser,
11
- parserOptions: {
12
- ecmaVersion: 2020,
13
- sourceType: 'module',
14
- },
15
- },
16
- })
17
-
18
- ruleTester.run('single-line-imports', rule, {
19
- valid: [{
20
- code: "import {foo} from 'bar'",
21
- }, {
22
- code: "import foo from 'bar'",
23
- }, {
24
- code: "import * as foo from 'bar'",
25
- }, {
26
- code: "import 'bar'",
27
- }, {
28
- code: "import type {Foo} from 'bar'",
29
- }, {
30
- code: "import foo, {bar} from 'baz'",
31
- }, {
32
- code: "import {a, b, c} from 'bar'",
33
- }, {
34
- code: "import {foo} from 'bar' with {type: 'json'}",
35
- }, {
36
- code: "import type {Foo} from 'bar' with {type: 'json'}",
37
- }],
38
- invalid: [{
39
- code: dedent`
40
- import {
41
- foo,
42
- } from 'bar'
43
- `,
44
- errors: [{messageId: 'multiline'}],
45
- output: dedent`
46
- import {foo} from 'bar'
47
- `,
48
- }, {
49
- code: dedent`
50
- import type {
51
- Foo,
52
- } from 'bar'
53
- `,
54
- errors: [{messageId: 'multiline'}],
55
- output: dedent`
56
- import type {Foo} from 'bar'
57
- `,
58
- }, {
59
- code: dedent`
60
- import {
61
- a,
62
- b,
63
- c,
64
- } from 'bar'
65
- `,
66
- errors: [{messageId: 'multiline'}],
67
- output: dedent`
68
- import {a, b, c} from 'bar'
69
- `,
70
- }, {
71
- code: dedent`
72
- import foo, {
73
- bar,
74
- } from 'baz'
75
- `,
76
- errors: [{messageId: 'multiline'}],
77
- output: dedent`
78
- import foo, {bar} from 'baz'
79
- `,
80
- }, {
81
- code: dedent`
82
- import
83
- foo
84
- from 'bar'
85
- `,
86
- errors: [{messageId: 'multiline'}],
87
- output: dedent`
88
- import foo from 'bar'
89
- `,
90
- }, {
91
- code: dedent`
92
- import * as foo
93
- from 'bar'
94
- `,
95
- errors: [{messageId: 'multiline'}],
96
- output: dedent`
97
- import * as foo from 'bar'
98
- `,
99
- }, {
100
- code: dedent`
101
- import
102
- 'bar'
103
- `,
104
- errors: [{messageId: 'multiline'}],
105
- output: dedent`
106
- import 'bar'
107
- `,
108
- }, {
109
- code: dedent`
110
- import {
111
- foo,
112
- } from 'bar' with {type: 'json'}
113
- `,
114
- errors: [{messageId: 'multiline'}],
115
- output: dedent`
116
- import {foo} from 'bar' with {type: 'json'}
117
- `,
118
- }, {
119
- code: dedent`
120
- import type {
121
- Foo,
122
- } from 'bar' with {type: 'json'}
123
- `,
124
- errors: [{messageId: 'multiline'}],
125
- output: dedent`
126
- import type {Foo} from 'bar' with {type: 'json'}
127
- `,
128
- }],
129
- })