eslint-plugin-perfectionist 4.1.1 → 4.2.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.
@@ -1,13 +1,12 @@
1
1
  'use strict'
2
2
  const utils = require('@typescript-eslint/utils')
3
- const isSortable = require('utils/is-sortable')
4
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
5
- const sortModules_types = require('./sort-modules.types.js')
6
4
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
7
5
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
6
+ const sortModules_types = require('./sort-modules.types.js')
8
7
  const validateGeneratedGroupsConfiguration = require('./validate-generated-groups-configuration.js')
8
+ const getCustomGroupsCompareOptions = require('./get-custom-groups-compare-options.js')
9
9
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
10
- const sortModulesUtils = require('./sort-modules-utils.js')
11
10
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
12
11
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
13
12
  const isPartitionComment = require('../utils/is-partition-comment.js')
@@ -20,10 +19,12 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
20
19
  const getLinesBetween = require('../utils/get-lines-between.js')
21
20
  const getGroupNumber = require('../utils/get-group-number.js')
22
21
  const getEnumMembers = require('../utils/get-enum-members.js')
22
+ const sortModulesUtils = require('./sort-modules-utils.js')
23
23
  const getSourceCode = require('../utils/get-source-code.js')
24
24
  const toSingleLine = require('../utils/to-single-line.js')
25
25
  const rangeToDiff = require('../utils/range-to-diff.js')
26
26
  const getSettings = require('../utils/get-settings.js')
27
+ const isSortable = require('../utils/is-sortable.js')
27
28
  const useGroups = require('../utils/use-groups.js')
28
29
  const makeFixes = require('../utils/make-fixes.js')
29
30
  const complete = require('../utils/complete.js')
