eslint-plugin-perfectionist 5.12.0 → 5.13.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 (99) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +9 -5
  3. package/dist/package.json.js +1 -1
  4. package/dist/rules/sort-array-includes.js +6 -6
  5. package/dist/rules/sort-arrays/sort-array.d.ts +14 -0
  6. package/dist/rules/sort-arrays/sort-array.js +31 -1
  7. package/dist/rules/sort-arrays.js +6 -6
  8. package/dist/rules/sort-classes/sort-class.js +7 -3
  9. package/dist/rules/sort-classes.js +11 -11
  10. package/dist/rules/sort-constructor-parameters/compute-matched-context-options.d.ts +25 -0
  11. package/dist/rules/sort-constructor-parameters/compute-matched-context-options.js +53 -0
  12. package/dist/rules/sort-constructor-parameters/compute-node-name.d.ts +17 -0
  13. package/dist/rules/sort-constructor-parameters/compute-node-name.js +38 -0
  14. package/dist/rules/sort-constructor-parameters/compute-parameter-modifiers.d.ts +18 -0
  15. package/dist/rules/sort-constructor-parameters/compute-parameter-modifiers.js +59 -0
  16. package/dist/rules/sort-constructor-parameters/is-constructor-overloaded.d.ts +11 -0
  17. package/dist/rules/sort-constructor-parameters/is-constructor-overloaded.js +26 -0
  18. package/dist/rules/sort-constructor-parameters/sort-constructor-parameters.d.ts +26 -0
  19. package/dist/rules/sort-constructor-parameters/sort-constructor-parameters.js +177 -0
  20. package/dist/rules/sort-constructor-parameters/types.d.ts +102 -0
  21. package/dist/rules/sort-constructor-parameters/types.js +36 -0
  22. package/dist/rules/sort-constructor-parameters.d.ts +26 -0
  23. package/dist/rules/sort-constructor-parameters.js +122 -0
  24. package/dist/rules/sort-decorators.js +9 -5
  25. package/dist/rules/sort-enums/sort-enum.js +5 -1
  26. package/dist/rules/sort-enums.js +7 -7
  27. package/dist/rules/sort-exports.js +7 -3
  28. package/dist/rules/sort-heritage-clauses/sort-heritage-clause.d.ts +8 -0
  29. package/dist/rules/sort-heritage-clauses/sort-heritage-clause.js +32 -7
  30. package/dist/rules/sort-heritage-clauses.js +6 -6
  31. package/dist/rules/sort-import-attributes/compute-matched-context-options.js +1 -3
  32. package/dist/rules/sort-import-attributes/compute-node-name.d.ts +1 -4
  33. package/dist/rules/sort-import-attributes/compute-node-name.js +3 -4
  34. package/dist/rules/sort-import-attributes/sort-import-or-export-attributes.d.ts +10 -0
  35. package/dist/rules/sort-import-attributes/sort-import-or-export-attributes.js +28 -2
  36. package/dist/rules/sort-import-attributes.js +6 -6
  37. package/dist/rules/sort-imports/compute-common-selectors.js +4 -5
  38. package/dist/rules/sort-imports/types.d.ts +5 -0
  39. package/dist/rules/sort-imports/types.js +10 -0
  40. package/dist/rules/sort-imports.js +34 -12
  41. package/dist/rules/sort-jsx-props/sort-jsx-object.d.ts +8 -0
  42. package/dist/rules/sort-jsx-props/sort-jsx-object.js +32 -7
  43. package/dist/rules/sort-jsx-props.js +7 -7
  44. package/dist/rules/sort-maps/sort-potential-map.d.ts +8 -0
  45. package/dist/rules/sort-maps/sort-potential-map.js +34 -7
  46. package/dist/rules/sort-maps.js +6 -6
  47. package/dist/rules/sort-modules/types.d.ts +5 -0
  48. package/dist/rules/sort-modules/types.js +12 -1
  49. package/dist/rules/sort-modules.js +25 -14
  50. package/dist/rules/sort-named-exports/sort-named-export.d.ts +8 -0
  51. package/dist/rules/sort-named-exports/sort-named-export.js +32 -7
  52. package/dist/rules/sort-named-exports.js +6 -6
  53. package/dist/rules/sort-named-imports/sort-named-import.d.ts +8 -0
  54. package/dist/rules/sort-named-imports/sort-named-import.js +32 -7
  55. package/dist/rules/sort-named-imports.js +6 -6
  56. package/dist/rules/sort-object-types/sort-object-type-elements.d.ts +10 -0
  57. package/dist/rules/sort-object-types/sort-object-type-elements.js +29 -2
  58. package/dist/rules/sort-object-types/types.d.ts +5 -0
  59. package/dist/rules/sort-object-types/types.js +12 -1
  60. package/dist/rules/sort-object-types.js +7 -9
  61. package/dist/rules/sort-objects/can-have-property-dependencies.d.ts +11 -0
  62. package/dist/rules/sort-objects/can-have-property-dependencies.js +54 -0
  63. package/dist/rules/sort-objects/sort-object.d.ts +8 -0
  64. package/dist/rules/sort-objects/sort-object.js +38 -9
  65. package/dist/rules/sort-objects/types.d.ts +5 -0
  66. package/dist/rules/sort-objects/types.js +12 -1
  67. package/dist/rules/sort-objects.js +9 -11
  68. package/dist/rules/sort-switch-case/build-case-block-comparator-by-options-computer.d.ts +26 -0
  69. package/dist/rules/sort-switch-case/build-case-block-comparator-by-options-computer.js +36 -0
  70. package/dist/rules/sort-switch-case.js +34 -43
  71. package/dist/rules/sort-union-or-intersection-types/build-json-schema.js +1 -1
  72. package/dist/rules/sort-union-or-intersection-types/sort-union-or-intersection-types.d.ts +14 -0
  73. package/dist/rules/sort-union-or-intersection-types/sort-union-or-intersection-types.js +31 -1
  74. package/dist/rules/sort-variable-declarations/sort-variable-declaration.js +16 -12
  75. package/dist/rules/sort-variable-declarations.js +13 -13
  76. package/dist/utils/alphabet.d.ts +13 -0
  77. package/dist/utils/alphabet.js +16 -0
  78. package/dist/utils/can-report-errors.d.ts +41 -0
  79. package/dist/utils/can-report-errors.js +51 -0
  80. package/dist/utils/compare/compare-naturally.js +8 -1
  81. package/dist/utils/complete.d.ts +28 -13
  82. package/dist/utils/complete.js +24 -9
  83. package/dist/utils/compute-deep-scope-references.d.ts +6 -4
  84. package/dist/utils/compute-deep-scope-references.js +59 -10
  85. package/dist/utils/compute-dependencies-by-sorting-node.js +5 -5
  86. package/dist/utils/get-eslint-disabled-lines.d.ts +3 -3
  87. package/dist/utils/get-eslint-disabled-lines.js +36 -3
  88. package/dist/utils/get-eslint-disabled-rules.js +26 -2
  89. package/dist/utils/get-settings.d.ts +54 -1
  90. package/dist/utils/get-settings.js +94 -26
  91. package/dist/utils/is-node-eslint-disabled.d.ts +3 -3
  92. package/dist/utils/is-node-eslint-disabled.js +3 -3
  93. package/dist/utils/json-schemas/common-groups-json-schemas.d.ts +4 -1
  94. package/dist/utils/matches-json-schema.d.ts +33 -0
  95. package/dist/utils/matches-json-schema.js +99 -0
  96. package/dist/utils/report-all-errors.d.ts +1 -2
  97. package/dist/utils/tsconfig/read-closest-ts-config-by-path.js +9 -1
  98. package/package.json +8 -3
  99. package/readme.md +29 -25
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ declare const _default: {
18
18
  configs: PluginConfigs
19
19
  } & ESLint.Plugin
