eslint-plugin-perfectionist 4.4.0 → 4.6.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 (47) 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 +24 -14
  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/{utils → rules/sort-objects}/get-first-node-parent-with-type.js +4 -1
  25. package/dist/rules/sort-objects.js +28 -14
  26. package/dist/rules/sort-union-types.js +5 -5
  27. package/dist/rules/sort-variable-declarations.js +5 -5
  28. package/dist/utils/alphabet.js +1 -2
  29. package/dist/utils/common-json-schemas.js +45 -16
  30. package/dist/utils/compare.js +8 -2
  31. package/dist/utils/get-eslint-disabled-rules.js +4 -2
  32. package/dist/utils/get-newlines-between-option.js +61 -0
  33. package/dist/utils/get-newlines-errors.js +21 -14
  34. package/dist/utils/get-node-range.js +5 -4
  35. package/dist/utils/get-options-with-clean-groups.js +3 -3
  36. package/dist/utils/get-settings.js +3 -3
  37. package/dist/utils/has-partition-comment.js +11 -0
  38. package/dist/utils/is-partition-comment.js +39 -13
  39. package/dist/utils/make-newlines-fixes.js +19 -29
  40. package/dist/utils/sort-nodes-by-groups.js +3 -7
  41. package/dist/utils/validate-generated-groups-configuration.js +1 -0
  42. package/dist/utils/validate-groups-configuration.js +23 -3
  43. package/dist/utils/validate-newlines-and-partition-configuration.js +13 -1
  44. package/package.json +3 -3
  45. /package/dist/{utils → rules/sort-decorators}/get-decorator-name.js +0 -0
  46. /package/dist/{utils → rules/sort-imports}/read-closest-ts-config-by-path.js +0 -0
  47. /package/dist/{utils → rules/sort-object-types}/is-member-optional.js +0 -0
@@ -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
  }
