eslint-plugin-perfectionist 4.4.0 → 4.5.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 (44) hide show
  1. package/dist/alphabet.d.ts +1 -2
  2. package/dist/rules/{sort-array-includes-utils.js → sort-array-includes/does-custom-group-match.js} +4 -4
  3. package/dist/rules/{sort-array-includes.types.js → sort-array-includes/types.js} +1 -1
  4. package/dist/rules/sort-array-includes.js +10 -11
  5. package/dist/rules/{sort-classes-utils.js → sort-classes/does-custom-group-match.js} +4 -36
  6. package/dist/rules/sort-classes/get-overload-signature-groups.js +34 -0
  7. package/dist/rules/{sort-classes.types.js → sort-classes/types.js} +1 -1
  8. package/dist/rules/sort-classes.js +14 -15
  9. package/dist/rules/sort-decorators.js +6 -6
  10. package/dist/rules/sort-enums.js +6 -6
  11. package/dist/rules/sort-exports.js +5 -5
  12. package/dist/{utils → rules/sort-imports}/get-typescript-import.js +4 -1
  13. package/dist/rules/sort-imports.js +23 -13
  14. package/dist/rules/sort-intersection-types.js +5 -5
  15. package/dist/rules/sort-maps.js +5 -5
  16. package/dist/rules/{sort-modules-utils.js → sort-modules/does-custom-group-match.js} +4 -4
  17. package/dist/rules/{sort-modules.types.js → sort-modules/types.js} +1 -1
  18. package/dist/rules/sort-modules.js +11 -12
  19. package/dist/rules/sort-named-exports.js +5 -5
  20. package/dist/rules/sort-named-imports.js +5 -5
  21. package/dist/rules/{sort-object-types-utils.js → sort-object-types/does-custom-group-match.js} +4 -4
  22. package/dist/rules/{sort-object-types.types.js → sort-object-types/types.js} +1 -1
  23. package/dist/rules/sort-object-types.js +12 -13
  24. package/dist/rules/sort-objects.js +6 -6
  25. package/dist/rules/sort-union-types.js +5 -5
  26. package/dist/rules/sort-variable-declarations.js +5 -5
  27. package/dist/utils/alphabet.js +1 -2
  28. package/dist/utils/common-json-schemas.js +35 -12
  29. package/dist/utils/compare.js +8 -2
  30. package/dist/utils/get-eslint-disabled-rules.js +4 -2
  31. package/dist/utils/get-newlines-between-option.js +54 -0
  32. package/dist/utils/get-newlines-errors.js +21 -14
  33. package/dist/utils/get-node-range.js +5 -4
  34. package/dist/utils/get-options-with-clean-groups.js +1 -1
  35. package/dist/utils/get-settings.js +3 -3
  36. package/dist/utils/has-partition-comment.js +11 -0
  37. package/dist/utils/is-partition-comment.js +39 -13
  38. package/dist/utils/make-newlines-fixes.js +19 -29
  39. package/dist/utils/sort-nodes-by-groups.js +3 -7
  40. package/package.json +3 -3
  41. /package/dist/{utils → rules/sort-decorators}/get-decorator-name.js +0 -0
  42. /package/dist/{utils → rules/sort-imports}/read-closest-ts-config-by-path.js +0 -0
  43. /package/dist/{utils → rules/sort-object-types}/is-member-optional.js +0 -0
  44. /package/dist/{utils → rules/sort-objects}/get-first-node-parent-with-type.js +0 -0