20
20
  export default _default
21
+ export type { Options as SortConstructorParametersOptions } from './rules/sort-constructor-parameters/types.js'
21
22
  export type { Options as SortVariableDeclarationsOptions } from './rules/sort-variable-declarations/types.js'
22
23
  export type { Options as SortIntersectionTypesOptions } from './rules/sort-intersection-types/types.js'
23
24
  export type { Options as SortImportAttributesOptions } from './rules/sort-import-attributes/types.js'
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { name, version } from './package.json.js'
2
+ import sort_constructor_parameters_default from './rules/sort-constructor-parameters.js'
2
3
  import sort_variable_declarations_default from './rules/sort-variable-declarations.js'
3
4
  import sort_intersection_types_default from './rules/sort-intersection-types.js'
4
5
  import sort_import_attributes_default from './rules/sort-import-attributes.js'
@@ -49,6 +50,7 @@ let recommendedRules = {
49
50
  }
50
51
  let rules = {
51
52
  ...recommendedRules,
53
+ 'sort-constructor-parameters': sort_constructor_parameters_default,
52
54
  'sort-arrays': sort_arrays_default,
53
55
  }
54
56
  let plugin = {
@@ -112,8 +114,10 @@ let configs = {
112
114
  order: 'asc',
113
115
  }),
