eslint-plugin-perfectionist 4.11.0 → 4.12.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 (34) hide show
  1. package/dist/package.json.js +1 -1
  2. package/dist/rules/sort-array-includes.js +9 -17
  3. package/dist/rules/sort-classes.js +17 -23
  4. package/dist/rules/sort-decorators.js +7 -4
  5. package/dist/rules/sort-enums.js +9 -13
  6. package/dist/rules/sort-exports.js +9 -17
  7. package/dist/rules/sort-heritage-clauses.js +7 -4
  8. package/dist/rules/sort-imports/compute-common-selectors.js +119 -0
  9. package/dist/rules/sort-imports/is-side-effect-only-group.js +13 -0
  10. package/dist/rules/sort-imports/matches-tsconfig-paths.js +22 -0
  11. package/dist/rules/sort-imports/types.js +48 -0
  12. package/dist/rules/sort-imports/validate-side-effects-configuration.js +24 -0
  13. package/dist/rules/sort-imports.js +364 -297
  14. package/dist/rules/sort-jsx-props.js +18 -32
  15. package/dist/rules/sort-maps.js +8 -13
  16. package/dist/rules/sort-modules.js +14 -23
  17. package/dist/rules/sort-named-exports/types.js +14 -0
  18. package/dist/rules/sort-named-exports.js +76 -13
  19. package/dist/rules/sort-named-imports/types.js +14 -0
  20. package/dist/rules/sort-named-imports.js +79 -13
  21. package/dist/rules/sort-object-types.js +20 -34
  22. package/dist/rules/sort-objects.js +59 -52
  23. package/dist/rules/sort-union-types.js +19 -15
  24. package/dist/rules/sort-variable-declarations.js +1 -0
  25. package/dist/utils/compute-group.js +48 -0
  26. package/dist/utils/compute-nodes-in-circular-dependencies.js +5 -5
  27. package/dist/utils/get-newlines-between-option.js +2 -4
  28. package/dist/utils/is-node-dependent-on-other-node.js +11 -0
  29. package/dist/utils/report-all-errors.js +4 -2
  30. package/dist/utils/sort-nodes-by-dependencies.js +7 -3
  31. package/dist/utils/validate-generated-groups-configuration.js +44 -11
  32. package/package.json +3 -3
  33. package/dist/rules/sort-jsx-props/does-custom-group-match.js +0 -49
  34. package/dist/utils/use-groups.js +0 -33
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  const name = 'eslint-plugin-perfectionist'
4
- const version = '4.11.0'
4
+ const version = '4.12.0'
5
5
  exports.name = name
6
6
  exports.version = version
@@ -19,10 +19,10 @@ const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
19
19
  const createEslintRule = require('../utils/create-eslint-rule.js')
20
20
  const reportAllErrors = require('../utils/report-all-errors.js')
21
21
  const shouldPartition = require('../utils/should-partition.js')
22
+ const computeGroup = require('../utils/compute-group.js')
22
23
  const rangeToDiff = require('../utils/range-to-diff.js')
23
24
  const getSettings = require('../utils/get-settings.js')
24
25
  const isSortable = require('../utils/is-sortable.js')
25
- const useGroups = require('../utils/use-groups.js')
26
26
  const complete = require('../utils/complete.js')
27
27
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
28
28
  let defaultOptions = {
@@ -150,7 +150,6 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
150
150
  if (element === null) {
151
151
  return accumulator
152
152
  }
153
- let { defineGroup, getGroup } = useGroups.useGroups(options)
154
153
  let groupKind
155
154
  let selector
156
155
  if (element.type === 'SpreadElement') {
@@ -160,39 +159,32 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
160
159
  groupKind = 'literal'
161
160
  selector = 'literal'
162
161
  }
162
+ let name = getNodeName({ sourceCode, element })
163
163
  let predefinedGroups = generatePredefinedGroups.generatePredefinedGroups({
164
164
  cache: cachedGroupsByModifiersAndSelectors,
165
165
  selectors: [selector],
166
166
  modifiers: [],
167
167
  })
168
- for (let predefinedGroup of predefinedGroups) {
169
- defineGroup(predefinedGroup)
170
- }
171
- let name = getNodeName({ sourceCode, element })
172
- for (let customGroup of options.customGroups) {
173
- if (
168
+ let group = computeGroup.computeGroup({
169
+ customGroupMatcher: customGroup =>
174
170
  doesCustomGroupMatch.doesCustomGroupMatch({
175
171
  selectors: [selector],
176
172
  elementName: name,
177
173
  modifiers: [],
178
174
  customGroup,
179
- })
180
- ) {
181
- defineGroup(customGroup.groupName, true)
182
- if (getGroup() === customGroup.groupName) {
183
- break
184
- }
185
- }
186
- }
175
+ }),
176
+ predefinedGroups,
177
+ options,
178
+ })
187
179
  let sortingNode = {
188
180
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
189
181
  element,
190
182
  eslintDisabledLines,
191
183
  ),
