eslint-plugin-perfectionist 4.10.1 → 4.11.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.
package/dist/index.d.ts CHANGED
@@ -36,7 +36,10 @@ declare interface PluginConfig {
36
36
  'recommended-natural': Linter.Config
37
37
  'recommended-custom': Linter.Config
38
38
  }
39
- name: string
39
+ meta: {
40
+ version: string
41
+ name: string
42
+ }
40
43
  }
41
44
 
42
45
  export {}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const _package = require('./package.json.js')
2
3
  const sortVariableDeclarations = require('./rules/sort-variable-declarations.js')
3
4
  const sortIntersectionTypes = require('./rules/sort-intersection-types.js')
4
5
  const sortHeritageClauses = require('./rules/sort-heritage-clauses.js')
@@ -19,7 +20,7 @@ const sortModules = require('./rules/sort-modules.js')
19
20
  const sortEnums = require('./rules/sort-enums.js')
20
21
  const sortMaps = require('./rules/sort-maps.js')
21
22
  const sortSets = require('./rules/sort-sets.js')
22
- let name = 'perfectionist'
23
+ let pluginName = 'perfectionist'
23
24
  let plugin = {
24
25
  rules: {
25
26
  'sort-variable-declarations': sortVariableDeclarations,
@@ -43,24 +44,27 @@ let plugin = {
43
44
  'sort-sets': sortSets,
44
45
  'sort-maps': sortMaps,
45
46
  },
46
- name,
47
+ meta: {
48
+ version: _package.version,
49
+ name: _package.name,
50
+ },
47
51
  }
48
52
  let getRules = options =>
49
53
  Object.fromEntries(
50
54
  Object.keys(plugin.rules).map(ruleName => [
51
- `${name}/${ruleName}`,
55
+ `${pluginName}/${ruleName}`,
52
56
  ['error', options],
53
57
  ]),
54
58
  )
55
59
  let createConfig = options => ({
56
60
  plugins: {
57
- [name]: plugin,
61
+ [pluginName]: plugin,
58
62
  },
59
63
  rules: getRules(options),
60
64
  })
61
65
  let createLegacyConfig = options => ({
62
66
  rules: getRules(options),
63
- plugins: [name],
67
+ plugins: [pluginName],
64
68
  })
65
69
  const index = {
66
70
  ...plugin,
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const name = 'eslint-plugin-perfectionist'
4
+ const version = '4.11.0'
5
+ exports.name = name
6
+ exports.version = version
@@ -10,11 +10,11 @@ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compar
10
10
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
11
11
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
12
12
  const types = require('./sort-array-includes/types.js')
13
- const doesCustomGroupMatch = require('./sort-array-includes/does-custom-group-match.js')
14
13
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
15
14
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
16
15
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
17
16
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
17
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
18
18
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
19
19
  const createEslintRule = require('../utils/create-eslint-rule.js')
20
20
  const reportAllErrors = require('../utils/report-all-errors.js')
@@ -46,8 +46,8 @@ let jsonSchema = {
46
46
  properties: {
47
47
  ...commonJsonSchemas.commonJsonSchemas,
48
48
  groupKind: {
49
+ description: '[DEPRECATED] Specifies top-level groups.',
49
50
  enum: ['mixed', 'literals-first', 'spreads-first'],
50
- description: 'Specifies top-level groups.',
51
51
  type: 'string',
52
52
  },
53
53
  customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
@@ -174,6 +174,7 @@ let sortArray = ({ availableMessageIds, elements, context }) => {
174
174
  doesCustomGroupMatch.doesCustomGroupMatch({
175
175
  selectors: [selector],
176
176
  elementName: name,
177
+ modifiers: [],
177
178
  customGroup,
178
179
  })
179
180
  ) {
@@ -9,9 +9,9 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
9
9
  const getOverloadSignatureGroups = require('./sort-classes/get-overload-signature-groups.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
11
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
12
- const doesCustomGroupMatch = require('./sort-classes/does-custom-group-match.js')
13
12
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
14
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
14
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
15
15
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
16
16
  const getNodeDecorators = require('../utils/get-node-decorators.js')
17
17
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -7,8 +7,8 @@ const validateCustomSortConfiguration = require('../utils/validate-custom-sort-c
7
7
  const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
8
8
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
9
9
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
10
- const doesCustomGroupMatch = require('./sort-enums/does-custom-group-match.js')
11
10
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
11
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
12
12
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
13
13
  const types = require('./sort-enums/types.js')
14
14
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -115,6 +115,8 @@ const sortEnums = createEslintRule.createEslintRule({
115
115
  doesCustomGroupMatch.doesCustomGroupMatch({
116
116
  elementValue: sourceCode.getText(member.initializer),
117
117
  elementName: name,
118
+ selectors: [],
119
+ modifiers: [],
118
120
  customGroup,
119
121
  })
120
122
  ) {
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
+ let allSelectors = ['export']
5
+ let allModifiers = ['value', 'type']
6
+ let singleCustomGroupJsonSchema = {
7
+ modifiers:
8
+ commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
9
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
10
+ elementNamePattern: commonJsonSchemas.regexJsonSchema,
11
+ }
12
+ exports.allModifiers = allModifiers
13
+ exports.allSelectors = allSelectors
14
+ exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -1,27 +1,38 @@
1
1
  'use strict'
2
2
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
3
+ const reportErrors = require('../utils/report-errors.js')
4
+ const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
5
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
6
+ const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
3
7
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
8
+ const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
4
9
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
5
10
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
11
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
12
+ const types = require('./sort-exports/types.js')
13
+ const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
6
14
  const createEslintRule = require('../utils/create-eslint-rule.js')
7
15
  const reportAllErrors = require('../utils/report-all-errors.js')
8
16
  const shouldPartition = require('../utils/should-partition.js')
9
17
  const rangeToDiff = require('../utils/range-to-diff.js')
10
- const reportErrors = require('../utils/report-errors.js')
11
18
  const getSettings = require('../utils/get-settings.js')
12
- const sortNodes = require('../utils/sort-nodes.js')
19
+ const useGroups = require('../utils/use-groups.js')
13
20
  const complete = require('../utils/complete.js')
21
+ let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
14
22
  let defaultOptions = {
15
23
  fallbackSort: { type: 'unsorted' },
16
24
  specialCharacters: 'keep',
17
25
  partitionByComment: false,
26
+ newlinesBetween: 'ignore',
18
27
  partitionByNewLine: false,
19
28
  type: 'alphabetical',
20
29
  groupKind: 'mixed',
30
+ customGroups: [],
21
31
  ignoreCase: true,
22
32
  locales: 'en-US',
23
33
  alphabet: '',
24
34
  order: 'asc',
35
+ groups: [],
25
36
  }
26
37
  const sortExports = createEslintRule.createEslintRule({
27
38
  create: context => {
@@ -32,14 +43,54 @@ const sortExports = createEslintRule.createEslintRule({
32
43
  defaultOptions,
33
44
  )
34
45
  validateCustomSortConfiguration.validateCustomSortConfiguration(options)
46
+ validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration({
47
+ modifiers: types.allModifiers,
48
+ selectors: types.allSelectors,
49
+ options,
50
+ })
51
+ validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
52
+ options,
53
+ )
35
54
  let { sourceCode, id } = context
36
55
  let eslintDisabledLines = getEslintDisabledLines.getEslintDisabledLines({
37
56
  ruleName: id,
38
57
  sourceCode,
39
58
  })
40
- let parts = [[]]
59
+ let formattedMembers = [[]]
41
60
  let registerNode = node => {
42
61
  var _a
62
+ let { defineGroup, getGroup } = useGroups.useGroups(options)
63
+ let selector = 'export'
64
+ let modifiers = []
65
+ if (node.exportKind === 'value') {
66
+ modifiers.push('value')
67
+ } else {
68
+ modifiers.push('type')
69
+ }
70
+ let predefinedGroups = generatePredefinedGroups.generatePredefinedGroups({
71
+ cache: cachedGroupsByModifiersAndSelectors,
72
+ selectors: [selector],
73
+ modifiers,
74
+ })
75
+ for (let predefinedGroup of predefinedGroups) {
76
+ defineGroup(predefinedGroup)
77
+ }
78
+ let name = node.source.value
79
+ for (let customGroup of options.customGroups) {
80
+ if (
81
+ doesCustomGroupMatch.doesCustomGroupMatch({
82
+ selectors: [selector],
83
+ elementName: name,
84
+ customGroup,
85
+ modifiers,
86
+ })
87
+ ) {
88
+ defineGroup(customGroup.groupName, true)
89
+ if (getGroup() === customGroup.groupName) {
90
+ break
91
+ }
92
+ }
93
+ }
43
94
  let sortingNode = {
44
95
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
45
96
  node,
@@ -48,10 +99,11 @@ const sortExports = createEslintRule.createEslintRule({
48
99
  groupKind: node.exportKind === 'value' ? 'value' : 'type',
49
100
  size: rangeToDiff.rangeToDiff(node, sourceCode),
50
101
  addSafetySemicolonWhenInline: true,
51
- name: node.source.value,
102
+ group: getGroup(),
103
+ name,
52
104
  node,
53
105
  }
54
- let lastNode = (_a = parts.at(-1)) == null ? void 0 : _a.at(-1)
106
+ let lastNode = (_a = formattedMembers.at(-1)) == null ? void 0 : _a.at(-1)
55
107
  if (
56
108
  shouldPartition.shouldPartition({
57
109
  lastSortingNode: lastNode,
@@ -60,9 +112,9 @@ const sortExports = createEslintRule.createEslintRule({
60
112
  options,
61
113
  })
62
114
  ) {
63
- parts.push([])
115
+ formattedMembers.push([])
64
116
  }
65
- parts.at(-1).push(sortingNode)
117
+ formattedMembers.at(-1).push(sortingNode)
66
118
  }
67
119
  return {
68
120
  'Program:exit': () => {
@@ -74,7 +126,7 @@ const sortExports = createEslintRule.createEslintRule({
74
126
  } else {
75
127
  groupKindOrder = ['any']
76
128
  }
77
- for (let nodes of parts) {
129
+ for (let nodes of formattedMembers) {
78
130
  let filteredGroupKindNodes = groupKindOrder.map(groupKind =>
79
131
  nodes.filter(
80
132
  currentNode =>
@@ -83,14 +135,21 @@ const sortExports = createEslintRule.createEslintRule({
83
135
  )
84
136
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
85
137
  filteredGroupKindNodes.flatMap(groupedNodes =>
86
- sortNodes.sortNodes({
138
+ sortNodesByGroups.sortNodesByGroups({
139
+ getOptionsByGroupNumber:
140
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
141
+ options,
142
+ ),
87
143
  ignoreEslintDisabledNodes,
144
+ groups: options.groups,
88
145
  nodes: groupedNodes,
89
- options,
90
146
  }),
91
147
  )
92
148
  reportAllErrors.reportAllErrors({
93
149
  availableMessageIds: {
150
+ missedSpacingBetweenMembers: 'missedSpacingBetweenExports',
151
+ extraSpacingBetweenMembers: 'extraSpacingBetweenExports',
152
+ unexpectedGroupOrder: 'unexpectedExportsGroupOrder',
94
153
  unexpectedOrder: 'unexpectedExportsOrder',
95
154
  },
96
155
  sortNodesExcludingEslintDisabled,
@@ -110,30 +169,40 @@ const sortExports = createEslintRule.createEslintRule({
110
169
  }
111
170
  },
112
171
  meta: {
113
- schema: [
114
- {
172
+ schema: {
173
+ items: {
115
174
  properties: {
116
175
  ...commonJsonSchemas.commonJsonSchemas,
117
176
  groupKind: {
177
+ description: '[DEPRECATED] Specifies top-level groups.',
118
178
  enum: ['mixed', 'values-first', 'types-first'],
119
- description: 'Specifies top-level groups.',
120
179
  type: 'string',
121
180
  },
181
+ customGroups: commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
182
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
183
+ }),
122
184
  partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
123
185
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
186
+ newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
187
+ groups: commonJsonSchemas.groupsJsonSchema,
124
188
  },
125
189
  additionalProperties: false,
126
190
  type: 'object',
127
191
  },
128
- ],
192
+ uniqueItems: true,
193
+ type: 'array',
194
+ },
195
+ messages: {
196
+ missedSpacingBetweenExports: reportErrors.MISSED_SPACING_ERROR,
197
+ extraSpacingBetweenExports: reportErrors.EXTRA_SPACING_ERROR,
198
+ unexpectedExportsGroupOrder: reportErrors.GROUP_ORDER_ERROR,
199
+ unexpectedExportsOrder: reportErrors.ORDER_ERROR,
200
+ },
129
201
  docs: {
130
202
  url: 'https://perfectionist.dev/rules/sort-exports',
131
203
  description: 'Enforce sorted exports.',
132
204
  recommended: true,
133
205
  },
134
- messages: {
135
- unexpectedExportsOrder: reportErrors.ORDER_ERROR,
136
- },
137
206
  type: 'suggestion',
138
207
  fixable: 'code',
139
208
  },
@@ -36,11 +36,11 @@ let doesCustomGroupMatch = props => {
36
36
  'elementValuePattern' in props.customGroup &&
37
37
  props.customGroup.elementValuePattern
38
38
  ) {
39
- let matchesElementValuePattern = matches.matches(
39
+ let matchesElementNamePattern = matches.matches(
40
40
  props.elementValue ?? '',
41
41
  props.customGroup.elementValuePattern,
42
42
  )
43
- if (!matchesElementValuePattern) {
43
+ if (!matchesElementNamePattern) {
44
44
  return false
45
45
  }
46
46
  }
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const commonJsonSchemas = require('../../utils/common-json-schemas.js')
4
+ let allSelectors = ['multiline', 'prop', 'shorthand']
5
+ let allModifiers = ['shorthand', 'multiline']
6
+ let singleCustomGroupJsonSchema = {
7
+ modifiers:
8
+ commonJsonSchemas.buildCustomGroupModifiersJsonSchema(allModifiers),
9
+ selector: commonJsonSchemas.buildCustomGroupSelectorJsonSchema(allSelectors),
10
+ elementValuePattern: commonJsonSchemas.regexJsonSchema,
11
+ elementNamePattern: commonJsonSchemas.regexJsonSchema,
12
+ }
13
+ exports.allModifiers = allModifiers
14
+ exports.allSelectors = allSelectors
15
+ exports.singleCustomGroupJsonSchema = singleCustomGroupJsonSchema
@@ -1,13 +1,17 @@
1
1
  'use strict'
2
- const types = require('@typescript-eslint/types')
2
+ const types$1 = require('@typescript-eslint/types')
3
3
  const commonJsonSchemas = require('../utils/common-json-schemas.js')
4
4
  const reportErrors = require('../utils/report-errors.js')
5
5
  const validateNewlinesAndPartitionConfiguration = require('../utils/validate-newlines-and-partition-configuration.js')
6
+ const getCustomGroupsCompareOptions = require('../utils/get-custom-groups-compare-options.js')
7
+ const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
6
8
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
7
- const validateGroupsConfiguration = require('../utils/validate-groups-configuration.js')
8
9
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
10
+ const doesCustomGroupMatch = require('./sort-jsx-props/does-custom-group-match.js')
11
+ const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
9
12
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
10
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
14
+ const types = require('./sort-jsx-props/types.js')
11
15
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
12
16
  const createEslintRule = require('../utils/create-eslint-rule.js')
13
17
  const reportAllErrors = require('../utils/report-all-errors.js')
@@ -18,6 +22,7 @@ const isSortable = require('../utils/is-sortable.js')
18
22
  const useGroups = require('../utils/use-groups.js')
19
23
  const complete = require('../utils/complete.js')
20
24
  const matches = require('../utils/matches.js')
25
+ let cachedGroupsByModifiersAndSelectors = /* @__PURE__ */ new Map()
21
26
  let defaultOptions = {
22
27
  fallbackSort: { type: 'unsorted' },
23
28
  specialCharacters: 'keep',
@@ -47,7 +52,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
47
52
  .filter(
48
53
  attribute =>
49
54
  attribute.type !==
50
- types.TSESTree.AST_NODE_TYPES.JSXSpreadAttribute,
55
+ types$1.TSESTree.AST_NODE_TYPES.JSXSpreadAttribute,
51
56
  )
52
57
  .map(attribute => getNodeName({ attribute })),
53
58
  contextOptions: context.options,
@@ -72,11 +77,13 @@ const sortJsxProps = createEslintRule.createEslintRule({
72
77
  defaultOptions,
73
78
  )
74
79
  validateCustomSortConfiguration.validateCustomSortConfiguration(options)
75
- validateGroupsConfiguration.validateGroupsConfiguration({
76
- allowedPredefinedGroups: ['multiline', 'shorthand', 'unknown'],
77
- allowedCustomGroups: Object.keys(options.customGroups),
78
- options,
79
- })
80
+ validateGeneratedGroupsConfiguration.validateGeneratedGroupsConfiguration(
81
+ {
82
+ selectors: types.allSelectors,
83
+ modifiers: types.allModifiers,
84
+ options,
85
+ },
86
+ )
80
87
  validateNewlinesAndPartitionConfiguration.validateNewlinesAndPartitionConfiguration(
81
88
  options,
82
89
  )
@@ -98,7 +105,8 @@ const sortJsxProps = createEslintRule.createEslintRule({
98
105
  (accumulator, attribute) => {
99
106
  var _a
100
107
  if (
101
- attribute.type === types.TSESTree.AST_NODE_TYPES.JSXSpreadAttribute
108
+ attribute.type ===
109
+ types$1.TSESTree.AST_NODE_TYPES.JSXSpreadAttribute
102
110
  ) {
103
111
  accumulator.push([])
104
112
  return accumulator
@@ -106,11 +114,49 @@ const sortJsxProps = createEslintRule.createEslintRule({
106
114
  let name = getNodeName({ attribute })
107
115
  let { setCustomGroups, defineGroup, getGroup } =
108
116
  useGroups.useGroups(options)
109
- setCustomGroups(options.customGroups, name)
117
+ let selectors = []
118
+ let modifiers = []
110
119
  if (attribute.value === null) {
111
- defineGroup('shorthand')
112
- } else if (attribute.loc.start.line !== attribute.loc.end.line) {
113
- defineGroup('multiline')
120
+ selectors.push('shorthand')
121
+ modifiers.push('shorthand')
122
+ }
123
+ if (attribute.loc.start.line !== attribute.loc.end.line) {
124
+ selectors.push('multiline')
125
+ modifiers.push('multiline')
126
+ }
127
+ selectors.push('prop')
128
+ let predefinedGroups =
129
+ generatePredefinedGroups.generatePredefinedGroups({
130
+ cache: cachedGroupsByModifiersAndSelectors,
131
+ selectors,
132
+ modifiers,
133
+ })
134
+ for (let predefinedGroup of predefinedGroups) {
135
+ defineGroup(predefinedGroup)
136
+ }
137
+ if (Array.isArray(options.customGroups)) {
138
+ for (let customGroup of options.customGroups) {
139
+ if (
140
+ doesCustomGroupMatch.doesCustomGroupMatch({
141
+ elementValue: attribute.value
142
+ ? sourceCode.getText(attribute.value)
143
+ : null,
144
+ elementName: name,
145
+ customGroup,
146
+ selectors,
147
+ modifiers,
148
+ })
149
+ ) {
150
+ defineGroup(customGroup.groupName, true)
151
+ if (getGroup() === customGroup.groupName) {
152
+ break
153
+ }
154
+ }
155
+ }
156
+ } else {
157
+ setCustomGroups(options.customGroups, name, {
158
+ override: true,
159
+ })
114
160
  }
115
161
  let sortingNode = {
116
162
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
@@ -142,7 +188,10 @@ const sortJsxProps = createEslintRule.createEslintRule({
142
188
  for (let nodes of formattedMembers) {
143
189
  let sortNodesExcludingEslintDisabled = ignoreEslintDisabledNodes =>
144
190
  sortNodesByGroups.sortNodesByGroups({
145
- getOptionsByGroupNumber: () => ({ options }),
191
+ getOptionsByGroupNumber:
192
+ getCustomGroupsCompareOptions.buildGetCustomGroupOverriddenOptionsFunction(
193
+ options,
194
+ ),
146
195
  ignoreEslintDisabledNodes,
147
196
  groups: options.groups,
148
197
  nodes,
@@ -168,6 +217,14 @@ const sortJsxProps = createEslintRule.createEslintRule({
168
217
  items: {
169
218
  properties: {
170
219
  ...commonJsonSchemas.commonJsonSchemas,
220
+ customGroups: {
221
+ oneOf: [
222
+ commonJsonSchemas.customGroupsJsonSchema,
223
+ commonJsonSchemas.buildCustomGroupsArrayJsonSchema({
224
+ singleCustomGroupJsonSchema: types.singleCustomGroupJsonSchema,
225
+ }),
226
+ ],
227
+ },
171
228
  useConfigurationIf:
172
229
  commonJsonSchemas.buildUseConfigurationIfJsonSchema({
173
230
  additionalProperties: {
@@ -176,7 +233,6 @@ const sortJsxProps = createEslintRule.createEslintRule({
176
233
  }),
177
234
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
178
235
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
179
- customGroups: commonJsonSchemas.customGroupsJsonSchema,
180
236
  ignorePattern: commonJsonSchemas.regexJsonSchema,
181
237
  groups: commonJsonSchemas.groupsJsonSchema,
182
238
  },
@@ -204,7 +260,7 @@ const sortJsxProps = createEslintRule.createEslintRule({
204
260
  name: 'sort-jsx-props',
205
261
  })
206
262
  let getNodeName = ({ attribute }) =>
207
- attribute.name.type === types.TSESTree.AST_NODE_TYPES.JSXNamespacedName
263
+ attribute.name.type === types$1.TSESTree.AST_NODE_TYPES.JSXNamespacedName
208
264
  ? `${attribute.name.namespace.name}:${attribute.name.name.name}`
209
265
  : attribute.name.name
210
266
  module.exports = sortJsxProps
@@ -6,8 +6,8 @@ const validateGeneratedGroupsConfiguration = require('../utils/validate-generate
6
6
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
7
7
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
8
8
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
9
- const doesCustomGroupMatch = require('./sort-maps/does-custom-group-match.js')
10
9
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
10
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
11
11
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
12
12
  const types = require('./sort-maps/types.js')
13
13
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -103,6 +103,8 @@ const sortMaps = createEslintRule.createEslintRule({
103
103
  if (
104
104
  doesCustomGroupMatch.doesCustomGroupMatch({
105
105
  elementName: name,
106
+ selectors: [],
107
+ modifiers: [],
106
108
  customGroup,
107
109
  })
108
110
  ) {
@@ -9,9 +9,9 @@ const types = require('./sort-modules/types.js')
9
9
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
10
10
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
11
11
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
12
- const doesCustomGroupMatch = require('./sort-modules/does-custom-group-match.js')
13
12
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
14
13
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
14
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
15
15
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
16
16
  const getNodeDecorators = require('../utils/get-node-decorators.js')
17
17
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -10,12 +10,12 @@ const types = require('./sort-object-types/types.js')
10
10
  const validateGeneratedGroupsConfiguration = require('../utils/validate-generated-groups-configuration.js')
11
11
  const getCustomGroupsCompareOptions = require('./sort-object-types/get-custom-groups-compare-options.js')
12
12
  const validateCustomSortConfiguration = require('../utils/validate-custom-sort-configuration.js')
13
- const doesCustomGroupMatch = require('./sort-object-types/does-custom-group-match.js')
14
13
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
15
14
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
16
15
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
17
16
  const isMemberOptional = require('./sort-object-types/is-member-optional.js')
18
17
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
18
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
19
19
  const isNodeFunctionType = require('../utils/is-node-function-type.js')
20
20
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
21
21
  const createEslintRule = require('../utils/create-eslint-rule.js')
@@ -63,16 +63,16 @@ let jsonSchema = {
63
63
  }),
64
64
  ],
65
65
  },
66
+ groupKind: {
67
+ description: '[DEPRECATED] Specifies top-level groups.',
68
+ enum: ['mixed', 'required-first', 'optional-first'],
69
+ type: 'string',
70
+ },
66
71
  useConfigurationIf: commonJsonSchemas.buildUseConfigurationIfJsonSchema({
67
72
  additionalProperties: {
68
73
  declarationMatchesPattern: commonJsonSchemas.regexJsonSchema,
69
74
  },
70
75
  }),
71
- groupKind: {
72
- enum: ['mixed', 'required-first', 'optional-first'],
73
- description: 'Specifies top-level groups.',
74
- type: 'string',
75
- },
76
76
  partitionByComment: commonJsonSchemas.partitionByCommentJsonSchema,
77
77
  partitionByNewLine: commonJsonSchemas.partitionByNewLineJsonSchema,
78
78
  newlinesBetween: commonJsonSchemas.newlinesBetweenJsonSchema,
@@ -11,9 +11,9 @@ const getFirstNodeParentWithType = require('./sort-objects/get-first-node-parent
11
11
  const getMatchingContextOptions = require('../utils/get-matching-context-options.js')
12
12
  const generatePredefinedGroups = require('../utils/generate-predefined-groups.js')
13
13
  const sortNodesByDependencies = require('../utils/sort-nodes-by-dependencies.js')
14
- const doesCustomGroupMatch = require('./sort-objects/does-custom-group-match.js')
15
14
  const getEslintDisabledLines = require('../utils/get-eslint-disabled-lines.js')
16
15
  const isNodeEslintDisabled = require('../utils/is-node-eslint-disabled.js')
16
+ const doesCustomGroupMatch = require('../utils/does-custom-group-match.js')
17
17
  const sortNodesByGroups = require('../utils/sort-nodes-by-groups.js')
18
18
  const createEslintRule = require('../utils/create-eslint-rule.js')
19
19
  const reportAllErrors = require('../utils/report-all-errors.js')
@@ -247,7 +247,7 @@ const sortObjects = createEslintRule.createEslintRule({
247
247
  let selectors = []
248
248
  let modifiers = []
249
249
  if (property.value.type === 'AssignmentPattern') {
250
- dependencies = extractDependencies(property.value)
250
+ dependencies = extractDependencies(property.value.right)
251
251
  }
252
252
  if (
253
253
  property.value.type === 'ArrowFunctionExpression' ||
@@ -297,6 +297,10 @@ const sortObjects = createEslintRule.createEslintRule({
297
297
  override: true,
298
298
  })
299
299
  }
300
+ let dependencyName = name
301
+ if (isDestructuredObject && property.value.type === 'Identifier') {
302
+ dependencyName = property.value.name
303
+ }
300
304
  let sortingNode = {
301
305
  isEslintDisabled: isNodeEslintDisabled.isNodeEslintDisabled(
302
306
  property,
@@ -304,6 +308,7 @@ const sortObjects = createEslintRule.createEslintRule({
304
308
  ),
305
309
  size: rangeToDiff.rangeToDiff(property, sourceCode),
306
310
  group: getGroup(),
311
+ dependencyName,
307
312
  node: property,
308
313
  dependencies,
309
314
  name,
@@ -416,7 +421,8 @@ const sortObjects = createEslintRule.createEslintRule({
416
421
  },
417
422
  }),
418
423
  destructureOnly: {
419
- description: 'Controls whether to sort only destructured objects.',
424
+ description:
425
+ '[DEPRECATED] Controls whether to sort only destructured objects.',
420
426
  type: 'boolean',
421
427
  },
422
428
  objectDeclarations: {
@@ -116,6 +116,9 @@ let singleRegexJsonSchema = {
116
116
  },
117
117
  },
118
118
  additionalProperties: false,
119
+ // https://github.com/azat-io/eslint-plugin-perfectionist/pull/490#issuecomment-2720969705
120
+ // Uncomment the code below in the next major version (v5)
121
+ // To uncomment: required: ['pattern'],
119
122
  type: 'object',
120
123
  },
121
124
  {
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ let computeNodesInCircularDependencies = elements => {
4
+ let elementsInCycles = /* @__PURE__ */ new Set()
5
+ let visitingElements = /* @__PURE__ */ new Set()
6
+ let visitedElements = /* @__PURE__ */ new Set()
7
+ let depthFirstSearch = (element, path) => {
8
+ if (visitedElements.has(element)) {
9
+ return
10
+ }
11
+ if (visitingElements.has(element)) {
12
+ let cycleStartIndex = path.indexOf(element)
13
+ if (cycleStartIndex !== -1) {
14
+ for (let cycleElements of path.slice(cycleStartIndex)) {
15
+ elementsInCycles.add(cycleElements)
16
+ }
17
+ }
18
+ return
19
+ }
20
+ visitingElements.add(element)
21
+ path.push(element)
22
+ for (let dependency of element.dependencies) {
23
+ let dependencyElement = elements.find(
24
+ currentElement =>
25
+ currentElement.dependencyName === dependency ||
26
+ currentElement.name === dependency,
27
+ )
28
+ if (dependencyElement) {
29
+ depthFirstSearch(dependencyElement, [...path])
30
+ }
31
+ }
32
+ visitingElements.delete(element)
33
+ visitedElements.add(element)
34
+ }
35
+ for (let element of elements) {
36
+ if (!visitedElements.has(element)) {
37
+ depthFirstSearch(element, [])
38
+ }
39
+ }
40
+ return elementsInCycles
41
+ }
42
+ exports.computeNodesInCircularDependencies = computeNodesInCircularDependencies
@@ -0,0 +1,74 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const matches = require('./matches.js')
4
+ let doesCustomGroupMatch = props => {
5
+ if ('anyOf' in props.customGroup) {
6
+ return props.customGroup.anyOf.some(subgroup =>
7
+ doesSingleCustomGroupMatch({
8
+ ...props,
9
+ customGroup: subgroup,
10
+ }),
11
+ )
12
+ }
13
+ return doesSingleCustomGroupMatch({
14
+ ...props,
15
+ customGroup: props.customGroup,
16
+ })
17
+ }
18
+ let doesSingleCustomGroupMatch = ({
19
+ elementValue,
20
+ customGroup,
21
+ elementName,
22
+ decorators,
23
+ selectors,
24
+ modifiers,
25
+ }) => {
26
+ if (
27
+ customGroup.selector &&
28
+ !(selectors == null ? void 0 : selectors.includes(customGroup.selector))
29
+ ) {
30
+ return false
31
+ }
32
+ if (customGroup.modifiers) {
33
+ for (let modifier of customGroup.modifiers) {
34
+ if (!(modifiers == null ? void 0 : modifiers.includes(modifier))) {
35
+ return false
36
+ }
37
+ }
38
+ }
39
+ if ('elementNamePattern' in customGroup && customGroup.elementNamePattern) {
40
+ let matchesElementNamePattern = matches.matches(
41
+ elementName,
42
+ customGroup.elementNamePattern,
43
+ )
44
+ if (!matchesElementNamePattern) {
45
+ return false
46
+ }
47
+ }
48
+ if ('elementValuePattern' in customGroup && customGroup.elementValuePattern) {
49
+ let matchesElementValuePattern = matches.matches(
50
+ elementValue ?? '',
51
+ customGroup.elementValuePattern,
52
+ )
53
+ if (!matchesElementValuePattern) {
54
+ return false
55
+ }
56
+ }
57
+ if (
58
+ 'decoratorNamePattern' in customGroup &&
59
+ customGroup.decoratorNamePattern
60
+ ) {
61
+ let decoratorPattern = customGroup.decoratorNamePattern
62
+ let matchesDecoratorNamePattern =
63
+ decorators == null
64
+ ? void 0
65
+ : decorators.some(decorator =>
66
+ matches.matches(decorator, decoratorPattern),
67
+ )
68
+ if (!matchesDecoratorNamePattern) {
69
+ return false
70
+ }
71
+ }
72
+ return true
73
+ }
74
+ exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -45,17 +45,27 @@ let getNewlinesBetweenOption = ({ nextSortingNode, sortingNode, options }) => {
45
45
  return groupBetween.newlinesBetween
46
46
  }
47
47
  } else {
48
- if (globalNewlinesBetweenOption === 'always') {
48
+ let relevantGroups = options.groups.slice(
49
+ nodeGroupNumber,
50
+ nextNodeGroupNumber + 1,
51
+ )
52
+ let groupsWithAllNewlinesBetween = buildGroupsWithAllNewlinesBetween(
53
+ relevantGroups,
54
+ globalNewlinesBetweenOption,
55
+ )
56
+ let newlinesBetweenOptions = new Set(
57
+ groupsWithAllNewlinesBetween
58
+ .filter(isNewlinesBetweenOption.isNewlinesBetweenOption)
59
+ .map(group => group.newlinesBetween),
60
+ )
61
+ if (newlinesBetweenOptions.has('always')) {
49
62
  return 'always'
50
63
  }
51
- for (let i = nodeGroupNumber + 2; i < nextNodeGroupNumber; i++) {
52
- let groupBetween = options.groups[i]
53
- if (
54
- isNewlinesBetweenOption.isNewlinesBetweenOption(groupBetween) &&
55
- groupBetween.newlinesBetween !== 'never'
56
- ) {
57
- return groupBetween.newlinesBetween
58
- }
64
+ if (newlinesBetweenOptions.has('ignore')) {
65
+ return 'ignore'
66
+ }
67
+ if (newlinesBetweenOptions.has('never')) {
68
+ return 'never'
59
69
  }
60
70
  }
61
71
  }
@@ -74,4 +84,26 @@ let getGlobalNewlinesBetweenOption = ({
74
84
  }
75
85
  return nodeGroupNumber === nextNodeGroupNumber ? 'never' : 'always'
76
86
  }
87
+ let buildGroupsWithAllNewlinesBetween = (
88
+ groups,
89
+ globalNewlinesBetweenOption,
90
+ ) => {
91
+ let returnValue = []
92
+ for (let i = 0; i < groups.length; i++) {
93
+ let group = groups[i]
94
+ if (isNewlinesBetweenOption.isNewlinesBetweenOption(group)) {
95
+ returnValue.push(group)
96
+ } else {
97
+ let previousGroup = groups[i - 1]
98
+ if (
99
+ previousGroup &&
100
+ !isNewlinesBetweenOption.isNewlinesBetweenOption(previousGroup)
101
+ ) {
102
+ returnValue.push({ newlinesBetween: globalNewlinesBetweenOption })
103
+ }
104
+ returnValue.push(group)
105
+ }
106
+ }
107
+ return returnValue
108
+ }
77
109
  exports.getNewlinesBetweenOption = getNewlinesBetweenOption
@@ -7,6 +7,11 @@ let matches = (value, regexOption) => {
7
7
  if (typeof regexOption === 'string') {
8
8
  return new RegExp(regexOption).test(value)
9
9
  }
10
+ if ('source' in regexOption) {
11
+ throw new Error(
12
+ 'Invalid configuration: please enter your RegExp expressions as strings.\nFor example, write ".*foo" instead of /.*foo/',
13
+ )
14
+ }
10
15
  return new RegExp(regexOption.pattern, regexOption.flags).test(value)
11
16
  }
12
17
  exports.matches = matches
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const sortNodesByDependencies = require('./sort-nodes-by-dependencies.js')
3
+ const computeNodesInCircularDependencies = require('./compute-nodes-in-circular-dependencies.js')
4
4
  const createNodeIndexMap = require('./create-node-index-map.js')
5
5
  const getNewlinesErrors = require('./get-newlines-errors.js')
6
6
  const getGroupNumber = require('./get-group-number.js')
@@ -20,6 +20,12 @@ let reportAllErrors = ({
20
20
  let sortedNodesExcludingEslintDisabled =
21
21
  sortNodesExcludingEslintDisabled(true)
22
22
  let nodeIndexMap = createNodeIndexMap.createNodeIndexMap(sortedNodes)
23
+ let nodesInCircularDependencies =
24
+ availableMessageIds.unexpectedDependencyOrder
25
+ ? computeNodesInCircularDependencies.computeNodesInCircularDependencies(
26
+ nodes,
27
+ )
28
+ : /* @__PURE__ */ new Set()
23
29
  pairwise.pairwise(nodes, (left, right) => {
24
30
  let leftNumber = options.groups
25
31
  ? getGroupNumber.getGroupNumber(options.groups, left)
@@ -34,13 +40,17 @@ let reportAllErrors = ({
34
40
  let messageIds = []
35
41
  let firstUnorderedNodeDependentOnRight
36
42
  if (availableMessageIds.unexpectedDependencyOrder) {
37
- firstUnorderedNodeDependentOnRight =
38
- sortNodesByDependencies.getFirstUnorderedNodeDependentOn(right, nodes)
43
+ firstUnorderedNodeDependentOnRight = getFirstUnorderedNodeDependentOn({
44
+ nodes,
45
+ node: right,
46
+ nodesInCircularDependencies,
47
+ })
39
48
  }
40
49
  if (
41
50
  firstUnorderedNodeDependentOnRight ||
42
51
  leftIndex > rightIndex ||
43
- leftIndex >= indexOfRightExcludingEslintDisabled
52
+ (left.isEslintDisabled &&
53
+ leftIndex >= indexOfRightExcludingEslintDisabled)
44
54
  ) {
45
55
  if (firstUnorderedNodeDependentOnRight) {
46
56
  messageIds.push(availableMessageIds.unexpectedDependencyOrder)
@@ -93,4 +103,24 @@ let reportAllErrors = ({
93
103
  })
94
104
  })
95
105
  }
106
+ let getFirstUnorderedNodeDependentOn = ({
107
+ nodesInCircularDependencies,
108
+ nodes,
109
+ node,
110
+ }) => {
111
+ let nodesDependentOnNode = nodes.filter(
112
+ currentlyOrderedNode =>
113
+ !nodesInCircularDependencies.has(currentlyOrderedNode) &&
114
+ currentlyOrderedNode.dependencies.includes(
115
+ node.dependencyName ?? node.name,
116
+ ),
117
+ )
118
+ return nodesDependentOnNode.find(firstNodeDependentOnNode => {
119
+ let currentIndexOfNode = nodes.indexOf(node)
120
+ let currentIndexOfFirstNodeDependentOnNode = nodes.indexOf(
121
+ firstNodeDependentOnNode,
122
+ )
123
+ return currentIndexOfFirstNodeDependentOnNode < currentIndexOfNode
124
+ })
125
+ }
96
126
  exports.reportAllErrors = reportAllErrors
@@ -1,20 +1,20 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
+ const computeNodesInCircularDependencies = require('./compute-nodes-in-circular-dependencies.js')
3
4
  let sortNodesByDependencies = (nodes, extraOptions) => {
5
+ let nodesInCircularDependencies =
6
+ computeNodesInCircularDependencies.computeNodesInCircularDependencies(nodes)
4
7
  let result = []
5
8
  let visitedNodes = /* @__PURE__ */ new Set()
6
- let inProcessNodes = /* @__PURE__ */ new Set()
7
9
  let visitNode = sortingNode => {
8
10
  if (visitedNodes.has(sortingNode)) {
9
11
  return
10
12
  }
11
- if (inProcessNodes.has(sortingNode)) {
12
- return
13
- }
14
- inProcessNodes.add(sortingNode)
15
- let dependentNodes = nodes.filter(({ dependencyName, name }) =>
16
- sortingNode.dependencies.includes(dependencyName ?? name),
17
- )
13
+ let dependentNodes = nodes
14
+ .filter(dependentNode => !nodesInCircularDependencies.has(dependentNode))
15
+ .filter(({ dependencyName, name }) =>
16
+ sortingNode.dependencies.includes(dependencyName ?? name),
17
+ )
18
18
  for (let dependentNode of dependentNodes) {
19
19
  if (
20
20
  !extraOptions.ignoreEslintDisabledNodes ||
@@ -24,7 +24,6 @@ let sortNodesByDependencies = (nodes, extraOptions) => {
24
24
  }
25
25
  }
26
26
  visitedNodes.add(sortingNode)
27
- inProcessNodes.delete(sortingNode)
28
27
  result.push(sortingNode)
29
28
  }
30
29
  for (let node of nodes) {
@@ -32,20 +31,4 @@ let sortNodesByDependencies = (nodes, extraOptions) => {
32
31
  }
33
32
  return result
34
33
  }
35
- let getFirstUnorderedNodeDependentOn = (node, currentlyOrderedNodes) => {
36
- let nodesDependentOnNode = currentlyOrderedNodes.filter(
37
- currentlyOrderedNode =>
38
- currentlyOrderedNode.dependencies.includes(
39
- node.dependencyName ?? node.name,
40
- ),
41
- )
42
- return nodesDependentOnNode.find(firstNodeDependentOnNode => {
43
- let currentIndexOfNode = currentlyOrderedNodes.indexOf(node)
44
- let currentIndexOfFirstNodeDependentOnNode = currentlyOrderedNodes.indexOf(
45
- firstNodeDependentOnNode,
46
- )
47
- return currentIndexOfFirstNodeDependentOnNode < currentIndexOfNode
48
- })
49
- }
50
- exports.getFirstUnorderedNodeDependentOn = getFirstUnorderedNodeDependentOn
51
34
  exports.sortNodesByDependencies = sortNodesByDependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-perfectionist",
3
- "version": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -27,8 +27,8 @@
27
27
  "./dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@typescript-eslint/types": "^8.26.0",
31
- "@typescript-eslint/utils": "^8.26.0",
30
+ "@typescript-eslint/types": "^8.29.0",
31
+ "@typescript-eslint/utils": "^8.29.0",
32
32
  "natural-orderby": "^5.0.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -1,30 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../../utils/matches.js')
4
- let doesCustomGroupMatch = props => {
5
- if ('anyOf' in props.customGroup) {
6
- return props.customGroup.anyOf.some(subgroup =>
7
- doesCustomGroupMatch({ ...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 (
17
- 'elementNamePattern' in props.customGroup &&
18
- props.customGroup.elementNamePattern
19
- ) {
20
- let matchesElementNamePattern = matches.matches(
21
- props.elementName,
22
- props.customGroup.elementNamePattern,
23
- )
24
- if (!matchesElementNamePattern) {
25
- return false
26
- }
27
- }
28
- return true
29
- }
30
- exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,61 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../../utils/matches.js')
4
- let doesCustomGroupMatch = props => {
5
- if ('anyOf' in props.customGroup) {
6
- return props.customGroup.anyOf.some(subgroup =>
7
- doesCustomGroupMatch({ ...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
- if (
36
- 'elementValuePattern' in props.customGroup &&
37
- props.customGroup.elementValuePattern
38
- ) {
39
- let matchesElementValuePattern = matches.matches(
40
- props.elementValue ?? '',
41
- props.customGroup.elementValuePattern,
42
- )
43
- if (!matchesElementValuePattern) {
44
- return false
45
- }
46
- }
47
- if (
48
- 'decoratorNamePattern' in props.customGroup &&
49
- props.customGroup.decoratorNamePattern
50
- ) {
51
- let decoratorPattern = props.customGroup.decoratorNamePattern
52
- let matchesDecoratorNamePattern = props.decorators.some(decorator =>
53
- matches.matches(decorator, decoratorPattern),
54
- )
55
- if (!matchesDecoratorNamePattern) {
56
- return false
57
- }
58
- }
59
- return true
60
- }
61
- exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,36 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../../utils/matches.js')
4
- let doesCustomGroupMatch = props => {
5
- if ('anyOf' in props.customGroup) {
6
- return props.customGroup.anyOf.some(subgroup =>
7
- doesCustomGroupMatch({ ...props, customGroup: subgroup }),
8
- )
9
- }
10
- if (
11
- 'elementNamePattern' in props.customGroup &&
12
- props.customGroup.elementNamePattern
13
- ) {
14
- let matchesElementNamePattern = matches.matches(
15
- props.elementName,
16
- props.customGroup.elementNamePattern,
17
- )
18
- if (!matchesElementNamePattern) {
19
- return false
20
- }
21
- }
22
- if (
23
- 'elementValuePattern' in props.customGroup &&
24
- props.customGroup.elementValuePattern
25
- ) {
26
- let matchesElementValuePattern = matches.matches(
27
- props.elementValue,
28
- props.customGroup.elementValuePattern,
29
- )
30
- if (!matchesElementValuePattern) {
31
- return false
32
- }
33
- }
34
- return true
35
- }
36
- exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,24 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../../utils/matches.js')
4
- let doesCustomGroupMatch = props => {
5
- if ('anyOf' in props.customGroup) {
6
- return props.customGroup.anyOf.some(subgroup =>
7
- doesCustomGroupMatch({ ...props, customGroup: subgroup }),
8
- )
9
- }
10
- if (
11
- 'elementNamePattern' in props.customGroup &&
12
- props.customGroup.elementNamePattern
13
- ) {
14
- let matchesElementNamePattern = matches.matches(
15
- props.elementName,
16
- props.customGroup.elementNamePattern,
17
- )
18
- if (!matchesElementNamePattern) {
19
- return false
20
- }
21
- }
22
- return true
23
- }
24
- exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,49 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../../utils/matches.js')
4
- let doesCustomGroupMatch = props => {
5
- if ('anyOf' in props.customGroup) {
6
- return props.customGroup.anyOf.some(subgroup =>
7
- doesCustomGroupMatch({ ...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
- if (
36
- 'decoratorNamePattern' in props.customGroup &&
37
- props.customGroup.decoratorNamePattern
38
- ) {
39
- let decoratorPattern = props.customGroup.decoratorNamePattern
40
- let matchesDecoratorNamePattern = props.decorators.some(decorator =>
41
- matches.matches(decorator, decoratorPattern),
42
- )
43
- if (!matchesDecoratorNamePattern) {
44
- return false
45
- }
46
- }
47
- return true
48
- }
49
- exports.doesCustomGroupMatch = doesCustomGroupMatch
@@ -1,49 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
3
- const matches = require('../../utils/matches.js')
4
- let doesCustomGroupMatch = props => {
5
- if ('anyOf' in props.customGroup) {
6
- return props.customGroup.anyOf.some(subgroup =>
7
- doesCustomGroupMatch({ ...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
- if (
36
- 'elementValuePattern' in props.customGroup &&
37
- props.customGroup.elementValuePattern
38
- ) {
39
- let matchesElementValuePattern = matches.matches(
40
- props.elementValue ?? '',
41
- props.customGroup.elementValuePattern,
42
- )
43
- if (!matchesElementValuePattern) {
44
- return false
45
- }
46
- }
47
- return true
48
- }
49
- exports.doesCustomGroupMatch = doesCustomGroupMatch