114
116
  }
115
- var eslint_plugin_perfectionist_default = {
116
- ...plugin,
117
- configs,
118
- }
119
- export { configs, eslint_plugin_perfectionist_default as default, rules }
117
+ /**
118
+ * The configs register `plugin` under its name, so the default export must be
119
+ * the same object. ESLint compares plugins by reference and throws "Cannot
120
+ * redefine plugin" when a user config registers a copy.
121
+ */
122
+ plugin.configs = configs
123
+ export { configs, plugin as default, rules }
@@ -1,3 +1,3 @@
1
1
  const name = 'eslint-plugin-perfectionist'
2
- const version = '5.12.0'
2
+ const version = '5.13.0'
3
3
  export { name, version }
@@ -1,19 +1,19 @@
1
- import {
2
- buildCommonJsonSchemas,
3
- buildUseConfigIfJsonSchema,
4
- matchesAstSelectorJsonSchema,
5
- } from '../utils/json-schemas/common-json-schemas.js'
6
- import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
7
1
  import {
8
2
  EXTRA_SPACING_ERROR,
9
3
  GROUP_ORDER_ERROR,
10
4
  MISSED_SPACING_ERROR,
11
5
  ORDER_ERROR,
12
6
  } from '../utils/report-errors.js'
7
+ import {
8
+ buildCommonJsonSchemas,
9
+ buildUseConfigIfJsonSchema,
10
+ matchesAstSelectorJsonSchema,
11
+ } from '../utils/json-schemas/common-json-schemas.js'
13
12
  import {
14
13
  partitionByCommentJsonSchema,
15
14
  partitionByNewlineJsonSchema,
16
15
  } from '../utils/json-schemas/common-partition-json-schemas.js'
16
+ import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
17
17
  import { buildAstListeners } from '../utils/build-ast-listeners.js'
18
18
  import { createEslintRule } from '../utils/create-eslint-rule.js'
19
19
  import { additionalCustomGroupMatchOptionsJsonSchema } from './sort-arrays/types.js'
@@ -1,6 +1,20 @@
1
1
  import { RuleContext } from '@typescript-eslint/utils/ts-eslint'
2
2
  import { TSESTree } from '@typescript-eslint/types'
3
3
  import { Options } from './types.js'