@@ -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')
@@ -68,13 +68,13 @@ const sortNamedExports = createEslintRule.createEslintRule({
68
68
  name,
69
69
  }
70
70
  if (
71
- isPartitionComment.hasPartitionComment(
72
- options.partitionByComment,
73
- getCommentsBefore.getCommentsBefore({
71
+ hasPartitionComment.hasPartitionComment({
72
+ comments: getCommentsBefore.getCommentsBefore({
74
73
  node: specifier,
75
74
  sourceCode,
76
75
  }),
77
- ) ||
76
+ partitionByComment: options.partitionByComment,
77
+ }) ||
78
78
  (options.partitionByNewLine &&
79
79
  lastSortingNode &&
80
80
  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')
@@ -77,13 +77,13 @@ const sortNamedImports = createEslintRule.createEslintRule({
77
77
  name,
78
78
  }
79
79
  if (
80
- isPartitionComment.hasPartitionComment(
81
- options.partitionByComment,
82
- getCommentsBefore.getCommentsBefore({
80
+ hasPartitionComment.hasPartitionComment({
81
+ comments: getCommentsBefore.getCommentsBefore({
83
82
  node: specifier,
84
83
  sourceCode,
85
84
  }),
86
- ) ||
85
+ partitionByComment: options.partitionByComment,
86
+ }) ||
87
87
  (options.partitionByNewLine &&
88
88
  lastSortingNode &&
89
89
  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 (
@@ -34,4 +34,4 @@ let customGroupMatches = props => {
34
34
  }
35
35
  return true
36
36
  }
37
- exports.customGroupMatches = customGroupMatches
37
+ 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
  'index-signature',
6
6
  'member',
@@ -5,15 +5,17 @@ Object.defineProperties(exports, {
5
5
  })
6
6
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
7
7
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
8
+ const types = require('./sort-object-types/types.js')
8
9
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
9
10
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
10
11
  const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
12
+ const doesCustomGroupMatch = require('./sort-object-types/does-custom-group-match.js')
11
13
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
12
14
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
13
15
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
14
- const sortObjectTypes_types = require('./sort-object-types.types.js')
16
+ const isMemberOptional = require('./sort-object-types/is-member-optional.js')
15
17
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
16
- const isPartitionComment = require('../utils/is-partition-comment.js')
18
+ const hasPartitionComment = require('../utils/has-partition-comment.js')
17
19
  const isNodeFunctionType = require('../utils/is-node-function-type.js')
18
20
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
19
21
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
@@ -21,8 +23,6 @@ const getCommentsBefore = require('../utils/get-comments-before.js')
21
23
  const makeNewlinesFixes = require('../utils/make-newlines-fixes.js')
22
24
  const getNewlinesErrors = require('../utils/get-newlines-errors.js')
23
25
  const createEslintRule = require('../utils/create-eslint-rule.js')
24
- const isMemberOptional = require('../utils/is-member-optional.js')
25
- const sortObjectTypesUtils = require('./sort-object-types-utils.js')
26
26
  const getLinesBetween = require('../utils/get-lines-between.js')
27
27
  const getGroupNumber = require('../utils/get-group-number.js')
28
28
  const getSourceCode = require('../utils/get-source-code.js')
@@ -79,8 +79,7 @@ let jsonSchema = {
79
79
  oneOf: [
80
80
  commonJsonSchemas.customGroupsJsonSchema,
81
81
  commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
82
- singleCustomGroupJsonSchema:
83
- sortObjectTypes_types.singleCustomGroupJsonSchema,
82
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
84
83
  }),
85
84
  ],
86
85
  },
@@ -197,8 +196,8 @@ let sortObjectTypeElements = ({
197
196
  validateCustomSortConfiguration.validateCustomSortConfiguration(options)
198
197
  validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
199
198
  customGroups: options.customGroups,
200
- selectors: sortObjectTypes_types.allSelectors,
201
- modifiers: sortObjectTypes_types.allModifiers,
199
+ selectors: types.allSelectors,
200
+ modifiers: types.allModifiers,
202
201
  groups: options.groups,
203
202
  })
204
203
  validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
@@ -265,7 +264,7 @@ let sortObjectTypeElements = ({
265
264
  if (Array.isArray(options.customGroups)) {
266
265
  for (let customGroup of options.customGroups) {
267
266
  if (
268
- sortObjectTypesUtils.customGroupMatches({
267
+ doesCustomGroupMatch.doesCustomGroupMatch({
269
268
  elementName: name,
270
269
  customGroup,
271
270
  selectors,
@@ -299,13 +298,13 @@ let sortObjectTypeElements = ({
299
298
  }
300
299
  if (
301
300
  (options.partitionByComment &&
302
- isPartitionComment.hasPartitionComment(
303
- options.partitionByComment,
304
- getCommentsBefore.getCommentsBefore({
301
+ hasPartitionComment.hasPartitionComment({
302
+ comments: getCommentsBefore.getCommentsBefore({
305
303
  node: typeElement,
306
304
  sourceCode,
307
305
  }),
308
- )) ||
306
+ partitionByComment: options.partitionByComment,
307
+ })) ||
309
308
  (options.partitionByNewLine &&
310
309
  lastSortingNode &&
311
310
  getLinesBetween.getLinesBetween(
@@ -1,7 +1,10 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- let getFirstNodeParentWithType = ({ allowedTypes, node }) => {
3
+ let getFirstNodeParentWithType = ({ onlyFirstParent, allowedTypes, node }) => {
4
4
  let { parent } = node
5
+ if (onlyFirstParent) {
6
+ return parent && allowedTypes.includes(parent.type) ? parent : null
7
+ }
5
8
  while (parent) {
6
9
  if (allowedTypes.includes(parent.type)) {
7
10
  return parent
@@ -4,13 +4,13 @@ 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 validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
7
- const getFirstNodeParentWithType = require('../utils/get-first-node-parent-with-type.js')
7
+ const getFirstNodeParentWithType = require('./sort-objects/get-first-node-parent-with-type.js')
8
8
  const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
9
9
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
10
10
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
11
11
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.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')
@@ -55,7 +55,10 @@ const sortObjects = createEslintRule.createEslintRule({
55
55
  if (!isSortable.isSortable(nodeObject.properties)) {
56
56
  return
57
57
  }
58
- let objectParent = getObjectParent({ node: nodeObject })
58
+ let objectParent = getObjectParent({
59
+ onlyFirstParent: true,
60
+ node: nodeObject,
61
+ })
59
62
  let matchedContextOptions = getMatchingContextOptions
60
63
  .getMatchingContextOptions({
61
64
  nodeNames: nodeObject.properties
@@ -114,10 +117,16 @@ const sortObjects = createEslintRule.createEslintRule({
114
117
  } else if (options.destructureOnly || !options.objectDeclarations) {
115
118
  return
116
119
  }
120
+ let objectParentForIgnorePattern = getObjectParent({
121
+ onlyFirstParent: false,
122
+ node: nodeObject,
123
+ })
117
124
  if (
118
- (objectParent == null ? void 0 : objectParent.name) &&
125
+ (objectParentForIgnorePattern == null
126
+ ? void 0
127
+ : objectParentForIgnorePattern.name) &&
119
128
  options.ignorePattern.some(pattern =>
120
- matches.matches(objectParent.name, pattern),
129
+ matches.matches(objectParentForIgnorePattern.name, pattern),
121
130
  )
122
131
  ) {
123
132
  return
@@ -277,13 +286,13 @@ const sortObjects = createEslintRule.createEslintRule({
277
286
  lastProperty,
278
287
  propertySortingNode,
279
288
  )) ||
280
- isPartitionComment.hasPartitionComment(
281
- options.partitionByComment,
282
- getCommentsBefore.getCommentsBefore({
289
+ hasPartitionComment.hasPartitionComment({
290
+ comments: getCommentsBefore.getCommentsBefore({
283
291
  node: property,
284
292
  sourceCode,
285
293
  }),
286
- )
294
+ partitionByComment: options.partitionByComment,
295
+ })
287
296
  ) {
288
297
  accumulator.push([])
289
298
  }
@@ -501,15 +510,18 @@ let getNodeName = ({ sourceCode, property }) => {
501
510
  }
502
511
  return sourceCode.getText(property.key)
503
512
  }
504
- let getObjectParent = ({ node }) => {
505
- let variableParentName = getVariableParentName({ node })
513
+ let getObjectParent = ({ onlyFirstParent, node }) => {
514
+ let variableParentName = getVariableParentName({ onlyFirstParent, node })
506
515
  if (variableParentName) {
507
516
  return {
508
517
  type: 'VariableDeclarator',
509
518
  name: variableParentName,
510
519
  }
511
520
  }
512
- let callParentName = getCallExpressionParentName({ node })
521
+ let callParentName = getCallExpressionParentName({
522
+ onlyFirstParent,
523
+ node,
524
+ })
513
525
  if (callParentName) {
514
526
  return {
515
527
  type: 'CallExpression',
@@ -518,12 +530,13 @@ let getObjectParent = ({ node }) => {
518
530
  }
519
531
  return null
520
532
  }
521
- let getVariableParentName = ({ node }) => {
533
+ let getVariableParentName = ({ onlyFirstParent, node }) => {
522
534
  let variableParent = getFirstNodeParentWithType.getFirstNodeParentWithType({
523
535
  allowedTypes: [
524
536
  types.TSESTree.AST_NODE_TYPES.VariableDeclarator,
525
537
  types.TSESTree.AST_NODE_TYPES.Property,
526
538
  ],
539
+ onlyFirstParent,
527
540
  node,
528
541
  })
529
542
  if (!variableParent) {
@@ -539,9 +552,10 @@ let getVariableParentName = ({ node }) => {
539
552
  }
540
553
  return parentId.type === 'Identifier' ? parentId.name : null
541
554
  }
542
- let getCallExpressionParentName = ({ node }) => {
555
+ let getCallExpressionParentName = ({ onlyFirstParent, node }) => {
543
556
  let callParent = getFirstNodeParentWithType.getFirstNodeParentWithType({
544
557
  allowedTypes: [types.TSESTree.AST_NODE_TYPES.CallExpression],
558
+ onlyFirstParent,
545
559
  node,
546
560
  })
547
561
  if (!callParent) {
@@ -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 sortUnionTypes = 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(
@@ -4,8 +4,8 @@ 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 hasPartitionComment = require('../utils/has-partition-comment.js')
7
8
  const createNodeIndexMap = require('../utils/create-node-index-map.js')
8
- const isPartitionComment = require('../utils/is-partition-comment.js')
9
9
  const getCommentsBefore = require('../utils/get-comments-before.js')
10
10
  const createEslintRule = require('../utils/create-eslint-rule.js')
11
11
  const getLinesBetween = require('../utils/get-lines-between.js')
@@ -147,13 +147,13 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
147
147
  name,
148
148
  }
149
149
  if (
150
- isPartitionComment.hasPartitionComment(
151
- options.partitionByComment,
152
- getCommentsBefore.getCommentsBefore({
150
+ hasPartitionComment.hasPartitionComment({
151
+ comments: getCommentsBefore.getCommentsBefore({
153
152
  node: declaration,
154
153
  sourceCode,
155
154
  }),
156
- ) ||
155
+ partitionByComment: options.partitionByComment,
156
+ }) ||
157
157
  (options.partitionByNewLine &&
158
158
  lastSortingNode &&
159
159
  getLinesBetween.getLinesBetween(
@@ -94,8 +94,7 @@ class Alphabet {
94
94
  * @returns {Alphabet} - The same alphabet instance with the cases prioritized
95
95
  * @example
96
96
  * Alphabet.generateFrom('aAbBcdCD')
97
- * .prioritizeCase('uppercase')
98
- * // Returns 'AaBbCDcd'
97
+ * .prioritizeCase('uppercase') // Returns 'AaBbCDcd'.
99
98
  */
100
99
  prioritizeCase(casePriority) {
101
100
  let charactersWithCase = this._getCharactersWithCase()
@@ -45,6 +45,11 @@ let specialCharactersJsonSchema = {
45
45
  enum: ['remove', 'trim', 'keep'],
46
46
  type: 'string',
47
47
  }
48
+ let newlinesBetweenJsonSchema = {
49
+ description: 'Specifies how new lines should be handled between groups.',
50
+ enum: ['ignore', 'always', 'never'],
51
+ type: 'string',
52
+ }
48
53
  let groupsJsonSchema = {
49
54
  items: {
50
55
  oneOf: [
@@ -57,6 +62,12 @@ let groupsJsonSchema = {
57
62
  },
58
63
  type: 'array',
59
64
  },
65
+ {
66
+ properties: {
67
+ newlinesBetween: newlinesBetweenJsonSchema,
68
+ },
69
+ type: 'object',
70
+ },
60
71
  ],
61
72
  },
62
73
  description: 'Specifies the order of the groups.',
@@ -79,19 +90,33 @@ let customGroupsJsonSchema = {
79
90
  description: 'Specifies custom groups.',
80
91
  type: 'object',
81
92
  }
93
+ let allowedPartitionByCommentJsonSchemas = [
94
+ {
95
+ items: {
96
+ type: 'string',
97
+ },
98
+ type: 'array',
99
+ },
100
+ {
101
+ type: 'boolean',
102
+ },
103
+ {
104
+ type: 'string',
105
+ },
106
+ ]
82
107
  let partitionByCommentJsonSchema = {
83
- anyOf: [
108
+ oneOf: [
109
+ ...allowedPartitionByCommentJsonSchemas,
84
110
  {
85
- items: {
86
- type: 'string',
111
+ properties: {
112
+ block: {
113
+ oneOf: allowedPartitionByCommentJsonSchemas,
114
+ },
115
+ line: {
116
+ oneOf: allowedPartitionByCommentJsonSchemas,
117
+ },
87
118
  },
88
- type: 'array',
89
- },
90
- {
91
- type: 'boolean',
92
- },
93
- {
94
- type: 'string',
119
+ type: 'object',
95
120
  },
96
121
  ],
97
122
  }
@@ -100,12 +125,6 @@ let partitionByNewLineJsonSchema = {
100
125
  'Allows to use newlines to separate the nodes into logical groups.',
101
126
  type: 'boolean',
102
127
  }
103
- let newlinesBetweenJsonSchema = {
104
- description:
105
- 'Specifies how new lines should be handled between modules members groups.',
106
- enum: ['ignore', 'always', 'never'],
107
- type: 'string',
108
- }
109
128
  let buildUseConfigurationIfJsonSchema = ({ additionalProperties } = {}) => ({
110
129
  properties: {
111
130
  allNamesMatchPattern: {
@@ -134,6 +153,14 @@ let customGroupNameJsonSchema = {
134
153
  type: 'string',
135
154
  },
136
155
  }
156
+ let customGroupNewlinesInsideJsonSchema = {
157
+ newlinesInside: {
158
+ description:
159
+ 'Specifies how new lines should be handled between members of the custom group.',
160
+ enum: ['always', 'never'],
161
+ type: 'string',
162
+ },
163
+ }
137
164
  let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
138
165
  items: {
139
166
  oneOf: [
@@ -141,6 +168,7 @@ let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
141
168
  properties: {
142
169
  ...customGroupNameJsonSchema,
143
170
  ...customGroupSortJsonSchema,
171
+ ...customGroupNewlinesInsideJsonSchema,
144
172
  anyOf: {
145
173
  items: {
146
174
  properties: {
@@ -161,6 +189,7 @@ let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
161
189
  properties: {
162
190
  ...customGroupNameJsonSchema,
163
191
  ...customGroupSortJsonSchema,
192
+ ...customGroupNewlinesInsideJsonSchema,
164
193
  ...singleCustomGroupJsonSchema,
165
194
  },
166
195
  description: 'Custom group.',
@@ -65,7 +65,8 @@ let getCustomSortingFunction = (
65
65
  return (aNode, bNode) => {
66
66
  let aValue = formatString(nodeValueGetter(aNode))
67
67
  let bValue = formatString(nodeValueGetter(bNode))
68
- for (let i = 0; i < aValue.length; i++) {
68
+ let minLength = Math.min(aValue.length, bValue.length)
69
+ for (let i = 0; i < minLength; i++) {
69
70
  let aCharacter = aValue[i]
70
71
  let bCharacter = bValue[i]
71
72
  let indexOfA = indexByCharacters.get(aCharacter)
@@ -78,7 +79,12 @@ let getCustomSortingFunction = (
78
79
  )
79
80
  }
80
81
  }
81
- return 0
82
+ if (aValue.length === bValue.length) {
83
+ return 0
84
+ }
85
+ return convertBooleanToSign.convertBooleanToSign(
86
+ aValue.length - bValue.length > 0,
87
+ )
82
88
  }
83
89
  }
84
90
  let getLineLengthSortingFunction =
@@ -28,10 +28,12 @@ let getEslintDisabledRulesByType = (comment, eslintDisableDirective) => {
28
28
  }
29
29
  let regexp = new RegExp(`^${eslintDisableDirective} ((?:.|\\s)*)$`)
30
30
  let disabledRulesMatch = trimmedCommentValue.match(regexp)
31
- if (!disabledRulesMatch) {
31
+ let disableRulesMatchValue =
32
+ disabledRulesMatch == null ? void 0 : disabledRulesMatch[1]
33
+ if (!disableRulesMatchValue) {
32
34
  return null
33
35
  }
34
- return disabledRulesMatch[1]
36
+ return disableRulesMatchValue
35
37
  .split(',')
36
38
  .map(rule => rule.trim())
37
39
  .filter(rule => !!rule)
@@ -0,0 +1,61 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const getGroupNumber = require('./get-group-number.js')
4
+ let getNewlinesBetweenOption = ({ nextSortingNode, sortingNode, options }) => {
5
+ let nodeGroupNumber = getGroupNumber.getGroupNumber(
6
+ options.groups,
7
+ sortingNode,
8
+ )
9
+ let nextNodeGroupNumber = getGroupNumber.getGroupNumber(
10
+ options.groups,
11
+ nextSortingNode,
12
+ )
13
+ let globalNewlinesBetweenOption = getGlobalNewlinesBetweenOption({
14
+ newlinesBetween: options.newlinesBetween,
15
+ nextNodeGroupNumber,
16
+ nodeGroupNumber,
17
+ })
18
+ let nodeGroup = options.groups[nodeGroupNumber]
19
+ let nextNodeGroup = options.groups[nextNodeGroupNumber]
20
+ if (
21
+ Array.isArray(options.customGroups) &&
22
+ typeof nodeGroup === 'string' &&
23
+ typeof nextNodeGroup === 'string' &&
24
+ nodeGroup === nextNodeGroup
25
+ ) {
26
+ let nodeCustomGroup = options.customGroups.find(
27
+ customGroup => customGroup.groupName === nodeGroup,
28
+ )
29
+ let nextNodeCustomGroup = options.customGroups.find(
30
+ customGroup => customGroup.groupName === nextNodeGroup,
31
+ )
32
+ if (
33
+ nodeCustomGroup &&
34
+ nextNodeCustomGroup &&
35
+ nodeCustomGroup.groupName === nextNodeCustomGroup.groupName
36
+ ) {
37
+ return nodeCustomGroup.newlinesInside ?? globalNewlinesBetweenOption
38
+ }
39
+ }
40
+ if (nextNodeGroupNumber === nodeGroupNumber + 2) {
41
+ let groupBetween = options.groups[nodeGroupNumber + 1]
42
+ if (typeof groupBetween === 'object' && 'newlinesBetween' in groupBetween) {
43
+ return groupBetween.newlinesBetween
44
+ }
45
+ }
46
+ return globalNewlinesBetweenOption
47
+ }
48
+ let getGlobalNewlinesBetweenOption = ({
49
+ nextNodeGroupNumber,
50
+ newlinesBetween,
51
+ nodeGroupNumber,
52
+ }) => {
53
+ if (newlinesBetween === 'ignore') {
54
+ return 'ignore'
55
+ }
56
+ if (newlinesBetween === 'never') {
57
+ return 'never'
58
+ }
59
+ return nodeGroupNumber === nextNodeGroupNumber ? 'never' : 'always'
60
+ }
61
+ exports.getNewlinesBetweenOption = getNewlinesBetweenOption