Skip to content

Commit ff6033a

Browse files
committed
Fix circular dependency with rule names
1 parent 04657bc commit ff6033a

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

src/config/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
export const PLUGIN_NAME = 'typescript-sort-keys'
2+
3+
export enum RuleNames {
4+
Enum = 'enum',
5+
StringEnum = 'string-enum',
6+
Interface = 'interface',
7+
}

src/report.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ export function reportParentNode(
3030
context.report({
3131
loc,
3232
messageId,
33-
node: bodyParent,
3433
data: {
3534
unsortedCount,
36-
notice: getDeprecationMessage(context.id),
35+
notice: getDeprecationMessage(context.id.split('/').at(-1)!),
3736
},
3837
fix: fixerFunction,
3938
})
@@ -50,12 +49,12 @@ export function reportBodyNodes(
5049
nodePositions: Map<NodeOrToken, NodePositionInfo>,
5150
sortedBody: NodeOrToken[],
5251
finalIndicesToReport: boolean[],
53-
fixerFunction: ReportFixFunction,
5452
) {
5553
const { context, createReportPropertiesObject } = createReporterArgs
5654
const { isInsensitive, isNatural, isRequiredFirst, order } = getOptions(
5755
createReporterArgs.context,
5856
)
57+
5958
for (const [node, { finalIndex }] of nodePositions.entries()) {
6059
// If the node is not in the correct position, report it
6160
if (finalIndicesToReport[finalIndex]) {
@@ -88,7 +87,6 @@ export function reportBodyNodes(
8887
options: optionsString,
8988
notice: getDeprecationMessage(context.id),
9089
},
91-
fix: fixerFunction,
9290
})
9391
}
9492
}

src/rules/enum.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TSESTree } from '@typescript-eslint/utils'
22
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
33

4+
import { RuleNames } from '../config/constants'
45
import { createReporter } from '../plugin'
56
import {
67
ErrorMessage,
@@ -15,7 +16,7 @@ import { createRule, RuleMetaData } from '../utils/rule'
1516
/**
1617
* The name of this rule.
1718
*/
18-
export const name = 'enum' as const
19+
export const name = RuleNames.Enum as const
1920

2021
/**
2122
* The options this rule can take.

src/rules/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TSESTree } from '@typescript-eslint/utils'
22
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
33

4+
import { RuleNames } from '../config/constants'
45
import { createReporter } from '../plugin'
56
import {
67
ErrorMessage,
@@ -15,7 +16,7 @@ import { createRule, RuleMetaData } from '../utils/rule'
1516
/**
1617
* The name of this rule.
1718
*/
18-
export const name = 'interface' as const
19+
export const name = RuleNames.Interface as const
1920

2021
/**
2122
* The options this rule can take.

src/rules/string-enum.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'
22
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
33

4+
import { RuleNames } from '../config/constants'
45
import { createReporter } from '../plugin'
56
import {
67
ErrorMessage,
@@ -16,7 +17,7 @@ import { createRule, RuleMetaData } from '../utils/rule'
1617
* @deprecated
1718
* The name of this rule.
1819
*/
19-
export const name = 'string-enum' as const
20+
export const name = RuleNames.StringEnum as const
2021

2122
/**
2223
* @deprecated
@@ -74,6 +75,7 @@ const meta: RuleMetaData<errorMessageKeys> = {
7475
messages: errorMessages,
7576
fixable: 'code',
7677
schema,
78+
deprecated: true,
7779
}
7880

7981
/**

src/types/error.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export enum ErrorMessage {
22
InterfaceParentInvalidOrder = `Found {{ unsortedCount }} keys out of order.`,
3-
EnumParentInvalidOrder = `{{ notice }}Found {{ unsortedCount }} members out of order.`,
3+
EnumParentInvalidOrder = `Found {{ unsortedCount }} members out of order.{{ notice }}`,
44
InterfaceInvalidOrder = `Expected interface keys to be in {{ order }}ending {{ options }}order. '{{ nodeName }}' should be {{ messageShouldBeWhere }}. Run autofix to sort entire body.`,
5-
EnumInvalidOrder = `{{ notice }}Expected enum members to be in {{ order }}ending {{ options }}order. '{{ nodeName }}' should be {{ messageShouldBeWhere }}. Run autofix to sort entire body.`,
5+
EnumInvalidOrder = `Expected enum members to be in {{ order }}ending {{ options }}order. '{{ nodeName }}' should be {{ messageShouldBeWhere }}. Run autofix to sort entire body.{{ notice }}`,
66
}

src/utils/reportUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PLUGIN_NAME, RuleNames } from '../config/constants'
12
import { NodeOrToken, NodePositionInfo } from '../types'
23

34
/**
@@ -44,8 +45,8 @@ export function getUnsortedInfo(
4445
// Return string with url to notify of rule deprecations
4546
export function getDeprecationMessage(name: string) {
4647
switch (name) {
47-
case enumRuleNameDeprecated:
48-
return `DEPRECATED: see [${PLUGIN_NAME}/${enumRuleName}](${getRuleDocsUrl(enumRuleName)})`
48+
case RuleNames.StringEnum:
49+
return `\nThis rule is deprecated. Use \`${PLUGIN_NAME}/${RuleNames.Enum}\` instead. See docs for more info.`
4950
default:
5051
return ''
5152
}

0 commit comments

Comments
 (0)