192
184
  size: rangeToDiff.rangeToDiff(element, sourceCode),
193
- group: getGroup(),
194
185
  node: element,
195
186
  groupKind,
187
+ group,
196
188
  name,
197
189
  }
198
190
  let lastSortingNode =
@@ -19,10 +19,10 @@ const getDecoratorName = require('../utils/get-decorator-name.js')
19
19
  const reportAllErrors = require('../utils/report-all-errors.js')
20
20
  const shouldPartition = require('../utils/should-partition.js')
21
21
  const getGroupNumber = require('../utils/get-group-number.js')
22
+ const computeGroup = require('../utils/compute-group.js')
22
23
  const rangeToDiff = require('../utils/range-to-diff.js')
23
24
  const getSettings = require('../utils/get-settings.js')
24
25
  const isSortable = require('../utils/is-sortable.js')
25
- const useGroups = require('../utils/use-groups.js')
26
26
  const complete = require('../utils/complete.js')
27
27
  const matches = require('../utils/matches.js')
28
28
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
@@ -233,7 +233,6 @@ const sortClasses = createEslintRule.createEslintRule({
233
233
  var _a2, _b, _c, _d, _e
234
234
  let name
235
235
  let dependencies = []
236
- let { defineGroup, getGroup } = useGroups.useGroups(options)
237
236
  if (member.type === 'StaticBlock') {
238
237
  name = 'static'
239
238
  } else if (member.type === 'TSIndexSignature') {
@@ -402,11 +401,8 @@ const sortClasses = createEslintRule.createEslintRule({
402
401
  selectors,
403
402
  modifiers,
404
403
  })
405
- for (let predefinedGroup of predefinedGroups) {
406
- defineGroup(predefinedGroup)
407
- }
408
- for (let customGroup of options.customGroups) {
409
- if (
404
+ let group = computeGroup.computeGroup({
405
+ customGroupMatcher: customGroup =>
410
406
  doesCustomGroupMatch.doesCustomGroupMatch({
411
407
  elementValue: memberValue,
412
408
  elementName: name,
@@ -414,14 +410,10 @@ const sortClasses = createEslintRule.createEslintRule({
414
410
  decorators,
415
411
  modifiers,
416
412
  selectors,
417
- })
418
- ) {
419
- defineGroup(customGroup.groupName, true)
420
- if (getGroup() === customGroup.groupName) {
421
- break
422
- }
423
- }
424
- }
413
+ }),
414
+ predefinedGroups,
415
+ options,
416
+ })
425
417
  let overloadSignatureGroupMemberIndex =
426
418
  overloadSignatureGroups.findIndex(overloadSignatures =>
427
419
  overloadSignatures.includes(member),
@@ -432,13 +424,15 @@ const sortClasses = createEslintRule.createEslintRule({
432
424
  ? void 0
433
425
  : _d.at(-1)
434
426
  let sortingNode = {
435
- dependencyName: getDependencyName({
436
- nodeNameWithoutStartingHash: name.startsWith('#')
437
- ? name.slice(1)
438
- : name,
439
- isStatic: modifiers.includes('static'),
440
- isPrivateHash,
441
- }),
427
+ dependencyNames: [
428
+ getDependencyName({
429
+ nodeNameWithoutStartingHash: name.startsWith('#')
430
+ ? name.slice(1)
431
+ : name,
432
+ isStatic: modifiers.includes('static'),
433
+ isPrivateHash,
434
+ }),
435
+ ],
442
436
  overloadSignaturesGroupId:
443
437
  overloadSignatureGroupMemberIndex === -1
444
438
  ? null
@@ -454,9 +448,9 @@ const sortClasses = createEslintRule.createEslintRule({
454
448
  eslintDisabledLines,
455
449
  ),
456
450
  addSafetySemicolonWhenInline,
457
- group: getGroup(),
458
451
  node: member,
459
452
  dependencies,
453
+ group,
460
454
  name,
461
455
  }
462
456
  let lastSortingNode =
@@ -11,10 +11,10 @@ const getDecoratorName = require('../utils/get-decorator-name.js')
11
11
  const createEslintRule = require('../utils/create-eslint-rule.js')
12
12
  const reportAllErrors = require('../utils/report-all-errors.js')
13
13
  const shouldPartition = require('../utils/should-partition.js')
14
+ const computeGroup = require('../utils/compute-group.js')
14
15
  const rangeToDiff = require('../utils/range-to-diff.js')
15
16
  const getSettings = require('../utils/get-settings.js')
16
17
  const isSortable = require('../utils/is-sortable.js')
17
- const useGroups = require('../utils/use-groups.js')
18
18
  const complete = require('../utils/complete.js')
19
19
  let defaultOptions = {
20
20
  fallbackSort: { type: 'unsorted' },
@@ -163,20 +163,23 @@ let sortDecorators$1 = (context, options, decorators) => {
163
163
  let formattedMembers = decorators.reduce(
164
164
  (accumulator, decorator) => {
165
165
  var _a
166
- let { setCustomGroups, getGroup } = useGroups.useGroups(options)
167
166
  let name = getDecoratorName.getDecoratorName({
168
167
  sourceCode,
169
168
  decorator,
170
169
  })
171
- setCustomGroups(options.customGroups, name)
170
+ let group = computeGroup.computeGroup({
171
+ predefinedGroups: [],
172
+ options,
173
+ name,
174
+ })
172
175
  let sortingNode = {
173
176
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
174
177
  decorator,
175
178
  eslintDisabledLines,
176
179
  ),
177
180
  size: rangeToDiff.rangeToDiff(decorator, sourceCode),
178
- group: getGroup(),
179
181
  node: decorator,
182
+ group,
180
183
  name,
181
184
  }
182
185
  let lastSortingNode =
@@ -15,10 +15,10 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
15
15
  const reportAllErrors = require('../utils/report-all-errors.js')
16
16
  const shouldPartition = require('../utils/should-partition.js')
17
17
  const getEnumMembers = require('../utils/get-enum-members.js')
18
+ const computeGroup = require('../utils/compute-group.js')
18
19
  const rangeToDiff = require('../utils/range-to-diff.js')
19
20
  const getSettings = require('../utils/get-settings.js')
20
21
  const isSortable = require('../utils/is-sortable.js')
21
- const useGroups = require('../utils/use-groups.js')
22
22
  const complete = require('../utils/complete.js')
23
23
  let defaultOptions = {
24
24
  fallbackSort: { type: 'unsorted' },
@@ -109,23 +109,18 @@ const sortEnums = createEslintRule.createEslintRule({
109
109
  member.id.type === 'Literal'
110
110
  ? `${member.id.value}`
111
111
  : sourceCode.getText(member.id)
112
- let { defineGroup, getGroup } = useGroups.useGroups(options)
113
- for (let customGroup of options.customGroups) {
114
- if (
112
+ let group = computeGroup.computeGroup({
113
+ customGroupMatcher: customGroup =>
115
114
  doesCustomGroupMatch.doesCustomGroupMatch({
116
115
  elementValue: sourceCode.getText(member.initializer),
117
116
  elementName: name,
118
117
  selectors: [],
119
118
  modifiers: [],
120
119
  customGroup,
121
- })
122
- ) {
123
- defineGroup(customGroup.groupName, true)
124
- if (getGroup() === customGroup.groupName) {
125
- break
126
- }
127
- }
128
- }
120
+ }),
121
+ predefinedGroups: [],
122
+ options,
123
+ })
129
124
  let lastSortingNode =
130
125
  (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
131
126
  let sortingNode = {
@@ -144,9 +139,10 @@ const sortEnums = createEslintRule.createEslintRule({
144
139
  eslintDisabledLines,
145
140
  ),
146
141
  size: rangeToDiff.rangeToDiff(member, sourceCode),
147
- group: getGroup(),
142
+ dependencyNames: [name],
148
143
  node: member,
149
144
  dependencies,
145
+ group,
150
146
  name,
151
147
  }
152
148
  if (
@@ -14,9 +14,9 @@ const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
14
14
  const createEslintRule = require('../utils/create-eslint-rule.js')
15
15
  const reportAllErrors = require('../utils/report-all-errors.js')
16
16
  const shouldPartition = require('../utils/should-partition.js')
17
+ const computeGroup = require('../utils/compute-group.js')
17
18
  const rangeToDiff = require('../utils/range-to-diff.js')
18
19
  const getSettings = require('../utils/get-settings.js')
19
- const useGroups = require('../utils/use-groups.js')
20
20
  const complete = require('../utils/complete.js')
21
21
  let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
22
22
  let defaultOptions = {
@@ -59,7 +59,6 @@ const sortExports = createEslintRule.createEslintRule({
59
59
  let formattedMembers = [[]]
60
60
  let registerNode = node => {
61
61
  var _a
62
- let { defineGroup, getGroup } = useGroups.useGroups(options)
63
62
  let selector = 'export'
64
63
  let modifiers = []
65
64
  if (node.exportKind === 'value') {
@@ -67,30 +66,23 @@ const sortExports = createEslintRule.createEslintRule({
67
66
  } else {
68
67
  modifiers.push('type')
69
68
  }
69
+ let name = node.source.value
70
70
  let predefinedGroups = generatePredefinedGroups.generatePredefinedGroups({
71
71
  cache: cachedGroupsByModifiersAndSelectors,
72
72
  selectors: [selector],
73
73
  modifiers,
74
74
  })
75
- for (let predefinedGroup of predefinedGroups) {
76
- defineGroup(predefinedGroup)
77
- }
78
- let name = node.source.value
79
- for (let customGroup of options.customGroups) {
80
- if (
75
+ let group = computeGroup.computeGroup({
76
+ customGroupMatcher: customGroup =>
81
77
  doesCustomGroupMatch.doesCustomGroupMatch({
82
78
  selectors: [selector],
83
79
  elementName: name,
84
80
  customGroup,
85
81
  modifiers,
86
- })
87
- ) {
88
- defineGroup(customGroup.groupName, true)
89
- if (getGroup() === customGroup.groupName) {
90
- break
91
- }
92
- }
93
- }
82
+ }),
83
+ predefinedGroups,
84
+ options,
85
+ })
94
86
  let sortingNode = {
95
87
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
96
88
  node,
@@ -99,7 +91,7 @@ const sortExports = createEslintRule.createEslintRule({
99
91
  groupKind: node.exportKind === 'value' ? 'value' : 'type',
100
92
  size: rangeToDiff.rangeToDiff(node, sourceCode),
101
93
  addSafetySemicolonWhenInline: true,
102
- group: getGroup(),
94
+ group,
103
95
  name,
104
96
  node,
105
97
  }
@@ -8,10 +8,10 @@ const reportErrors = require('../utils/report-errors.js')
8
8
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
9
9
  const createEslintRule = require('../utils/create-eslint-rule.js')
10
10
  const reportAllErrors = require('../utils/report-all-errors.js')
11
+ const computeGroup = require('../utils/compute-group.js')
11
12
  const rangeToDiff = require('../utils/range-to-diff.js')
12
13
  const getSettings = require('../utils/get-settings.js')
13
14
  const isSortable = require('../utils/is-sortable.js')
14
- const useGroups = require('../utils/use-groups.js')
15
15
  const complete = require('../utils/complete.js')
16
16
  let defaultOptions = {
17
17
  fallbackSort: { type: 'unsorted' },
@@ -83,8 +83,11 @@ let sortHeritageClauses$1 = (context, options, heritageClauses) => {
83
83
  })
84
84
  let nodes = heritageClauses.map(heritageClause => {
85
85
  let name = getHeritageClauseExpressionName(heritageClause.expression)
86
- let { setCustomGroups, getGroup } = useGroups.useGroups(options)
87
- setCustomGroups(options.customGroups, name)
86
+ let group = computeGroup.computeGroup({
87
+ predefinedGroups: [],
88
+ options,
89
+ name,
90
+ })
88
91
  return {
89
92
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
90
93
  heritageClause,
@@ -92,7 +95,7 @@ let sortHeritageClauses$1 = (context, options, heritageClauses) => {
92
95
  ),
93
96
  size: rangeToDiff.rangeToDiff(heritageClause, sourceCode),
94
97
  node: heritageClause,
95
- group: getGroup(),
98
+ group,
96
99
  name,
97
100
  }
98
101
  })
@@ -0,0 +1,119 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const node_module = require('node:module')
4
+ const matchesTsconfigPaths = require('./matches-tsconfig-paths.js')
5
+ const getTypescriptImport = require('./get-typescript-import.js')
6
+ const matches = require('../../utils/matches.js')
7
+ let computeCommonSelectors = ({ tsConfigOutput, filename, options, name }) => {
8
+ let matchesInternalPattern = value =>
9
+ options.internalPattern.some(pattern => matches.matches(value, pattern))
10
+ let internalExternalGroup = matchesInternalPattern(name)
11
+ ? 'internal'
12
+ : getInternalOrExternalGroup({
13
+ tsConfigOutput,
14
+ filename,
15
+ name,
16
+ })
17
+ let commonSelectors = []
18
+ if (
19
+ tsConfigOutput &&
20
+ matchesTsconfigPaths.matchesTsconfigPaths({
21
+ tsConfigOutput,
22
+ name,
23
+ })
24
+ ) {
25
+ commonSelectors.push('tsconfig-path')
26
+ }
27
+ if (isIndex(name)) {
28
+ commonSelectors.push('index')
29
+ }
30
+ if (isSibling(name)) {
31
+ commonSelectors.push('sibling')
32
+ }
33
+ if (isParent(name)) {
34
+ commonSelectors.push('parent')
35
+ }
36
+ if (isSubpath(name)) {
37
+ commonSelectors.push('subpath')
38
+ }
39
+ if (internalExternalGroup === 'internal') {
40
+ commonSelectors.push('internal')
41
+ }
42
+ if (isCoreModule(name, options.environment)) {
43
+ commonSelectors.push('builtin')
44
+ }
45
+ if (internalExternalGroup === 'external') {
46
+ commonSelectors.push('external')
47
+ }
48
+ return commonSelectors
49
+ }
50
+ let bunModules = /* @__PURE__ */ new Set([
51
+ 'detect-libc',
52
+ 'bun:sqlite',
53
+ 'bun:test',
54
+ 'bun:wrap',
55
+ 'bun:ffi',
56
+ 'bun:jsc',
57
+ 'undici',
58
+ 'bun',
59
+ 'ws',
60
+ ])
61
+ let nodeBuiltinModules = new Set(node_module.builtinModules)
62
+ let builtinPrefixOnlyModules = /* @__PURE__ */ new Set([
63
+ 'node:sqlite',
64
+ 'node:test',
65
+ 'node:sea',
66
+ ])
67
+ let isCoreModule = (value, environment) => {
68
+ let valueToCheck = value.startsWith('node:') ? value.split('node:')[1] : value
69
+ return (
70
+ (!!valueToCheck && nodeBuiltinModules.has(valueToCheck)) ||
71
+ builtinPrefixOnlyModules.has(value) ||
72
+ (environment === 'bun' ? bunModules.has(value) : false)
73
+ )
74
+ }
75
+ let isParent = value => value.startsWith('..')
76
+ let isSibling = value => value.startsWith('./')
77
+ let isSubpath = value => value.startsWith('#')
78
+ let isIndex = value =>
79
+ [
80
+ './index.d.js',
81
+ './index.d.ts',
82
+ './index.js',
83
+ './index.ts',
84
+ './index',
85
+ './',
86
+ '.',
87
+ ].includes(value)
88
+ let getInternalOrExternalGroup = ({ tsConfigOutput, filename, name }) => {
89
+ var _a
90
+ let typescriptImport = getTypescriptImport.getTypescriptImport()
91
+ if (!typescriptImport) {
92
+ return !name.startsWith('.') && !name.startsWith('/') ? 'external' : null
93
+ }
94
+ let isRelativeImport = typescriptImport.isExternalModuleNameRelative(name)
95
+ if (isRelativeImport) {
96
+ return null
97
+ }
98
+ if (!tsConfigOutput) {
99
+ return 'external'
100
+ }
101
+ let resolution = typescriptImport.resolveModuleName(
102
+ name,
103
+ filename,
104
+ tsConfigOutput.compilerOptions,
105
+ typescriptImport.sys,
106
+ tsConfigOutput.cache,
107
+ )
108
+ if (
109
+ typeof ((_a = resolution.resolvedModule) == null
110
+ ? void 0
111
+ : _a.isExternalLibraryImport) !== 'boolean'
112
+ ) {
113
+ return 'external'
114
+ }
115
+ return resolution.resolvedModule.isExternalLibraryImport
116
+ ? 'external'
117
+ : 'internal'
118
+ }
119
+ exports.computeCommonSelectors = computeCommonSelectors
@@ -0,0 +1,13 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const isNewlinesBetweenOption = require('../../utils/is-newlines-between-option.js')
4
+ let isSideEffectOnlyGroup = group => {
5
+ if (isNewlinesBetweenOption.isNewlinesBetweenOption(group)) {
6
+ return false
7
+ }
8
+ if (typeof group === 'string') {
9
+ return group === 'side-effect' || group === 'side-effect-style'
10
+ }
11
+ return group.every(isSideEffectOnlyGroup)
12
+ }
13
+ exports.isSideEffectOnlyGroup = isSideEffectOnlyGroup
@@ -0,0 +1,22 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let regexByTsconfigPathCache = /* @__PURE__ */ new Map()
4
+ let matchesTsconfigPaths = ({ tsConfigOutput, name }) => {
5
+ if (!tsConfigOutput.compilerOptions.paths) {
6
+ return false
7
+ }
8
+ return Object.keys(tsConfigOutput.compilerOptions.paths).some(key =>
9
+ getRegexByTsconfigPath(key).test(name),
10
+ )
11
+ }
12
+ let getRegexByTsconfigPath = path => {
13
+ let existingRegex = regexByTsconfigPathCache.get(path)
14
+ if (existingRegex) {
15
+ return existingRegex
16
+ }
17
+ let regex = new RegExp(`^${escapeRegExp(path).replaceAll('*', '(.+)')}$`)
18
+ regexByTsconfigPathCache.set(path, regex)
19
+ return regex
20
+ }
21
+ let escapeRegExp = value => value.replaceAll(/[$+.?[\\\]]/gu, String.raw`\$&`)
22
+ exports.matchesTsconfigPaths = matchesTsconfigPaths
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
+ let allSelectors = [
5
+ 'side-effect-style',
6
+ 'tsconfig-path',
7
+ 'side-effect',
8
+ 'external',
9
+ 'internal',
10
+ 'builtin',
11
+ 'sibling',
12
+ 'subpath',
13
+ 'import',
14
+ 'parent',
15
+ 'index',
16
+ 'style',
17
+ 'type',
18
+ ]
19
+ let allDeprecatedSelectors = [
20
+ 'internal-type',
21
+ 'external-type',
22
+ 'sibling-type',
23
+ 'builtin-type',
24
+ 'parent-type',
25
+ 'index-type',
26
+ 'object',
27
+ ]
28
+ let allModifiers = [
29
+ 'default',
30
+ 'named',
31
+ 'require',
32
+ 'side-effect',
33
+ 'ts-equals',
34
+ 'type',
35
+ 'value',
36
+ 'wildcard',
37
+ ]
38
+ let singleCustomGroupJsonSchema = {
39
+ modifiers:
40
+ commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
41
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
42
+ elementValuePattern: commonJsonSchemas.regexJsonSchema,
43
+ elementNamePattern: commonJsonSchemas.regexJsonSchema,
44
+ }
45
+ exports.allDeprecatedSelectors = allDeprecatedSelectors
46
+ exports.allModifiers = allModifiers
47
+ exports.allSelectors = allSelectors
48
+ exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const isSideEffectOnlyGroup = require('./is-side-effect-only-group.js')
4
+ let validateSideEffectsConfiguration = ({ sortSideEffects, groups }) => {
5
+ if (sortSideEffects) {
6
+ return
7
+ }
8
+ let hasInvalidGroup = groups
9
+ .filter(group => Array.isArray(group))
10
+ .some(
11
+ nestedGroup =>
12
+ !isSideEffectOnlyGroup.isSideEffectOnlyGroup(nestedGroup) &&
13
+ nestedGroup.some(
14
+ subGroup =>
15
+ subGroup === 'side-effect' || subGroup === 'side-effect-style',
16
+ ),
17
+ )
18
+ if (hasInvalidGroup) {
19
+ throw new Error(
20
+ "Side effect groups cannot be nested with non side effect groups when 'sortSideEffects' is 'false'.",
21
+ )
22
+ }
23
+ }
24
+ exports.validateSideEffectsConfiguration = validateSideEffectsConfiguration