@@ -59,49 +60,15 @@ const sortModules = createEslintRule.createEslintRule({
59
60
  schema: [
60
61
  {
61
62
  properties: {
62
- customGroups: {
63
- items: {
64
- oneOf: [
65
- {
66
- properties: {
67
- ...sortModules_types.customGroupNameJsonSchema,
68
- ...sortModules_types.customGroupSortJsonSchema,
69
- anyOf: {
70
- items: {
71
- properties: {
72
- ...sortModules_types.singleCustomGroupJsonSchema,
73
- },
74
- description: 'Custom group.',
75
- additionalProperties: false,
76
- type: 'object',
77
- },
78
- type: 'array',
79
- },
80
- },
81
- description: 'Custom group block.',
82
- additionalProperties: false,
83
- type: 'object',
84
- },
85
- {
86
- properties: {
87
- ...sortModules_types.customGroupNameJsonSchema,
88
- ...sortModules_types.customGroupSortJsonSchema,
89
- ...sortModules_types.singleCustomGroupJsonSchema,
90
- },
91
- description: 'Custom group.',
92
- additionalProperties: false,
93
- type: 'object',
94
- },
95
- ],
96
- },
97
- description: 'Specifies custom groups.',
98
- type: 'array',
99
- },
100
63
  partitionByComment: {
101
64
  ...commonJsonSchemas.partitionByCommentJsonSchema,
102
65
  description:
103
66
  'Allows to use comments to separate the modules members into logical groups.',
104
67
  },
68
+ customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
69
+ singleCustomGroupJsonSchema:
70
+ sortModules_types.singleCustomGroupJsonSchema,
71
+ }),
105
72
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
106
73
  specialCharacters: commonJsonSchemas.specialCharactersJsonSchema,
107
74
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
@@ -327,7 +294,6 @@ let analyzeModule = ({
327
294
  node,
328
295
  name,
329
296
  }
330
- let comments = getCommentsBefore.getCommentsBefore(node, sourceCode)
331
297
  let lastSortingNode =
332
298
  (_a = formattedNodes.at(-1)) == null ? void 0 : _a.at(-1)
333
299
  if (
@@ -341,7 +307,10 @@ let analyzeModule = ({
341
307
  (options.partitionByComment &&
342
308
  isPartitionComment.hasPartitionComment(
343
309
  options.partitionByComment,
344
- comments,
310
+ getCommentsBefore.getCommentsBefore({
311
+ sourceCode,
312
+ node,
313
+ }),
345
314
  ))
346
315
  ) {
347
316
  formattedNodes.push([])
@@ -356,7 +325,10 @@ let analyzeModule = ({
356
325
  getGroupNumber.getGroupNumber(options.groups, sortingNode) ===
357
326
  options.groups.length,
358
327
  getGroupCompareOptions: groupNumber =>
359
- sortModulesUtils.getCompareOptions(options, groupNumber),
328
+ getCustomGroupsCompareOptions.getCustomGroupsCompareOptions(
329
+ options,
330
+ groupNumber,
331
+ ),
360
332
  ignoreEslintDisabledNodes,
361
333
  }),
362
334
  ),
@@ -1,5 +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
4
  let allSelectors = [
4
5
  'enum',
5
6
  'function',
@@ -10,53 +11,16 @@ let allSelectors = [
10
11
  'class',
11
12
  ]
12
13
  let allModifiers = ['async', 'declare', 'decorated', 'default', 'export']
13
- let customGroupSortJsonSchema = {
14
- type: {
15
- enum: ['alphabetical', 'line-length', 'natural', 'unsorted'],
16
- description: 'Custom group sort type.',
17
- type: 'string',
18
- },
19
- order: {
20
- description: 'Custom group sort order.',
21
- enum: ['desc', 'asc'],
22
- type: 'string',
23
- },
24
- }
25
- let customGroupNameJsonSchema = {
26
- groupName: {
27
- description: 'Custom group name.',
28
- type: 'string',
29
- },
30
- }
31
14
  let singleCustomGroupJsonSchema = {
32
- modifiers: {
33
- items: {
34
- enum: allModifiers,
35
- type: 'string',
36
- },
37
- description: 'Modifier filters.',
38
- type: 'array',
39
- },
40
- elementValuePattern: {
41
- description: 'Element value pattern filter for properties.',
42
- type: 'string',
43
- },
44
15
  decoratorNamePattern: {
45
16
  description: 'Decorator name pattern filter.',
46
17
  type: 'string',
47
18
  },
48
- selector: {
49
- description: 'Selector filter.',
50
- enum: allSelectors,
51
- type: 'string',
52
- },
53
- elementNamePattern: {
54
- description: 'Element name pattern filter.',
55
- type: 'string',
56
- },
19
+ modifiers:
20
+ commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
21
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
22
+ elementNamePattern: commonJsonSchemas.elementNamePatternJsonSchema,
57
23
  }
58
24
  exports.allModifiers = allModifiers
59
25
  exports.allSelectors = allSelectors
60
- exports.customGroupNameJsonSchema = customGroupNameJsonSchema
61
- exports.customGroupSortJsonSchema = customGroupSortJsonSchema
62
26
  exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -67,7 +67,10 @@ const sortNamedExports = createEslintRule.createEslintRule({
67
67
  (options.partitionByComment &&
68
68
  isPartitionComment.hasPartitionComment(
69
69
  options.partitionByComment,
70
- getCommentsBefore.getCommentsBefore(specifier, sourceCode),
70
+ getCommentsBefore.getCommentsBefore({
71
+ node: specifier,
72
+ sourceCode,
73
+ }),
71
74
  )) ||
72
75
  (options.partitionByNewLine &&
73
76
  lastSortingNode &&
@@ -76,7 +76,10 @@ const sortNamedImports = createEslintRule.createEslintRule({
76
76
  (options.partitionByComment &&
77
77
  isPartitionComment.hasPartitionComment(
78
78
  options.partitionByComment,
79
- getCommentsBefore.getCommentsBefore(specifier, sourceCode),
79
+ getCommentsBefore.getCommentsBefore({
80
+ node: specifier,
81
+ sourceCode,
82
+ }),
80
83
  )) ||
81
84
  (options.partitionByNewLine &&
82
85
  lastSortingNode &&
@@ -0,0 +1,37 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const matches = require('../utils/matches.js')
4
+ let customGroupMatches = props => {
5
+ if ('anyOf' in props.customGroup) {
6
+ return props.customGroup.anyOf.some(subgroup =>
7
+ customGroupMatches({ ...props, customGroup: subgroup }),
8
+ )
9
+ }
10
+ if (
11
+ props.customGroup.selector &&
12
+ !props.selectors.includes(props.customGroup.selector)
13
+ ) {
14
+ return false
15
+ }
16
+ if (props.customGroup.modifiers) {
17
+ for (let modifier of props.customGroup.modifiers) {
18
+ if (!props.modifiers.includes(modifier)) {
19
+ return false
20
+ }
21
+ }
22
+ }
23
+ if (
24
+ 'elementNamePattern' in props.customGroup &&
25
+ props.customGroup.elementNamePattern
26
+ ) {
27
+ let matchesElementNamePattern = matches.matches(
28
+ props.elementName,
29
+ props.customGroup.elementNamePattern,
30
+ )
31
+ if (!matchesElementNamePattern) {
32
+ return false
33
+ }
34
+ }
35
+ return true
36
+ }
37
+ exports.customGroupMatches = customGroupMatches