@@ -39,8 +39,7 @@ export declare class Alphabet {
39
39
  * @returns {Alphabet} - The same alphabet instance with the cases prioritized
40
40
  * @example
41
41
  * Alphabet.generateFrom('aAbBcdCD')
42
- * .prioritizeCase('uppercase')
43
- * // Returns 'AaBbCDcd'
42
+ * .prioritizeCase('uppercase') // Returns 'AaBbCDcd'.
44
43
  */
45
44
  prioritizeCase(casePriority: 'lowercase' | 'uppercase'): this
46
45
  /**
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../utils/matches.js')
4
- let customGroupMatches = props => {
3
+ const matches = require('../../utils/matches.js')
4
+ let doesCustomGroupMatch = props => {
5
5
  if ('anyOf' in props.customGroup) {
6
6
  return props.customGroup.anyOf.some(subgroup =>
7
- customGroupMatches({ ...props, customGroup: subgroup }),
7
+ doesCustomGroupMatch({ ...props, customGroup: subgroup }),
8
8
  )
9
9
  }
10
10
  if (
@@ -27,4 +27,4 @@ let customGroupMatches = props => {
27
27
  }
28
28
  return true
29
29
  }
30
- exports.customGroupMatches = customGroupMatches
30
+ exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
4
  let allSelectors = ['literal', 'spread']
5
5
  let singleCustomGroupJsonSchema = {
6
6
  selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
@@ -5,17 +5,17 @@ Object.defineProperties(exports, {
5
5
  })
6
6
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
7
7
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
8
+ const types = require('./sort-array-includes/types.js')
8
9
  const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
10
+ const doesCustomGroupMatch = require('./sort-array-includes/does-custom-group-match.js')
9
11
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
10
12
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
13
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
12
- const sortArrayIncludes_types = require('./sort-array-includes.types.js')
13
14
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
14
- const isPartitionComment = require('../utils/is-partition-comment.js')
15
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
15
16
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
16
17
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
17
18
  const getCommentsBefore = require('../utils/get-comments-before.js')
18
- const sortArrayIncludesUtils = require('./sort-array-includes-utils.js')
19
19
  const createEslintRule = require('../utils/create-eslint-rule.js')
20
20
  const getLinesBetween = require('../utils/get-lines-between.js')
21
21
  const getGroupNumber = require('../utils/get-group-number.js')
@@ -57,8 +57,7 @@ let jsonSchema = {
57
57
  type: 'string',
58
58
  },
59
59
  customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
60
- singleCustomGroupJsonSchema:
61
- sortArrayIncludes_types.singleCustomGroupJsonSchema,
60
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
62
61
  }),
63
62
  useConfigurationIf: commonJsonSchemas.buildUseConfigurationIfJsonSchema(),
64
63
  type: commonJsonSchemas.buildTypeJsonSchema({ withUnsorted: true }),
@@ -147,7 +146,7 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
147
146
  }
148
147
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
149
148
  customGroups: options.customGroups,
150
- selectors: sortArrayIncludes_types.allSelectors,
149
+ selectors: types.allSelectors,
151
150
  groups: options.groups,
152
151
  modifiers: [],
153
152
  })
@@ -182,7 +181,7 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
182
181
  let name = getNodeName({ sourceCode, element })
183
182
  for (let customGroup of options.customGroups) {
184
183
  if (
185
- sortArrayIncludesUtils.customGroupMatches({
184
+ doesCustomGroupMatch.doesCustomGroupMatch({
186
185
  selectors: [selector],
187
186
  elementName: name,
188
187
  customGroup,
@@ -208,13 +207,13 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
208
207
  let lastSortingNode =
209
208
  (_a = accumulator.at(-1)) == null ? void 0 : _a.at(-1)
210
209
  if (
211
- isPartitionComment.hasPartitionComment(
212
- options.partitionByComment,
213
- getCommentsBefore.getCommentsBefore({
210
+ hasPartitionComment.hasPartitionComment({
211
+ comments: getCommentsBefore.getCommentsBefore({
214
212
  node: element,
215
213
  sourceCode,
216
214
  }),
217
- ) ||
215
+ partitionByComment: options.partitionByComment,
216
+ }) ||
218
217
  (options.partitionByNewLine &&
219
218
  lastSortingNode &&
220
219
  getLinesBetween.getLinesBetween(
@@ -1,41 +1,10 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const isSortable = require('../utils/is-sortable.js')
4
- const matches = require('../utils/matches.js')
5
- let getOverloadSignatureGroups = members => {
6
- let methods = members
7
- .filter(
8
- member =>
9
- member.type === 'MethodDefinition' ||
10
- member.type === 'TSAbstractMethodDefinition',
11
- )
12
- .filter(member => member.kind === 'method')
13
- let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
14
- let overloadSignaturesByName = /* @__PURE__ */ new Map()
15
- for (let method of methods) {
16
- if (method.key.type !== 'Identifier') {
17
- continue
18
- }
19
- let { name } = method.key
20
- let mapToUse = method.static
21
- ? staticOverloadSignaturesByName
22
- : overloadSignaturesByName
23
- let signatureOverloadsGroup = mapToUse.get(name)
24
- if (!signatureOverloadsGroup) {
25
- signatureOverloadsGroup = []
26
- mapToUse.set(name, signatureOverloadsGroup)
27
- }
28
- signatureOverloadsGroup.push(method)
29
- }
30
- return [
31
- ...overloadSignaturesByName.values(),
32
- ...staticOverloadSignaturesByName.values(),
33
- ].filter(isSortable.isSortable)
34
- }
35
- let customGroupMatches = props => {
3
+ const matches = require('../../utils/matches.js')
4
+ let doesCustomGroupMatch = props => {
36
5
  if ('anyOf' in props.customGroup) {
37
6
  return props.customGroup.anyOf.some(subgroup =>
38
- customGroupMatches({ ...props, customGroup: subgroup }),
7
+ doesCustomGroupMatch({ ...props, customGroup: subgroup }),
39
8
  )
40
9
  }
41
10
  if (
@@ -89,5 +58,4 @@ let customGroupMatches = props => {
89
58
  }
90
59
  return true
91
60
  }
92
- exports.customGroupMatches = customGroupMatches
93
- exports.getOverloadSignatureGroups = getOverloadSignatureGroups
61
+ exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const isSortable = require('../../utils/is-sortable.js')
4
+ let getOverloadSignatureGroups = members => {
5
+ let methods = members
6
+ .filter(
7
+ member =>
8
+ member.type === 'MethodDefinition' ||
9
+ member.type === 'TSAbstractMethodDefinition',
10
+ )
11
+ .filter(member => member.kind === 'method')
12
+ let staticOverloadSignaturesByName = /* @__PURE__ */ new Map()
13
+ let overloadSignaturesByName = /* @__PURE__ */ new Map()
14
+ for (let method of methods) {
15
+ if (method.key.type !== 'Identifier') {
16
+ continue
17
+ }
18
+ let { name } = method.key
19
+ let mapToUse = method.static
20
+ ? staticOverloadSignaturesByName
21
+ : overloadSignaturesByName
22
+ let signatureOverloadsGroup = mapToUse.get(name)
23
+ if (!signatureOverloadsGroup) {
24
+ signatureOverloadsGroup = []
25
+ mapToUse.set(name, signatureOverloadsGroup)
26
+ }
27
+ signatureOverloadsGroup.push(method)
28
+ }
29
+ return [
30
+ ...overloadSignaturesByName.values(),
31
+ ...staticOverloadSignaturesByName.values(),
32
+ ].filter(isSortable.isSortable)
33
+ }
34
+ exports.getOverloadSignatureGroups = getOverloadSignatureGroups
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
4
  let allSelectors = [
5
5
  'accessor-property',
6
6
  'index-signature',
@@ -3,14 +3,15 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
4
4
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
5
5
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
6
- const sortClasses_types = require('./sort-classes.types.js')
6
+ const types = require('./sort-classes/types.js')
7
7
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
8
- const sortClassesUtils = require('./sort-classes-utils.js')
9
8
  const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
9
+ const getOverloadSignatureGroups = require('./sort-classes/get-overload-signature-groups.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
+ const doesCustomGroupMatch = require('./sort-classes/does-custom-group-match.js')
11
12
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
12
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
13
- const isPartitionComment = require('../utils/is-partition-comment.js')
14
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
14
15
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
15
16
  const getCommentsBefore = require('../utils/get-comments-before.js')
16
17
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
@@ -83,8 +84,8 @@ const sortClasses = createEslintRule.createEslintRule({
83
84
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
84
85
  {
85
86
  customGroups: options.customGroups,
86
- modifiers: sortClasses_types.allModifiers,
87
- selectors: sortClasses_types.allSelectors,
87
+ modifiers: types.allModifiers,
88
+ selectors: types.allSelectors,
88
89
  groups: options.groups,
89
90
  },
90
91
  )
@@ -228,9 +229,8 @@ const sortClasses = createEslintRule.createEslintRule({
228
229
  traverseNode(expression)
229
230
  return dependencies
230
231
  }
231
- let overloadSignatureGroups = sortClassesUtils.getOverloadSignatureGroups(
232
- node.body,
233
- )
232
+ let overloadSignatureGroups =
233
+ getOverloadSignatureGroups.getOverloadSignatureGroups(node.body)
234
234
  let formattedNodes = node.body.reduce(
235
235
  (accumulator, member) => {
236
236
  var _a2, _b, _c, _d, _e
@@ -405,7 +405,7 @@ const sortClasses = createEslintRule.createEslintRule({
405
405
  }
406
406
  for (let customGroup of options.customGroups) {
407
407
  if (
408
- sortClassesUtils.customGroupMatches({
408
+ doesCustomGroupMatch.doesCustomGroupMatch({
409
409
  elementValue: memberValue,
410
410
  elementName: name,
411
411
  customGroup,
@@ -460,13 +460,13 @@ const sortClasses = createEslintRule.createEslintRule({
460
460
  lastMember,
461
461
  sortingNode,
462
462
  )) ||
463
- isPartitionComment.hasPartitionComment(
464
- options.partitionByComment,
465
- getCommentsBefore.getCommentsBefore({
463
+ hasPartitionComment.hasPartitionComment({
464
+ comments: getCommentsBefore.getCommentsBefore({
466
465
  node: member,
467
466
  sourceCode,
468
467
  }),
469
- )
468
+ partitionByComment: options.partitionByComment,
469
+ })
470
470
  ) {
471
471
  accumulator.push([])
472
472
  }
@@ -589,8 +589,7 @@ const sortClasses = createEslintRule.createEslintRule({
589
589
  'Allows to use comments to separate the class members into logical groups.',
590
590
  },
591
591
  customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
592
- singleCustomGroupJsonSchema:
593
- sortClasses_types.singleCustomGroupJsonSchema,
592
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
594
593
  }),
595
594
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
596
595
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
@@ -4,13 +4,13 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
4
4
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
5
5
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
6
6
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
7
- const isPartitionComment = require('../utils/is-partition-comment.js')
7
+ const getDecoratorName = require('./sort-decorators/get-decorator-name.js')
8
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
8
9
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
9
10
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
10
11
  const getCommentsBefore = require('../utils/get-comments-before.js')
11
12
  const getNodeDecorators = require('../utils/get-node-decorators.js')
12
13
  const createEslintRule = require('../utils/create-eslint-rule.js')
13
- const getDecoratorName = require('../utils/get-decorator-name.js')
14
14
  const getGroupNumber = require('../utils/get-group-number.js')
15
15
  const getSourceCode = require('../utils/get-source-code.js')
16
16
  const toSingleLine = require('../utils/to-single-line.js')
@@ -178,13 +178,13 @@ let sortDecorators$1 = (context, options, decorators) => {
178
178
  let formattedMembers = decorators.reduce(
179
179
  (accumulator, decorator) => {
180
180
  if (
181
- isPartitionComment.hasPartitionComment(
182
- options.partitionByComment,
183
- getCommentsBefore.getCommentsBefore({
181
+ hasPartitionComment.hasPartitionComment({
182
+ comments: getCommentsBefore.getCommentsBefore({
184
183
  node: decorator,
185
184
  sourceCode,
186
185
  }),
187
- )
186
+ partitionByComment: options.partitionByComment,
187
+ })
188
188
  ) {
189
189
  accumulator.push([])
190
190
  }
@@ -4,7 +4,7 @@ const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js'
4
4
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
5
5
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
6
6
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
7
- const isPartitionComment = require('../utils/is-partition-comment.js')
7
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
8
8
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
9
9
  const getCommentsBefore = require('../utils/get-comments-before.js')
10
10
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -109,13 +109,13 @@ const sortEnums = createEslintRule.createEslintRule({
109
109
  dependencies,
110
110
  }
111
111
  if (
112
- isPartitionComment.hasPartitionComment(
113
- options.partitionByComment,
114
- getCommentsBefore.getCommentsBefore({
112
+ hasPartitionComment.hasPartitionComment({
113
+ comments: getCommentsBefore.getCommentsBefore({
115
114
  node: member,
116
115
  sourceCode,
117
116
  }),
118
- ) ||
117
+ partitionByComment: options.partitionByComment,
118
+ }) ||
119
119
  (options.partitionByNewLine &&
120
120
  lastSortingNode &&
121
121
  getLinesBetween.getLinesBetween(
@@ -138,7 +138,7 @@ const sortEnums = createEslintRule.createEslintRule({
138
138
  !Number.isNaN(sortingNode.numericValue),
139
139
  )
140
140
  let compareOptions = {
141
- // Get the enum value rather than the name if needed
141
+ // Get the enum value rather than the name if needed.
142
142
  nodeValueGetter:
143
143
  options.sortByValue || (isNumericEnum && options.forceNumericSort)
144
144
  ? sortingNode => {
@@ -3,8 +3,8 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
4
4
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
5
5
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
6
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
6
7
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
7
- const isPartitionComment = require('../utils/is-partition-comment.js')
8
8
  const getCommentsBefore = require('../utils/get-comments-before.js')
9
9
  const createEslintRule = require('../utils/create-eslint-rule.js')
10
10
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -58,13 +58,13 @@ const sortExports = createEslintRule.createEslintRule({
58
58
  let lastNode = (_a = parts.at(-1)) == null ? void 0 : _a.at(-1)
59
59
  if (
60
60
  (partitionComment &&
61
- isPartitionComment.hasPartitionComment(
62
- partitionComment,
63
- getCommentsBefore.getCommentsBefore({
61
+ hasPartitionComment.hasPartitionComment({
62
+ comments: getCommentsBefore.getCommentsBefore({
64
63
  sourceCode,
65
64
  node,
66
65
  }),
67
- )) ||
66
+ partitionByComment: options.partitionByComment,
67
+ })) ||
68
68
  (options.partitionByNewLine &&
69
69
  lastNode &&
70
70
  getLinesBetween.getLinesBetween(sourceCode, lastNode, sortingNode))
@@ -20,7 +20,10 @@ let getTypescriptImport = () => {
20
20
  : (_documentCurrentScript &&
21
21
  _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' &&
22
22
  _documentCurrentScript.src) ||
23
- new URL('utils/get-typescript-import.js', document.baseURI).href,
23
+ new URL(
24
+ 'rules/sort-imports/get-typescript-import.js',
25
+ document.baseURI,
26
+ ).href,
24
27
  )('typescript')
25
28
  } catch (_error) {
26
29
  return null
@@ -3,14 +3,14 @@ const node_module = require('node:module')
3
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
4
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
5
5
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
6
+ const readClosestTsConfigByPath = require('./sort-imports/read-closest-ts-config-by-path.js')
6
7
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
7
- const readClosestTsConfigByPath = require('../utils/read-closest-ts-config-by-path.js')
8
8
  const getOptionsWithCleanGroups = require('../utils/get-options-with-clean-groups.js')
9
9
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
10
+ const getTypescriptImport = require('./sort-imports/get-typescript-import.js')
10
11
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
11
- const getTypescriptImport = require('../utils/get-typescript-import.js')
12
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
12
13
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
13
- const isPartitionComment = require('../utils/is-partition-comment.js')
14
14
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
15
15
  const getCommentsBefore = require('../utils/get-comments-before.js')
16
16
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
@@ -144,7 +144,9 @@ const sortImports = createEslintRule.createEslintRule({
144
144
  ]
145
145
  let isStyle = value => {
146
146
  let [cleanedValue] = value.split('?')
147
- return styleExtensions.some(extension => cleanedValue.endsWith(extension))
147
+ return styleExtensions.some(extension =>
148
+ cleanedValue == null ? void 0 : cleanedValue.endsWith(extension),
149
+ )
148
150
  }
149
151
  let flatGroups = new Set(options.groups.flat())
150
152
  let shouldRegroupSideEffectNodes = flatGroups.has('side-effect')
@@ -194,10 +196,12 @@ const sortImports = createEslintRule.createEslintRule({
194
196
  'ws',
195
197
  ]
196
198
  let builtinPrefixOnlyModules = ['sea', 'sqlite', 'test']
199
+ let valueToCheck = value.startsWith('node:')
200
+ ? value.split('node:')[1]
201
+ : value
197
202
  return (
198
- node_module.builtinModules.includes(
199
- value.startsWith('node:') ? value.split('node:')[1] : value,
200
- ) ||
203
+ (!!valueToCheck &&
204
+ node_module.builtinModules.includes(valueToCheck)) ||
201
205
  builtinPrefixOnlyModules.some(
202
206
  module2 => `node:${module2}` === value,
203
207
  ) ||
@@ -347,13 +351,13 @@ const sortImports = createEslintRule.createEslintRule({
347
351
  let lastGroup = formattedMembers.at(-1)
348
352
  let lastSortingNode = lastGroup == null ? void 0 : lastGroup.at(-1)
349
353
  if (
350
- isPartitionComment.hasPartitionComment(
351
- options.partitionByComment,
352
- getCommentsBefore.getCommentsBefore({
354
+ hasPartitionComment.hasPartitionComment({
355
+ comments: getCommentsBefore.getCommentsBefore({
353
356
  node: sortingNode.node,
354
357
  sourceCode,
355
358
  }),
356
- ) ||
359
+ partitionByComment: options.partitionByComment,
360
+ }) ||
357
361
  (options.partitionByNewLine &&
358
362
  lastSortingNode &&
359
363
  getLinesBetween.getLinesBetween(
@@ -410,12 +414,15 @@ const sortImports = createEslintRule.createEslintRule({
410
414
  messageIds = [
411
415
  ...messageIds,
412
416
  ...getNewlinesErrors.getNewlinesErrors({
417
+ options: {
418
+ ...options,
419
+ customGroups: [],
420
+ },
413
421
  missedSpacingError: 'missedSpacingBetweenImports',
414
422
  extraSpacingError: 'extraSpacingBetweenImports',
415
423
  rightNum: rightNumber,
416
424
  leftNum: leftNumber,
417
425
  sourceCode,
418
- options,
419
426
  right,
420
427
  left,
421
428
  }),
@@ -431,10 +438,13 @@ const sortImports = createEslintRule.createEslintRule({
431
438
  fixer,
432
439
  }),
433
440
  ...makeNewlinesFixes.makeNewlinesFixes({
441
+ options: {
442
+ ...options,
443
+ customGroups: [],
444
+ },
434
445
  sortedNodes: sortedNodesExcludingEslintDisabled,
435
446
  nodes: nodeList,
436
447
  sourceCode,
437
- options,
438
448
  fixer,
439
449
  }),
440
450
  ],
@@ -5,8 +5,8 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
5
5
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
6
6
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
7
7
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
8
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
8
9
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
9
- const isPartitionComment = require('../utils/is-partition-comment.js')
10
10
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
11
11
  const getCommentsBefore = require('../utils/get-comments-before.js')
12
12
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
@@ -144,14 +144,14 @@ const sortIntersectionTypes = createEslintRule.createEslintRule({
144
144
  node: type,
145
145
  }
146
146
  if (
147
- isPartitionComment.hasPartitionComment(
148
- options.partitionByComment,
149
- getCommentsBefore.getCommentsBefore({
147
+ hasPartitionComment.hasPartitionComment({
148
+ comments: getCommentsBefore.getCommentsBefore({
150
149
  tokenValueToIgnoreBefore: '&',
151
150
  node: type,
152
151
  sourceCode,
153
152
  }),
154
- ) ||
153
+ partitionByComment: options.partitionByComment,
154
+ }) ||
155
155
  (options.partitionByNewLine &&
156
156
  lastSortingNode &&
157
157
  getLinesBetween.getLinesBetween(
@@ -3,8 +3,8 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
3
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
4
4
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
5
5
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
6
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
6
7
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
7
- const isPartitionComment = require('../utils/is-partition-comment.js')
8
8
  const getCommentsBefore = require('../utils/get-comments-before.js')
9
9
  const createEslintRule = require('../utils/create-eslint-rule.js')
10
10
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -95,13 +95,13 @@ const sortMaps = createEslintRule.createEslintRule({
95
95
  name,
96
96
  }
97
97
  if (
98
- isPartitionComment.hasPartitionComment(
99
- options.partitionByComment,
100
- getCommentsBefore.getCommentsBefore({
98
+ hasPartitionComment.hasPartitionComment({
99
+ comments: getCommentsBefore.getCommentsBefore({
101
100
  node: element,
102
101
  sourceCode,
103
102
  }),
104
- ) ||
103
+ partitionByComment: options.partitionByComment,
104
+ }) ||
105
105
  (options.partitionByNewLine &&
106
106
  lastSortingNode &&
107
107
  getLinesBetween.getLinesBetween(
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../utils/matches.js')
4
- let customGroupMatches = props => {
3
+ const matches = require('../../utils/matches.js')
4
+ let doesCustomGroupMatch = props => {
5
5
  if ('anyOf' in props.customGroup) {
6
6
  return props.customGroup.anyOf.some(subgroup =>
7
- customGroupMatches({ ...props, customGroup: subgroup }),
7
+ doesCustomGroupMatch({ ...props, customGroup: subgroup }),
8
8
  )
9
9
  }
10
10
  if (
@@ -46,4 +46,4 @@ let customGroupMatches = props => {
46
46
  }
47
47
  return true
48
48
  }
49
- exports.customGroupMatches = customGroupMatches
49
+ exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
4
  let allSelectors = [
5
5
  'enum',
6
6
  'function',
@@ -4,14 +4,15 @@ const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
4
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
5
5
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
6
6
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
7
- const sortModules_types = require('./sort-modules.types.js')
7
+ const types = require('./sort-modules/types.js')
8
8
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
9
9
  const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
+ const doesCustomGroupMatch = require('./sort-modules/does-custom-group-match.js')
11
12
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
12
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
14
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
13
15
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
14
- const isPartitionComment = require('../utils/is-partition-comment.js')
15
16
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
16
17
  const getNewlinesErrors = require('../utils/get-newlines-errors.js')
17
18
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
@@ -21,7 +22,6 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
21
22
  const getLinesBetween = require('../utils/get-lines-between.js')
22
23
  const getGroupNumber = require('../utils/get-group-number.js')
23
24
  const getEnumMembers = require('../utils/get-enum-members.js')
24
- const sortModulesUtils = require('./sort-modules-utils.js')
25
25
  const getSourceCode = require('../utils/get-source-code.js')
26
26
  const toSingleLine = require('../utils/to-single-line.js')
27
27
  const rangeToDiff = require('../utils/range-to-diff.js')
@@ -69,8 +69,7 @@ const sortModules = createEslintRule.createEslintRule({
69
69
  'Allows to use comments to separate the modules members into logical groups.',
70
70
  },
71
71
  customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
72
- singleCustomGroupJsonSchema:
73
- sortModules_types.singleCustomGroupJsonSchema,
72
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
74
73
  }),
75
74
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
76
75
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
@@ -115,8 +114,8 @@ const sortModules = createEslintRule.createEslintRule({
115
114
  validateCustomSortConfiguration.validateCustomSortConfiguration(options)
116
115
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
117
116
  customGroups: options.customGroups,
118
- modifiers: sortModules_types.allModifiers,
119
- selectors: sortModules_types.allSelectors,
117
+ modifiers: types.allModifiers,
118
+ selectors: types.allSelectors,
120
119
  groups: options.groups,
121
120
  })
122
121
  validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
@@ -272,7 +271,7 @@ let analyzeModule = ({
272
271
  }
273
272
  for (let customGroup of options.customGroups) {
274
273
  if (
275
- sortModulesUtils.customGroupMatches({
274
+ doesCustomGroupMatch.doesCustomGroupMatch({
276
275
  selectors: [selector],
277
276
  elementName: name,
278
277
  customGroup,
@@ -309,13 +308,13 @@ let analyzeModule = ({
309
308
  lastSortingNode,
310
309
  sortingNode,
311
310
  )) ||
312
- isPartitionComment.hasPartitionComment(
313
- options.partitionByComment,
314
- getCommentsBefore.getCommentsBefore({
311
+ hasPartitionComment.hasPartitionComment({
312
+ comments: getCommentsBefore.getCommentsBefore({
315
313
  sourceCode,
316
314
  node,
317
315
  }),
318
- )
316
+ partitionByComment: options.partitionByComment,
317
+ })
319
318
  ) {
320
319
  formattedNodes.push([])
321
320
  }