eslint-plugin-perfectionist 3.7.0 → 3.8.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 (53) hide show
  1. package/dist/index.d.ts +18 -0
  2. package/dist/rules/sort-array-includes.js +9 -3
  3. package/dist/rules/sort-array-includes.mjs +9 -3
  4. package/dist/rules/sort-astro-attributes.js +8 -1
  5. package/dist/rules/sort-astro-attributes.mjs +9 -3
  6. package/dist/rules/sort-classes-utils.js +4 -8
  7. package/dist/rules/sort-classes-utils.mjs +4 -8
  8. package/dist/rules/sort-classes.js +21 -13
  9. package/dist/rules/sort-classes.mjs +19 -16
  10. package/dist/rules/sort-enums.js +15 -3
  11. package/dist/rules/sort-enums.mjs +9 -3
  12. package/dist/rules/sort-exports.js +15 -3
  13. package/dist/rules/sort-exports.mjs +9 -3
  14. package/dist/rules/sort-imports.js +57 -29
  15. package/dist/rules/sort-imports.mjs +54 -32
  16. package/dist/rules/sort-interfaces.js +18 -8
  17. package/dist/rules/sort-interfaces.mjs +13 -10
  18. package/dist/rules/sort-intersection-types.js +16 -4
  19. package/dist/rules/sort-intersection-types.mjs +10 -4
  20. package/dist/rules/sort-jsx-props.js +10 -3
  21. package/dist/rules/sort-jsx-props.mjs +11 -5
  22. package/dist/rules/sort-maps.js +9 -3
  23. package/dist/rules/sort-maps.mjs +9 -3
  24. package/dist/rules/sort-named-exports.js +15 -3
  25. package/dist/rules/sort-named-exports.mjs +9 -3
  26. package/dist/rules/sort-named-imports.js +14 -3
  27. package/dist/rules/sort-named-imports.mjs +8 -3
  28. package/dist/rules/sort-object-types.js +17 -5
  29. package/dist/rules/sort-object-types.mjs +11 -7
  30. package/dist/rules/sort-objects.js +27 -16
  31. package/dist/rules/sort-objects.mjs +25 -15
  32. package/dist/rules/sort-sets.js +1 -0
  33. package/dist/rules/sort-sets.mjs +1 -0
  34. package/dist/rules/sort-svelte-attributes.js +11 -6
  35. package/dist/rules/sort-svelte-attributes.mjs +12 -8
  36. package/dist/rules/sort-union-types.js +16 -4
  37. package/dist/rules/sort-union-types.mjs +10 -4
  38. package/dist/rules/sort-variable-declarations.js +15 -3
  39. package/dist/rules/sort-variable-declarations.mjs +9 -3
  40. package/dist/rules/sort-vue-attributes.js +8 -1
  41. package/dist/rules/sort-vue-attributes.mjs +9 -3
  42. package/dist/utils/compare.js +12 -6
  43. package/dist/utils/compare.mjs +12 -6
  44. package/dist/utils/get-node-range.js +11 -3
  45. package/dist/utils/get-node-range.mjs +13 -3
  46. package/dist/utils/is-partition-comment.js +8 -10
  47. package/dist/utils/is-partition-comment.mjs +8 -10
  48. package/dist/utils/matches.js +15 -0
  49. package/dist/utils/matches.mjs +13 -0
  50. package/dist/utils/use-groups.js +4 -8
  51. package/dist/utils/use-groups.mjs +4 -13
  52. package/{license → license.md} +1 -1
  53. package/package.json +3 -3