4
+ /**
5
+ * Sorts the elements of an array-like expression.
6
+ *
7
+ * @param params - Parameters.
8
+ * @param params.cachedGroupsByModifiersAndSelectors - Cache of predefined
9
+ * groups.
10
+ * @param params.mustHaveMatchedContextOptions - Whether to skip nodes matching
11
+ * no option.
12
+ * @param params.availableMessageIds - The message IDs to report with.
13
+ * @param params.matchedAstSelectors - The AST selectors the node matched.
14
+ * @param params.defaultOptions - The rule default options.
15
+ * @param params.context - The rule context.
16
+ * @param params.node - Array or `new` expression whose elements are sorted.
17
+ */
4
18
  export declare function sortArray<MessageIds extends string>({
5
19
  cachedGroupsByModifiersAndSelectors,
6
20
  mustHaveMatchedContextOptions,
@@ -15,11 +15,26 @@ import { rangeToDiff } from '../../utils/range-to-diff.js'
15
15
  import { getSettings } from '../../utils/get-settings.js'
16
16
  import { isSortable } from '../../utils/is-sortable.js'
17
17
  import { complete } from '../../utils/complete.js'
18
+ import { canReportErrors } from '../../utils/can-report-errors.js'
18
19
  import { allSelectors } from './types.js'
19
20
  import { computeNodeName } from './compute-node-name.js'
20
21
  import { computeMatchedContextOptions } from './compute-matched-context-options.js'
21
22
  import { computeArrayElements } from './compute-array-elements.js'
22
23
  import { AST_NODE_TYPES } from '@typescript-eslint/types'
24
+ /**
25
+ * Sorts the elements of an array-like expression.
26
+ *
27
+ * @param params - Parameters.
28
+ * @param params.cachedGroupsByModifiersAndSelectors - Cache of predefined
29
+ * groups.
30
+ * @param params.mustHaveMatchedContextOptions - Whether to skip nodes matching
31
+ * no option.
32
+ * @param params.availableMessageIds - The message IDs to report with.
33
+ * @param params.matchedAstSelectors - The AST selectors the node matched.
34
+ * @param params.defaultOptions - The rule default options.
35
+ * @param params.context - The rule context.
36
+ * @param params.node - Array or `new` expression whose elements are sorted.
37
+ */
23
38
  function sortArray({
24
39
  cachedGroupsByModifiersAndSelectors,
25
40
  mustHaveMatchedContextOptions,
@@ -46,7 +61,11 @@ function sortArray({
46
61
  if (mustHaveMatchedContextOptions && !matchedContextOptions) {
47
62
  return
48
63
  }
49
- let options = complete(matchedContextOptions, settings, defaultOptions)
64
+ let options = complete({
65
+ options: matchedContextOptions,
66
+ defaults: defaultOptions,
67
+ settings,
68
+ })
50
69
  validateCustomSortConfig(options)
51
70
  validateGroupsConfig({
52
71
  selectors: allSelectors,
@@ -54,6 +73,17 @@ function sortArray({
54
73
  options,
55
74
  })
56
75
  validateNewlinesAndPartitionConfig(options)
76
+ if (
77
+ !canReportErrors({
78
+ comparatorByOptionsComputer: defaultComparatorByOptionsComputer,
79
+ newlinesBetweenValueGetter: void 0,
80
+ canHaveDependencies: false,
81
+ availableMessageIds,
82
+ options,
83
+ })
84
+ ) {
85
+ return
86
+ }
57
87
  let eslintDisabledLines = getEslintDisabledLines({
58
88
  ruleName: id,
59
89
  sourceCode,
@@ -1,19 +1,19 @@
1
- import {
2
- buildCommonJsonSchemas,
3
- buildUseConfigIfJsonSchema,
4
- matchesAstSelectorJsonSchema,
5
- } from '../utils/json-schemas/common-json-schemas.js'
6
- import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
7
1
  import {
8
2
  EXTRA_SPACING_ERROR,
9
3
  GROUP_ORDER_ERROR,
10
4
  MISSED_SPACING_ERROR,
11
5
  ORDER_ERROR,
12
6
  } from '../utils/report-errors.js'
7
+ import {
8
+ buildCommonJsonSchemas,
9
+ buildUseConfigIfJsonSchema,
10
+ matchesAstSelectorJsonSchema,
11
+ } from '../utils/json-schemas/common-json-schemas.js'
13
12
  import {
14
13
  partitionByCommentJsonSchema,
15
14
  partitionByNewlineJsonSchema,
16
15
  } from '../utils/json-schemas/common-partition-json-schemas.js'
16
+ import { buildCommonGroupsJsonSchemas } from '../utils/json-schemas/common-groups-json-schemas.js'
17
17
  import { buildAstListeners } from '../utils/build-ast-listeners.js'
18
18
  import { createEslintRule } from '../utils/create-eslint-rule.js'
19
19
  import { additionalCustomGroupMatchOptionsJsonSchema } from './sort-arrays/types.js'
@@ -10,8 +10,10 @@ import { getEslintDisabledLines } from '../../utils/get-eslint-disabled-lines.js
10
10
  import { doesCustomGroupMatch } from '../../utils/does-custom-group-match.js'
11
11
  import { isNodeEslintDisabled } from '../../utils/is-node-eslint-disabled.js'
12
12
  import { validateGroupsConfig } from '../../utils/validate-groups-config.js'
13
+ import { getNodeDecorators } from '../../utils/get-node-decorators.js'
13
14
  import { getGroupIndex } from '../../utils/get-group-index.js'
14
15
  import { sortNodesByGroups } from '../../utils/sort-nodes-by-groups.js'
16
+ import { getDecoratorName } from '../../utils/get-decorator-name.js'
15
17
  import { reportAllErrors } from '../../utils/report-all-errors.js'
16
18
  import { shouldPartition } from '../../utils/should-partition.js'
17
19
  import { computeGroup } from '../../utils/compute-group.js'
@@ -19,8 +21,6 @@ import { rangeToDiff } from '../../utils/range-to-diff.js'
19
21
  import { getSettings } from '../../utils/get-settings.js'
20
22
  import { isSortable } from '../../utils/is-sortable.js'
21
23
  import { complete } from '../../utils/complete.js'
22
- import { getNodeDecorators } from '../../utils/get-node-decorators.js'
23
- import { getDecoratorName } from '../../utils/get-decorator-name.js'
24
24
  import {
25
25
  DEPENDENCY_ORDER_ERROR_ID,
26
26
  EXTRA_SPACING_ERROR_ID,
@@ -99,7 +99,11 @@ function sortClass({ matchedAstSelectors, context, node }) {
99
99
  classElements,
100
100
  context,
101
101
  })
102
- let options = complete(matchedContextOptions, settings, defaultOptions)
102
+ let options = complete({
103
+ options: matchedContextOptions,
104
+ defaults: defaultOptions,
105
+ settings,
106
+ })
103
107
  validateCustomSortConfig(options)
104
108
  validateGroupsConfig({
105
109
  modifiers: allModifiers,
@@ -1,14 +1,3 @@
1
- import {
2
- buildCommonJsonSchemas,
3
- buildRegexJsonSchema,
4
- buildUseConfigIfJsonSchema,
5
- matchesAstSelectorJsonSchema,
6
- useExperimentalDependencyDetectionJsonSchema,
7
- } from '../utils/json-schemas/common-json-schemas.js'
8
- import {
9
- buildCommonGroupsJsonSchemas,
10
- newlinesBetweenJsonSchema,
11
- } from '../utils/json-schemas/common-groups-json-schemas.js'
12
1
  import {
13
2
  DEPENDENCY_ORDER_ERROR,
14
3
  EXTRA_SPACING_ERROR,
@@ -16,10 +5,21 @@ import {
16
5
  MISSED_SPACING_ERROR,
17
6
  ORDER_ERROR,
18
7
  } from '../utils/report-errors.js'
8
+ import {
9
+ buildCommonJsonSchemas,
10
+ buildRegexJsonSchema,
11
+ buildUseConfigIfJsonSchema,
12
+ matchesAstSelectorJsonSchema,
13
+ useExperimentalDependencyDetectionJsonSchema,
14
+ } from '../utils/json-schemas/common-json-schemas.js'
19
15
  import {
20
16
  partitionByCommentJsonSchema,
21
17
  partitionByNewlineJsonSchema,
22
18
  } from '../utils/json-schemas/common-partition-json-schemas.js'
19
+ import {
20
+ buildCommonGroupsJsonSchemas,
21
+ newlinesBetweenJsonSchema,
22
+ } from '../utils/json-schemas/common-groups-json-schemas.js'
23
23
  import { buildAstListeners } from '../utils/build-ast-listeners.js'
24
24
  import { createEslintRule } from '../utils/create-eslint-rule.js'
25
25
  import {
@@ -0,0 +1,25 @@
1
+ import { RuleContext } from '@typescript-eslint/utils/ts-eslint'
2
+ import { TSESTree } from '@typescript-eslint/types'
3
+ import { Options } from './types.js'
4
+ /**
5
+ * Computes the matched context options for a given constructor node.
6
+ *
7
+ * @param params - Parameters.
8
+ * @param params.matchedAstSelectors - The matched AST selectors for a
9
+ * constructor node.
10
+ * @param params.params - The constructor parameters to compute the context
11
+ * options for.
12
+ * @param params.context - The rule context.
13
+ * @returns The matched context options or undefined if none match.
14
+ */
15
+ export declare function computeMatchedContextOptions<
16
+ MessageIds extends string,
17
+ >({
18
+ matchedAstSelectors,
19
+ context,
20
+ params,
21
+ }: {
22
+ context: Readonly<RuleContext<MessageIds, Options>>
23
+ matchedAstSelectors: ReadonlySet<string>
24
+ params: TSESTree.Parameter[]
25
+ }): Options[number] | undefined
@@ -0,0 +1,53 @@
1
+ import { passesAllNamesMatchPatternFilter } from '../../utils/context-matching/passes-all-names-match-pattern-filter.js'
2
+ import { passesAstSelectorFilter } from '../../utils/context-matching/passes-ast-selector-filter.js'
3
+ import { computeNodeName } from './compute-node-name.js'
4
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
5
+ /**
6
+ * Computes the matched context options for a given constructor node.
7
+ *
8
+ * @param params - Parameters.
9
+ * @param params.matchedAstSelectors - The matched AST selectors for a
10
+ * constructor node.
11
+ * @param params.params - The constructor parameters to compute the context
12
+ * options for.
13
+ * @param params.context - The rule context.
14
+ * @returns The matched context options or undefined if none match.
15
+ */
16
+ function computeMatchedContextOptions({
17
+ matchedAstSelectors,
18
+ context,
19
+ params,
20
+ }) {
21
+ let nodeNames = params
22
+ .filter(parameter => parameter.type !== AST_NODE_TYPES.RestElement)
23
+ .map(parameter =>
24
+ computeNodeName({
25
+ sourceCode: context.sourceCode,
26
+ node: parameter,
27
+ }),
28
+ )
29
+ return context.options.find(options =>
30
+ isContextOptionMatching({
31
+ matchedAstSelectors,
32
+ nodeNames,
33
+ options,
34
+ }),
35
+ )
36
+ }
37
+ function isContextOptionMatching({ matchedAstSelectors, nodeNames, options }) {
38
+ /* v8 ignore if -- Filtered at validation level */
39
+ if (!options.useConfigurationIf) {
40
+ return true
41
+ }
42
+ return (
43
+ passesAllNamesMatchPatternFilter({
44
+ allNamesMatchPattern: options.useConfigurationIf.allNamesMatchPattern,
45
+ nodeNames,
46
+ }) &&
47
+ passesAstSelectorFilter({
48
+ matchesAstSelector: options.useConfigurationIf.matchesAstSelector,
49
+ matchedAstSelectors,
50
+ })
51
+ )
52
+ }
53
+ export { computeMatchedContextOptions }
@@ -0,0 +1,17 @@
1
+ import { TSESTree } from '@typescript-eslint/types'
2
+ import { TSESLint } from '@typescript-eslint/utils'
3
+ /**
4
+ * Computes the name of a constructor parameter.
5
+ *
6
+ * @param props - The parameters object.
7
+ * @param props.sourceCode - ESLint source code object for text extraction.
8
+ * @param props.node - The AST node representing a constructor parameter.
9
+ * @returns The name of the constructor parameter.
10
+ */
11
+ export declare function computeNodeName({
12
+ sourceCode,
13
+ node,
14
+ }: {
15
+ node: Exclude<TSESTree.Parameter, TSESTree.RestElement>
16
+ sourceCode: TSESLint.SourceCode
17
+ }): string
@@ -0,0 +1,38 @@
1
+ import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
2
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
3
+ /**
4
+ * Computes the name of a constructor parameter.
5
+ *
6
+ * @param props - The parameters object.
7
+ * @param props.sourceCode - ESLint source code object for text extraction.
8
+ * @param props.node - The AST node representing a constructor parameter.
9
+ * @returns The name of the constructor parameter.
10
+ */
11
+ function computeNodeName({ sourceCode, node }) {
12
+ let nonParameterNorAssignmentNode =
13
+ extractFirstNonParameterNorAssignmentNode(node)
14
+ switch (nonParameterNorAssignmentNode.type) {
15
+ case AST_NODE_TYPES.ObjectPattern:
16
+ case AST_NODE_TYPES.ArrayPattern:
17
+ return sourceCode.getText(nonParameterNorAssignmentNode)
18
+ case AST_NODE_TYPES.Identifier:
19
+ return nonParameterNorAssignmentNode.name
20
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
21
+ default:
22
+ throw new UnreachableCaseError(nonParameterNorAssignmentNode)
23
+ }
24
+ }
25
+ function extractFirstNonParameterNorAssignmentNode(node) {
26
+ let currentNode = node
27
+ while (
28
+ currentNode.type === AST_NODE_TYPES.TSParameterProperty ||
29
+ currentNode.type === AST_NODE_TYPES.AssignmentPattern
30
+ ) {
31
+ currentNode =
32
+ currentNode.type === AST_NODE_TYPES.TSParameterProperty ?
33
+ currentNode.parameter
34
+ : currentNode.left
35
+ }
36
+ return currentNode
37
+ }
38
+ export { computeNodeName }
@@ -0,0 +1,18 @@
1
+ import { TSESTree } from '@typescript-eslint/types'
2
+ import { Modifier } from './types.js'
3
+ type Parameter = Exclude<TSESTree.Parameter, TSESTree.RestElement>
4
+ /**
5
+ * Computes the modifiers carried by a constructor parameter, ordered from most
6
+ * to least important.
7
+ *
8
+ * Every parameter receives an accessibility modifier, defaulting to `public`
9
+ * when none is declared (including plain parameters that are not parameter
10
+ * properties).
11
+ *
12
+ * @param parameter - The constructor parameter node.
13
+ * @returns The modifiers, ordered from most to least important.
14
+ */
15
+ export declare function computeParameterModifiers(
16
+ parameter: Parameter,
17
+ ): Modifier[]
18
+ export {}
@@ -0,0 +1,59 @@
1
+ import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
2
+ import { getNodeDecorators } from '../../utils/get-node-decorators.js'
3
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
4
+ /**
5
+ * Computes the modifiers carried by a constructor parameter, ordered from most
6
+ * to least important.
7
+ *
8
+ * Every parameter receives an accessibility modifier, defaulting to `public`
9
+ * when none is declared (including plain parameters that are not parameter
10
+ * properties).
11
+ *
12
+ * @param parameter - The constructor parameter node.
13
+ * @returns The modifiers, ordered from most to least important.
14
+ */
15
+ function computeParameterModifiers(parameter) {
16
+ return [
17
+ ...computeDecoratedModifier(parameter),
18
+ ...computeOverrideModifier(parameter),
19
+ ...computeReadonlyModifier(parameter),
20
+ ...computeAccessibilityModifier(parameter),
21
+ ]
22
+ }
23
+ function computeAccessibilityModifier(parameter) {
24
+ if (parameter.type !== AST_NODE_TYPES.TSParameterProperty) {
25
+ return ['public']
26
+ }
27
+ switch (parameter.accessibility) {
28
+ case 'protected':
29
+ return ['protected']
30
+ case 'private':
31
+ return ['private']
32
+ case void 0:
33
+ case 'public':
34
+ return ['public']
35
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
36
+ default:
37
+ throw new UnreachableCaseError(parameter.accessibility)
38
+ }
39
+ }
40
+ function computeOverrideModifier(parameter) {
41
+ return (
42
+ parameter.type === AST_NODE_TYPES.TSParameterProperty &&
43
+ parameter.override
44
+ ) ?
45
+ ['override']
46
+ : []
47
+ }
48
+ function computeReadonlyModifier(parameter) {
49
+ return (
50
+ parameter.type === AST_NODE_TYPES.TSParameterProperty &&
51
+ parameter.readonly
52
+ ) ?
53
+ ['readonly']
54
+ : []
55
+ }
56
+ function computeDecoratedModifier(parameter) {
57
+ return getNodeDecorators(parameter).length > 0 ? ['decorated'] : []
58
+ }
59
+ export { computeParameterModifiers }
@@ -0,0 +1,11 @@
1
+ import { TSESTree } from '@typescript-eslint/types'
2
+ /**
3
+ * Checks whether a constructor is part of an overload set or is a bodiless
4
+ * signature.
5
+ *
6
+ * @param node - The constructor method definition to check.
7
+ * @returns Whether the constructor is overloaded or bodiless.
8
+ */
9
+ export declare function isConstructorOverloaded(
10
+ node: TSESTree.MethodDefinition,
11
+ ): boolean
@@ -0,0 +1,26 @@
1
+ import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
2
+ import { AST_NODE_TYPES } from '@typescript-eslint/types'
3
+ /**
4
+ * Checks whether a constructor is part of an overload set or is a bodiless
5
+ * signature.
6
+ *
7
+ * @param node - The constructor method definition to check.
8
+ * @returns Whether the constructor is overloaded or bodiless.
9
+ */
10
+ function isConstructorOverloaded(node) {
11
+ switch (node.value.type) {
12
+ case AST_NODE_TYPES.TSEmptyBodyFunctionExpression:
13
+ return true
14
+ case AST_NODE_TYPES.FunctionExpression:
15
+ return node.parent.body.some(
16
+ member =>
17
+ member !== node &&
18
+ member.type === AST_NODE_TYPES.MethodDefinition &&
19
+ member.kind === 'constructor',
20
+ )
21
+ /* v8 ignore next 2 -- @preserve Exhaustive guard. */
22
+ default:
23
+ throw new UnreachableCaseError(node.value)
24
+ }
25
+ }
26
+ export { isConstructorOverloaded }
@@ -0,0 +1,26 @@
1
+ import { RuleContext } from '@typescript-eslint/utils/ts-eslint'
2
+ import { TSESTree } from '@typescript-eslint/types'
3
+ import { Options } from './types.js'
4
+ export declare function sortConstructorParameters<MessageIds extends string>({
5
+ cachedGroupsByModifiersAndSelectors,
6
+ mustHaveMatchedContextOptions,
7
+ availableMessageIds,
8
+ matchedAstSelectors,
9
+ defaultOptions,
10
+ context,
11
+ node,
12
+ }: {
13
+ availableMessageIds: {
14
+ missedSpacingBetweenMembers: MessageIds
15
+ extraSpacingBetweenMembers: MessageIds
16
+ unexpectedDependencyOrder: MessageIds
17
+ unexpectedGroupOrder: MessageIds
18
+ unexpectedOrder: MessageIds
19
+ }
20
+ cachedGroupsByModifiersAndSelectors: Map<string, string[]>
21
+ context: Readonly<RuleContext<MessageIds, Options>>
22
+ defaultOptions: Required<Options[number]>
23
+ matchedAstSelectors: ReadonlySet<string>
24
+ mustHaveMatchedContextOptions: boolean
25
+ node: TSESTree.MethodDefinition
26
+ }): void