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
@@ -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(
@@ -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')
@@ -277,13 +277,13 @@ const sortObjects = createEslintRule.createEslintRule({
277
277
  lastProperty,
278
278
  propertySortingNode,
279
279
  )) ||
280
- isPartitionComment.hasPartitionComment(
281
- options.partitionByComment,
282
- getCommentsBefore.getCommentsBefore({
280
+ hasPartitionComment.hasPartitionComment({
281
+ comments: getCommentsBefore.getCommentsBefore({
283
282
  node: property,
284
283
  sourceCode,
285
284
  }),
286
- )
285
+ partitionByComment: options.partitionByComment,
286
+ })
287
287
  ) {
288
288
  accumulator.push([])
289
289
  }
@@ -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()
@@ -79,19 +79,33 @@ let customGroupsJsonSchema = {
79
79
  description: 'Specifies custom groups.',
80
80
  type: 'object',
81
81
  }
82
+ let allowedPartitionByCommentJsonSchemas = [
83
+ {
84
+ items: {
85
+ type: 'string',
86
+ },
87
+ type: 'array',
88
+ },
89
+ {
90
+ type: 'boolean',
91
+ },
92
+ {
93
+ type: 'string',
94
+ },
95
+ ]
82
96
  let partitionByCommentJsonSchema = {
83
- anyOf: [
97
+ oneOf: [
98
+ ...allowedPartitionByCommentJsonSchemas,
84
99
  {
85
- items: {
86
- type: 'string',
100
+ properties: {
101
+ block: {
102
+ oneOf: allowedPartitionByCommentJsonSchemas,
103
+ },
104
+ line: {
105
+ oneOf: allowedPartitionByCommentJsonSchemas,
106
+ },
87
107
  },
88
- type: 'array',
89
- },
90
- {
91
- type: 'boolean',
92
- },
93
- {
94
- type: 'string',
108
+ type: 'object',
95
109
  },
96
110
  ],
97
111
  }
@@ -101,8 +115,7 @@ let partitionByNewLineJsonSchema = {
101
115
  type: 'boolean',
102
116
  }
103
117
  let newlinesBetweenJsonSchema = {
104
- description:
105
- 'Specifies how new lines should be handled between modules members groups.',
118
+ description: 'Specifies how new lines should be handled between groups.',
106
119
  enum: ['ignore', 'always', 'never'],
107
120
  type: 'string',
108
121
  }
@@ -134,6 +147,14 @@ let customGroupNameJsonSchema = {
134
147
  type: 'string',
135
148
  },
136
149
  }
150
+ let customGroupNewlinesInsideJsonSchema = {
151
+ newlinesInside: {
152
+ description:
153
+ 'Specifies how new lines should be handled between members of the custom group.',
154
+ enum: ['always', 'never'],
155
+ type: 'string',
156
+ },
157
+ }
137
158
  let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
138
159
  items: {
139
160
  oneOf: [
@@ -141,6 +162,7 @@ let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
141
162
  properties: {
142
163
  ...customGroupNameJsonSchema,
143
164
  ...customGroupSortJsonSchema,
165
+ ...customGroupNewlinesInsideJsonSchema,
144
166
  anyOf: {
145
167
  items: {
146
168
  properties: {
@@ -161,6 +183,7 @@ let buildCustomGroupsArrayJsonSchema = ({ singleCustomGroupJsonSchema }) => ({
161
183
  properties: {
162
184
  ...customGroupNameJsonSchema,
163
185
  ...customGroupSortJsonSchema,
186
+ ...customGroupNewlinesInsideJsonSchema,
164
187
  ...singleCustomGroupJsonSchema,
165
188
  },
166
189
  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,54 @@
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
+ if (!options.customGroups || !Array.isArray(options.customGroups)) {
19
+ return globalNewlinesBetweenOption
20
+ }
21
+ let nodeGroup = options.groups[nodeGroupNumber]
22
+ let nextNodeGroup = options.groups[nextNodeGroupNumber]
23
+ if (Array.isArray(nodeGroup) || Array.isArray(nextNodeGroup)) {
24
+ return globalNewlinesBetweenOption
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
+ return globalNewlinesBetweenOption
40
+ }
41
+ let getGlobalNewlinesBetweenOption = ({
42
+ nextNodeGroupNumber,
43
+ newlinesBetween,
44
+ nodeGroupNumber,
45
+ }) => {
46
+ if (newlinesBetween === 'ignore') {
47
+ return 'ignore'
48
+ }
49
+ if (newlinesBetween === 'never') {
50
+ return 'never'
51
+ }
52
+ return nodeGroupNumber === nextNodeGroupNumber ? 'never' : 'always'
53
+ }
54
+ exports.getNewlinesBetweenOption = getNewlinesBetweenOption
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const getNewlinesBetweenOption = require('./get-newlines-between-option.js')
3
4
  const getLinesBetween = require('./get-lines-between.js')
4
5
  let getNewlinesErrors = ({
5
6
  missedSpacingError,
@@ -11,25 +12,31 @@ let getNewlinesErrors = ({
11
12
  right,
12
13
  left,
13
14
  }) => {
14
- let errors = []
15
+ let newlinesBetween = getNewlinesBetweenOption.getNewlinesBetweenOption({
16
+ nextSortingNode: right,
17
+ sortingNode: left,
18
+ options,
19
+ })
20
+ if (leftNum > rightNum) {
21
+ return []
22
+ }
15
23
  let numberOfEmptyLinesBetween = getLinesBetween.getLinesBetween(
16
24
  sourceCode,
17
25
  left,
18
26
  right,
19
27
  )
20
- if (options.newlinesBetween === 'never' && numberOfEmptyLinesBetween > 0) {
21
- errors.push(extraSpacingError)
22
- }
23
- if (options.newlinesBetween === 'always') {
24
- if (leftNum < rightNum && numberOfEmptyLinesBetween === 0) {
25
- errors.push(missedSpacingError)
26
- } else if (
27
- numberOfEmptyLinesBetween > 1 ||
28
- (leftNum === rightNum && numberOfEmptyLinesBetween > 0)
29
- ) {
30
- errors.push(extraSpacingError)
31
- }
28
+ switch (newlinesBetween) {
29
+ case 'ignore':
30
+ return []
31
+ case 'never':
32
+ return numberOfEmptyLinesBetween > 0 ? [extraSpacingError] : []
33
+ case 'always':
34
+ if (numberOfEmptyLinesBetween === 0) {
35
+ return [missedSpacingError]
36
+ } else if (numberOfEmptyLinesBetween > 1) {
37
+ return [extraSpacingError]
38
+ }
32
39
  }
33
- return errors
40
+ return []
34
41
  }
35
42
  exports.getNewlinesErrors = getNewlinesErrors
@@ -36,10 +36,11 @@ let getNodeRange = ({
36
36
  comment.value,
37
37
  )
38
38
  if (
39
- isPartitionComment.isPartitionComment(
40
- (options == null ? void 0 : options.partitionByComment) ?? false,
41
- comment.value,
42
- ) ||
39
+ isPartitionComment.isPartitionComment({
40
+ partitionByComment:
41
+ (options == null ? void 0 : options.partitionByComment) ?? false,
42
+ comment,
43
+ }) ||
43
44
  (eslintDisabledRules == null
44
45
  ? void 0
45
46
  : eslintDisabledRules.eslintDisableDirective) === 'eslint-disable' ||
@@ -9,5 +9,5 @@ let getOptionsWithCleanGroups = options => ({
9
9
  ),
10
10
  })
11
11
  let getCleanedNestedGroups = nestedGroup =>
12
- nestedGroup.length === 1 ? nestedGroup[0] : nestedGroup
12
+ nestedGroup.length === 1 && nestedGroup[0] ? nestedGroup[0] : nestedGroup
13
13
  exports.getOptionsWithCleanGroups = getOptionsWithCleanGroups
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
3
  let getSettings = (settings = {}) => {
4
- if (!settings.perfectionist) {
4
+ if (!settings['perfectionist']) {
5
5
  return {}
6
6
  }
7
7
  let getInvalidOptions = object => {
@@ -18,13 +18,13 @@ let getSettings = (settings = {}) => {
18
18
  ])
19
19
  return Object.keys(object).filter(key => !allowedOptions.has(key))
20
20
  }
21
- let perfectionistSettings = settings.perfectionist
21
+ let perfectionistSettings = settings['perfectionist']
22
22
  let invalidOptions = getInvalidOptions(perfectionistSettings)
23
23
  if (invalidOptions.length) {
24
24
  throw new Error(
25
25
  `Invalid Perfectionist setting(s): ${invalidOptions.join(', ')}`,
26
26
  )
27
27
  }
28
- return settings.perfectionist
28
+ return settings['perfectionist']
29
29
  }
30
30
  exports.getSettings = getSettings
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const isPartitionComment = require('./is-partition-comment.js')
4
+ let hasPartitionComment = ({ partitionByComment, comments }) =>
5
+ comments.some(comment =>
6
+ isPartitionComment.isPartitionComment({
7
+ partitionByComment,
8
+ comment,
9
+ }),
10
+ )
11
+ exports.hasPartitionComment = hasPartitionComment
@@ -1,25 +1,51 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const types = require('@typescript-eslint/types')
3
4
  const getEslintDisabledRules = require('./get-eslint-disabled-rules.js')
4
5
  const matches = require('./matches.js')
5
- let isPartitionComment = (partitionComment, comment) => {
6
+ let isPartitionComment = ({ partitionByComment, comment }) => {
6
7
  if (
7
- getEslintDisabledRules.getEslintDisabledRules(comment) ||
8
- !partitionComment
8
+ getEslintDisabledRules.getEslintDisabledRules(comment.value) ||
9
+ !partitionByComment
9
10
  ) {
10
11
  return false
11
12
  }
13
+ let trimmedComment = comment.value.trim()
14
+ if (
15
+ Array.isArray(partitionByComment) ||
16
+ typeof partitionByComment === 'boolean' ||
17
+ typeof partitionByComment === 'string'
18
+ ) {
19
+ return isTrimmedCommentPartitionComment({
20
+ partitionByComment,
21
+ trimmedComment,
22
+ })
23
+ }
24
+ let relevantPartitionByComment =
25
+ comment.type === types.AST_TOKEN_TYPES.Block
26
+ ? partitionByComment.block
27
+ : partitionByComment.line
12
28
  return (
13
- (Array.isArray(partitionComment) &&
14
- partitionComment.some(pattern =>
15
- matches.matches(comment.trim(), pattern),
16
- )) ||
17
- (typeof partitionComment === 'string' &&
18
- matches.matches(comment.trim(), partitionComment)) ||
19
- partitionComment === true
29
+ // eslint-disable-next-line no-undefined
30
+ relevantPartitionByComment !== void 0 &&
31
+ isTrimmedCommentPartitionComment({
32
+ partitionByComment: relevantPartitionByComment,
33
+ trimmedComment,
34
+ })
35
+ )
36
+ }
37
+ let isTrimmedCommentPartitionComment = ({
38
+ partitionByComment,
39
+ trimmedComment,
40
+ }) => {
41
+ if (typeof partitionByComment === 'boolean') {
42
+ return partitionByComment
43
+ }
44
+ if (typeof partitionByComment === 'string') {
45
+ return matches.matches(trimmedComment.trim(), partitionByComment)
46
+ }
47
+ return partitionByComment.some(pattern =>
48
+ matches.matches(trimmedComment.trim(), pattern),
20
49
  )
21
50
  }
22
- let hasPartitionComment = (partitionComment, comments) =>
23
- comments.some(comment => isPartitionComment(partitionComment, comment.value))
24
- exports.hasPartitionComment = hasPartitionComment
25
51
  exports.isPartitionComment = isPartitionComment