@@ -33,6 +33,11 @@ const sortExports = createEslintRule.createEslintRule({
33
33
  type: 'string',
34
34
  enum: ['asc', 'desc'],
35
35
  },
36
+ matcher: {
37
+ description: 'Specifies the string matcher.',
38
+ type: 'string',
39
+ enum: ['minimatch', 'regex'],
40
+ },
36
41
  ignoreCase: {
37
42
  description:
38
43
  'Controls whether sorting should be case-sensitive or not.',
@@ -79,6 +84,7 @@ const sortExports = createEslintRule.createEslintRule({
79
84
  type: 'alphabetical',
80
85
  order: 'asc',
81
86
  ignoreCase: true,
87
+ matcher: 'minimatch',
82
88
  partitionByComment: false,
83
89
  partitionByNewLine: false,
84
90
  groupKind: 'mixed',
@@ -90,6 +96,7 @@ const sortExports = createEslintRule.createEslintRule({
90
96
  type: 'alphabetical',
91
97
  ignoreCase: true,
92
98
  order: 'asc',
99
+ matcher: 'minimatch',
93
100
  partitionByComment: false,
94
101
  partitionByNewLine: false,
95
102
  groupKind: 'mixed',
@@ -110,6 +117,7 @@ const sortExports = createEslintRule.createEslintRule({
110
117
  isPartitionComment.hasPartitionComment(
111
118
  partitionComment,
112
119
  getCommentsBefore.getCommentsBefore(node, sourceCode),
120
+ options.matcher,
113
121
  )) ||
114
122
  (options.partitionByNewLine &&
115
123
  lastNode &&
@@ -166,9 +174,13 @@ const sortExports = createEslintRule.createEslintRule({
166
174
  },
167
175
  node: right.node,
168
176
  fix: fixer =>
169
- makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
170
- partitionComment,
171
- }),
177
+ makeFixes.makeFixes(
178
+ fixer,
179
+ nodes,
180
+ sortedNodes,
181
+ sourceCode,
182
+ options,
183
+ ),
172
184
  })
173
185
  }
174
186
  })
@@ -32,6 +32,11 @@ const sortExports = createEslintRule({
32
32
  type: 'string',
33
33
  enum: ['asc', 'desc'],
34
34
  },
35
+ matcher: {
36
+ description: 'Specifies the string matcher.',
37
+ type: 'string',
38
+ enum: ['minimatch', 'regex'],
39
+ },
35
40
  ignoreCase: {
36
41
  description:
37
42
  'Controls whether sorting should be case-sensitive or not.',
@@ -78,6 +83,7 @@ const sortExports = createEslintRule({
78
83
  type: 'alphabetical',
79
84
  order: 'asc',
80
85
  ignoreCase: true,
86
+ matcher: 'minimatch',
81
87
  partitionByComment: false,
82
88
  partitionByNewLine: false,
83
89
  groupKind: 'mixed',
@@ -89,6 +95,7 @@ const sortExports = createEslintRule({
89
95
  type: 'alphabetical',
90
96
  ignoreCase: true,
91
97
  order: 'asc',
98
+ matcher: 'minimatch',
92
99
  partitionByComment: false,
93
100
  partitionByNewLine: false,
94
101
  groupKind: 'mixed',
@@ -109,6 +116,7 @@ const sortExports = createEslintRule({
109
116
  hasPartitionComment(
110
117
  partitionComment,
111
118
  getCommentsBefore(node, sourceCode),
119
+ options.matcher,
112
120
  )) ||
113
121
  (options.partitionByNewLine &&
114
122
  lastNode &&
@@ -162,9 +170,7 @@ const sortExports = createEslintRule({
162
170
  },
163
171
  node: right.node,
164
172
  fix: fixer =>
165
- makeFixes(fixer, nodes, sortedNodes, sourceCode, {
166
- partitionComment,
167
- }),
173
+ makeFixes(fixer, nodes, sortedNodes, sourceCode, options),
168
174
  })
169
175
  }
170
176
  })
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
  const node_module = require('node:module')
3
- const minimatch = require('minimatch')
4
3
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
5
4
  const getCommentsBefore = require('../utils/get-comments-before.js')
6
5
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -16,6 +15,7 @@ const sortNodes = require('../utils/sort-nodes.js')
16
15
  const complete = require('../utils/complete.js')
17
16
  const pairwise = require('../utils/pairwise.js')
18
17
  const compare = require('../utils/compare.js')
18
+ const matches = require('../utils/matches.js')
19
19
  const sortImports = createEslintRule.createEslintRule({
20
20
  name: 'sort-imports',
21
21
  meta: {
@@ -40,6 +40,11 @@ const sortImports = createEslintRule.createEslintRule({
40
40
  type: 'string',
41
41
  enum: ['asc', 'desc'],
42
42
  },
43
+ matcher: {
44
+ description: 'Specifies the string matcher.',
45
+ type: 'string',
46
+ enum: ['minimatch', 'regex'],
47
+ },
43
48
  ignoreCase: {
44
49
  description:
45
50
  'Controls whether sorting should be case-sensitive or not.',
@@ -158,6 +163,7 @@ const sortImports = createEslintRule.createEslintRule({
158
163
  sortSideEffects: false,
159
164
  newlinesBetween: 'always',
160
165
  maxLineLength: void 0,
166
+ matcher: 'minimatch',
161
167
  groups: [
162
168
  'type',
163
169
  ['builtin', 'external'],
@@ -174,7 +180,8 @@ const sortImports = createEslintRule.createEslintRule({
174
180
  ],
175
181
  create: context => {
176
182
  let settings = getSettings.getSettings(context.settings)
177
- let options = complete.complete(context.options.at(0), settings, {
183
+ let defaultOptions = context.options.at(0)
184
+ let options = complete.complete(defaultOptions, settings, {
178
185
  groups: [
179
186
  'type',
180
187
  ['builtin', 'external'],
@@ -185,8 +192,12 @@ const sortImports = createEslintRule.createEslintRule({
185
192
  'object',
186
193
  'unknown',
187
194
  ],
195
+ matcher: 'minimatch',
188
196
  customGroups: { type: {}, value: {} },
189
- internalPattern: ['~/**'],
197
+ internalPattern:
198
+ (defaultOptions == null ? void 0 : defaultOptions.matcher) === 'regex'
199
+ ? ['^~/.*']
200
+ : ['~/**'],
190
201
  newlinesBetween: 'always',
191
202
  sortSideEffects: false,
192
203
  type: 'alphabetical',
@@ -203,10 +214,8 @@ const sortImports = createEslintRule.createEslintRule({
203
214
  hasUnknownGroup = true
204
215
  }
205
216
  }
206
- } else {
207
- if (group === 'unknown') {
208
- hasUnknownGroup = true
209
- }
217
+ } else if (group === 'unknown') {
218
+ hasUnknownGroup = true
210
219
  }
211
220
  }
212
221
  if (!hasUnknownGroup) {
@@ -260,17 +269,14 @@ const sortImports = createEslintRule.createEslintRule({
260
269
  './',
261
270
  '.',
262
271
  ].includes(value)
263
- let isParent = value => value.indexOf('..') === 0
264
- let isSibling = value => value.indexOf('./') === 0
265
- let { getGroup, defineGroup, setCustomGroups } = useGroups.useGroups(
266
- options.groups,
267
- )
272
+ let isParent = value => value.startsWith('..')
273
+ let isSibling = value => value.startsWith('./')
274
+ let { getGroup, defineGroup, setCustomGroups } =
275
+ useGroups.useGroups(options)
268
276
  let isInternal = value =>
269
277
  options.internalPattern.length &&
270
278
  options.internalPattern.some(pattern =>
271
- minimatch.minimatch(value, pattern, {
272
- nocomment: true,
273
- }),
279
+ matches.matches(value, pattern, options.matcher),
274
280
  )
275
281
  let isCoreModule = value => {
276
282
  let bunModules = [
@@ -423,15 +429,16 @@ const sortImports = createEslintRule.createEslintRule({
423
429
  let groupNum = getGroupNumber.getGroupNumber(options.groups, node)
424
430
  if (!(groupNum in grouped)) {
425
431
  grouped[groupNum] = [node]
432
+ } else if (
433
+ !options.sortSideEffects &&
434
+ isSideEffectImport(node.node)
435
+ ) {
436
+ grouped[groupNum] = [...grouped[groupNum], node]
426
437
  } else {
427
- if (!options.sortSideEffects && isSideEffectImport(node.node)) {
428
- grouped[groupNum] = [...grouped[groupNum], node]
429
- } else {
430
- grouped[groupNum] = sortNodes.sortNodes(
431
- [...grouped[groupNum], node],
432
- options,
433
- )
434
- }
438
+ grouped[groupNum] = sortNodes.sortNodes(
439
+ [...grouped[groupNum], node],
440
+ options,
441
+ )
435
442
  }
436
443
  }
437
444
  let formatted = Object.keys(grouped)
@@ -444,9 +451,13 @@ const sortImports = createEslintRule.createEslintRule({
444
451
  let node = formatted.at(i)
445
452
  fixes.push(
446
453
  fixer.replaceTextRange(
447
- getNodeRange.getNodeRange(nodesToFix.at(i).node, sourceCode),
454
+ getNodeRange.getNodeRange(
455
+ nodesToFix.at(i).node,
456
+ sourceCode,
457
+ options,
458
+ ),
448
459
  sourceCode.text.slice(
449
- ...getNodeRange.getNodeRange(node.node, sourceCode),
460
+ ...getNodeRange.getNodeRange(node.node, sourceCode, options),
450
461
  ),
451
462
  ),
452
463
  )
@@ -469,10 +480,18 @@ const sortImports = createEslintRule.createEslintRule({
469
480
  fixes.push(
470
481
  fixer.removeRange([
471
482
  getNodeRange
472
- .getNodeRange(nodesToFix.at(i).node, sourceCode)
483
+ .getNodeRange(
484
+ nodesToFix.at(i).node,
485
+ sourceCode,
486
+ options,
487
+ )
473
488
  .at(1),
474
489
  getNodeRange
475
- .getNodeRange(nodesToFix.at(i + 1).node, sourceCode)
490
+ .getNodeRange(
491
+ nodesToFix.at(i + 1).node,
492
+ sourceCode,
493
+ options,
494
+ )
476
495
  .at(0) - 1,
477
496
  ]),
478
497
  )
@@ -487,10 +506,18 @@ const sortImports = createEslintRule.createEslintRule({
487
506
  fixer.replaceTextRange(
488
507
  [
489
508
  getNodeRange
490
- .getNodeRange(nodesToFix.at(i).node, sourceCode)
509
+ .getNodeRange(
510
+ nodesToFix.at(i).node,
511
+ sourceCode,
512
+ options,
513
+ )
491
514
  .at(1),
492
515
  getNodeRange
493
- .getNodeRange(nodesToFix.at(i + 1).node, sourceCode)
516
+ .getNodeRange(
517
+ nodesToFix.at(i + 1).node,
518
+ sourceCode,
519
+ options,
520
+ )
494
521
  .at(0) - 1,
495
522
  ],
496
523
  '\n',
@@ -508,6 +535,7 @@ const sortImports = createEslintRule.createEslintRule({
508
535
  getNodeRange.getNodeRange(
509
536
  nodesToFix.at(i).node,
510
537
  sourceCode,
538
+ options,
511
539
  ),
512
540
  '\n',
513
541
  ),
@@ -1,5 +1,4 @@
1
1
  import { builtinModules } from 'node:module'
2
- import { minimatch } from 'minimatch'
3
2
  import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
4
3
  import { getCommentsBefore } from '../utils/get-comments-before.mjs'
5
4
  import { createEslintRule } from '../utils/create-eslint-rule.mjs'
@@ -15,6 +14,7 @@ import { sortNodes } from '../utils/sort-nodes.mjs'
15
14
  import { complete } from '../utils/complete.mjs'
16
15
  import { pairwise } from '../utils/pairwise.mjs'
17
16
  import { compare } from '../utils/compare.mjs'
17
+ import { matches } from '../utils/matches.mjs'
18
18
  const sortImports = createEslintRule({
19
19
  name: 'sort-imports',
20
20
  meta: {
@@ -39,6 +39,11 @@ const sortImports = createEslintRule({
39
39
  type: 'string',
40
40
  enum: ['asc', 'desc'],
41
41
  },
42
+ matcher: {
43
+ description: 'Specifies the string matcher.',
44
+ type: 'string',
45
+ enum: ['minimatch', 'regex'],
46
+ },
42
47
  ignoreCase: {
43
48
  description:
44
49
  'Controls whether sorting should be case-sensitive or not.',
@@ -157,6 +162,7 @@ const sortImports = createEslintRule({
157
162
  sortSideEffects: false,
158
163
  newlinesBetween: 'always',
159
164
  maxLineLength: void 0,
165
+ matcher: 'minimatch',
160
166
  groups: [
161
167
  'type',
162
168
  ['builtin', 'external'],
@@ -173,7 +179,8 @@ const sortImports = createEslintRule({
173
179
  ],
174
180
  create: context => {
175
181
  let settings = getSettings(context.settings)
176
- let options = complete(context.options.at(0), settings, {
182
+ let defaultOptions = context.options.at(0)
183
+ let options = complete(defaultOptions, settings, {
177
184
  groups: [
178
185
  'type',
179
186
  ['builtin', 'external'],
@@ -184,8 +191,12 @@ const sortImports = createEslintRule({
184
191
  'object',
185
192
  'unknown',
186
193
  ],
194
+ matcher: 'minimatch',
187
195
  customGroups: { type: {}, value: {} },
188
- internalPattern: ['~/**'],
196
+ internalPattern:
197
+ (defaultOptions == null ? void 0 : defaultOptions.matcher) === 'regex'
198
+ ? ['^~/.*']
199
+ : ['~/**'],
189
200
  newlinesBetween: 'always',
190
201
  sortSideEffects: false,
191
202
  type: 'alphabetical',
@@ -202,10 +213,8 @@ const sortImports = createEslintRule({
202
213
  hasUnknownGroup = true
203
214
  }
204
215
  }
205
- } else {
206
- if (group === 'unknown') {
207
- hasUnknownGroup = true
208
- }
216
+ } else if (group === 'unknown') {
217
+ hasUnknownGroup = true
209
218
  }
210
219
  }
211
220
  if (!hasUnknownGroup) {
@@ -259,15 +268,13 @@ const sortImports = createEslintRule({
259
268
  './',
260
269
  '.',
261
270
  ].includes(value)
262
- let isParent = value => value.indexOf('..') === 0
263
- let isSibling = value => value.indexOf('./') === 0
264
- let { getGroup, defineGroup, setCustomGroups } = useGroups(options.groups)
271
+ let isParent = value => value.startsWith('..')
272
+ let isSibling = value => value.startsWith('./')
273
+ let { getGroup, defineGroup, setCustomGroups } = useGroups(options)
265
274
  let isInternal = value =>
266
275
  options.internalPattern.length &&
267
276
  options.internalPattern.some(pattern =>
268
- minimatch(value, pattern, {
269
- nocomment: true,
270
- }),
277
+ matches(value, pattern, options.matcher),
271
278
  )
272
279
  let isCoreModule = value => {
273
280
  let bunModules = [
@@ -417,15 +424,16 @@ const sortImports = createEslintRule({
417
424
  let groupNum = getGroupNumber(options.groups, node)
418
425
  if (!(groupNum in grouped)) {
419
426
  grouped[groupNum] = [node]
427
+ } else if (
428
+ !options.sortSideEffects &&
429
+ isSideEffectImport(node.node)
430
+ ) {
431
+ grouped[groupNum] = [...grouped[groupNum], node]
420
432
  } else {
421
- if (!options.sortSideEffects && isSideEffectImport(node.node)) {
422
- grouped[groupNum] = [...grouped[groupNum], node]
423
- } else {
424
- grouped[groupNum] = sortNodes(
425
- [...grouped[groupNum], node],
426
- options,
427
- )
428
- }
433
+ grouped[groupNum] = sortNodes(
434
+ [...grouped[groupNum], node],
435
+ options,
436
+ )
429
437
  }
430
438
  }
431
439
  let formatted = Object.keys(grouped)
@@ -438,8 +446,10 @@ const sortImports = createEslintRule({
438
446
  let node = formatted.at(i)
439
447
  fixes.push(
440
448
  fixer.replaceTextRange(
441
- getNodeRange(nodesToFix.at(i).node, sourceCode),
442
- sourceCode.text.slice(...getNodeRange(node.node, sourceCode)),
449
+ getNodeRange(nodesToFix.at(i).node, sourceCode, options),
450
+ sourceCode.text.slice(
451
+ ...getNodeRange(node.node, sourceCode, options),
452
+ ),
443
453
  ),
444
454
  )
445
455
  if (options.newlinesBetween !== 'ignore') {
@@ -460,10 +470,16 @@ const sortImports = createEslintRule({
460
470
  ) {
461
471
  fixes.push(
462
472
  fixer.removeRange([
463
- getNodeRange(nodesToFix.at(i).node, sourceCode).at(1),
464
- getNodeRange(nodesToFix.at(i + 1).node, sourceCode).at(
465
- 0,
466
- ) - 1,
473
+ getNodeRange(
474
+ nodesToFix.at(i).node,
475
+ sourceCode,
476
+ options,
477
+ ).at(1),
478
+ getNodeRange(
479
+ nodesToFix.at(i + 1).node,
480
+ sourceCode,
481
+ options,
482
+ ).at(0) - 1,
467
483
  ]),
468
484
  )
469
485
  }
@@ -476,10 +492,16 @@ const sortImports = createEslintRule({
476
492
  fixes.push(
477
493
  fixer.replaceTextRange(
478
494
  [
479
- getNodeRange(nodesToFix.at(i).node, sourceCode).at(1),
480
- getNodeRange(nodesToFix.at(i + 1).node, sourceCode).at(
481
- 0,
482
- ) - 1,
495
+ getNodeRange(
496
+ nodesToFix.at(i).node,
497
+ sourceCode,
498
+ options,
499
+ ).at(1),
500
+ getNodeRange(
501
+ nodesToFix.at(i + 1).node,
502
+ sourceCode,
503
+ options,
504
+ ).at(0) - 1,
483
505
  ],
484
506
  '\n',
485
507
  ),
@@ -493,7 +515,7 @@ const sortImports = createEslintRule({
493
515
  ) {
494
516
  fixes.push(
495
517
  fixer.insertTextAfterRange(
496
- getNodeRange(nodesToFix.at(i).node, sourceCode),
518
+ getNodeRange(nodesToFix.at(i).node, sourceCode, options),
497
519
  '\n',
498
520
  ),
499
521
  )
@@ -1,5 +1,4 @@
1
1
  'use strict'
2
- const minimatch = require('minimatch')
3
2
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
4
3
  const isPartitionComment = require('../utils/is-partition-comment.js')
5
4
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
@@ -16,6 +15,7 @@ const useGroups = require('../utils/use-groups.js')
16
15
  const makeFixes = require('../utils/make-fixes.js')
17
16
  const complete = require('../utils/complete.js')
18
17
  const pairwise = require('../utils/pairwise.js')
18
+ const matches = require('../utils/matches.js')
19
19
  const sortInterfaces = createEslintRule.createEslintRule({
20
20
  name: 'sort-interfaces',
21
21
  meta: {
@@ -39,6 +39,11 @@ const sortInterfaces = createEslintRule.createEslintRule({
39
39
  type: 'string',
40
40
  enum: ['asc', 'desc'],
41
41
  },
42
+ matcher: {
43
+ description: 'Specifies the string matcher.',
44
+ type: 'string',
45
+ enum: ['minimatch', 'regex'],
46
+ },
42
47
  ignoreCase: {
43
48
  description:
44
49
  'Controls whether sorting should be case-sensitive or not.',
@@ -130,6 +135,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
130
135
  type: 'alphabetical',
131
136
  order: 'asc',
132
137
  ignoreCase: true,
138
+ matcher: 'minimatch',
133
139
  ignorePattern: [],
134
140
  partitionByComment: false,
135
141
  partitionByNewLine: false,
@@ -147,6 +153,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
147
153
  partitionByNewLine: false,
148
154
  type: 'alphabetical',
149
155
  groupKind: 'mixed',
156
+ matcher: 'minimatch',
150
157
  ignorePattern: [],
151
158
  ignoreCase: true,
152
159
  customGroups: {},
@@ -162,9 +169,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
162
169
  let partitionComment = options.partitionByComment
163
170
  if (
164
171
  !options.ignorePattern.some(pattern =>
165
- minimatch.minimatch(node.id.name, pattern, {
166
- nocomment: true,
167
- }),
172
+ matches.matches(node.id.name, pattern, options.matcher),
168
173
  )
169
174
  ) {
170
175
  let formattedMembers = node.body.body.reduce(
@@ -178,7 +183,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
178
183
  (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
179
184
  let name
180
185
  let { getGroup, defineGroup, setCustomGroups } =
181
- useGroups.useGroups(options.groups)
186
+ useGroups.useGroups(options)
182
187
  if (element.type === 'TSPropertySignature') {
183
188
  if (element.key.type === 'Identifier') {
184
189
  ;({ name } = element.key)
@@ -220,6 +225,7 @@ const sortInterfaces = createEslintRule.createEslintRule({
220
225
  isPartitionComment.hasPartitionComment(
221
226
  partitionComment,
222
227
  getCommentsBefore.getCommentsBefore(element, sourceCode),
228
+ options.matcher,
223
229
  )) ||
224
230
  (options.partitionByNewLine &&
225
231
  lastElement &&
@@ -296,9 +302,13 @@ const sortInterfaces = createEslintRule.createEslintRule({
296
302
  },
297
303
  node: right.node,
298
304
  fix: fixer =>
299
- makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
300
- partitionComment,
301
- }),
305
+ makeFixes.makeFixes(
306
+ fixer,
307
+ nodes,
308
+ sortedNodes,
309
+ sourceCode,
310
+ options,
311
+ ),
302
312
  })
303
313
  }
304
314
  })
@@ -1,4 +1,3 @@
1
- import { minimatch } from 'minimatch'
2
1
  import { validateGroupsConfiguration } from '../utils/validate-groups-configuration.mjs'
3
2
  import { hasPartitionComment } from '../utils/is-partition-comment.mjs'
4
3
  import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.mjs'
@@ -15,6 +14,7 @@ import { useGroups } from '../utils/use-groups.mjs'
15
14
  import { makeFixes } from '../utils/make-fixes.mjs'
16
15
  import { complete } from '../utils/complete.mjs'
17
16
  import { pairwise } from '../utils/pairwise.mjs'
17
+ import { matches } from '../utils/matches.mjs'
18
18
  const sortInterfaces = createEslintRule({
19
19
  name: 'sort-interfaces',
20
20
  meta: {
@@ -38,6 +38,11 @@ const sortInterfaces = createEslintRule({
38
38
  type: 'string',
39
39
  enum: ['asc', 'desc'],
40
40
  },
41
+ matcher: {
42
+ description: 'Specifies the string matcher.',
43
+ type: 'string',
44
+ enum: ['minimatch', 'regex'],
45
+ },
41
46
  ignoreCase: {
42
47
  description:
43
48
  'Controls whether sorting should be case-sensitive or not.',
@@ -129,6 +134,7 @@ const sortInterfaces = createEslintRule({
129
134
  type: 'alphabetical',
130
135
  order: 'asc',
131
136
  ignoreCase: true,
137
+ matcher: 'minimatch',
132
138
  ignorePattern: [],
133
139
  partitionByComment: false,
134
140
  partitionByNewLine: false,
@@ -146,6 +152,7 @@ const sortInterfaces = createEslintRule({
146
152
  partitionByNewLine: false,
147
153
  type: 'alphabetical',
148
154
  groupKind: 'mixed',
155
+ matcher: 'minimatch',
149
156
  ignorePattern: [],
150
157
  ignoreCase: true,
151
158
  customGroups: {},
@@ -161,9 +168,7 @@ const sortInterfaces = createEslintRule({
161
168
  let partitionComment = options.partitionByComment
162
169
  if (
163
170
  !options.ignorePattern.some(pattern =>
164
- minimatch(node.id.name, pattern, {
165
- nocomment: true,
166
- }),
171
+ matches(node.id.name, pattern, options.matcher),
167
172
  )
168
173
  ) {
169
174
  let formattedMembers = node.body.body.reduce(
@@ -176,9 +181,8 @@ const sortInterfaces = createEslintRule({
176
181
  let lastElement =
177
182
  (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
178
183
  let name
179
- let { getGroup, defineGroup, setCustomGroups } = useGroups(
180
- options.groups,
181
- )
184
+ let { getGroup, defineGroup, setCustomGroups } =
185
+ useGroups(options)
182
186
  if (element.type === 'TSPropertySignature') {
183
187
  if (element.key.type === 'Identifier') {
184
188
  ;({ name } = element.key)
@@ -220,6 +224,7 @@ const sortInterfaces = createEslintRule({
220
224
  hasPartitionComment(
221
225
  partitionComment,
222
226
  getCommentsBefore(element, sourceCode),
227
+ options.matcher,
223
228
  )) ||
224
229
  (options.partitionByNewLine &&
225
230
  lastElement &&
@@ -274,9 +279,7 @@ const sortInterfaces = createEslintRule({
274
279
  },
275
280
  node: right.node,
276
281
  fix: fixer =>
277
- makeFixes(fixer, nodes, sortedNodes, sourceCode, {
278
- partitionComment,
279
- }),
282
+ makeFixes(fixer, nodes, sortedNodes, sourceCode, options),
280
283
  })
281
284
  }
282
285
  })
@@ -37,6 +37,11 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
37
37
  type: 'string',
38
38
  enum: ['asc', 'desc'],
39
39
  },
40
+ matcher: {
41
+ description: 'Specifies the string matcher.',
42
+ type: 'string',
43
+ enum: ['minimatch', 'regex'],
44
+ },
40
45
  ignoreCase: {
41
46
  description:
42
47
  'Controls whether sorting should be case-sensitive or not.',
@@ -98,6 +103,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
98
103
  type: 'alphabetical',
99
104
  order: 'asc',
100
105
  ignoreCase: true,
106
+ matcher: 'minimatch',
101
107
  partitionByNewLine: false,
102
108
  partitionByComment: false,
103
109
  groups: [],
@@ -110,6 +116,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
110
116
  type: 'alphabetical',
111
117
  ignoreCase: true,
112
118
  order: 'asc',
119
+ matcher: 'minimatch',
113
120
  partitionByComment: false,
114
121
  partitionByNewLine: false,
115
122
  groups: [],
@@ -138,7 +145,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
138
145
  let formattedMembers = node.types.reduce(
139
146
  (accumulator, type) => {
140
147
  var _a, _b
141
- let { getGroup, defineGroup } = useGroups.useGroups(options.groups)
148
+ let { getGroup, defineGroup } = useGroups.useGroups(options)
142
149
  switch (type.type) {
143
150
  case 'TSConditionalType':
144
151
  defineGroup('conditional')
@@ -210,6 +217,7 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
210
217
  isPartitionComment.hasPartitionComment(
211
218
  partitionComment,
212
219
  getCommentsBefore.getCommentsBefore(type, sourceCode),
220
+ options.matcher,
213
221
  )) ||
214
222
  (options.partitionByNewLine &&
215
223
  lastSortingNode &&
@@ -247,9 +255,13 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
247
255
  },
248
256
  node: right.node,
249
257
  fix: fixer =>
250
- makeFixes.makeFixes(fixer, nodes, sortedNodes, sourceCode, {
251
- partitionComment,
252
- }),
258
+ makeFixes.makeFixes(
259
+ fixer,
260
+ nodes,
261
+ sortedNodes,
262
+ sourceCode,
263
+ options,
264
+ ),
253
265
  })
254
266
  }
255
267
  })