Skip to content

Commit 4af6210

Browse files
committed
update plugin messages
1 parent fa25630 commit 4af6210

File tree

5 files changed

+35
-45
lines changed

5 files changed

+35
-45
lines changed

src/report.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,29 @@ export function reportParentNode(
2727
) {
2828
const { context, createReportParentObject } = createReporterArgs
2929
const { loc, messageId } = createReportParentObject(_loc)
30+
31+
const { isInsensitive, isNatural, isRequiredFirst, order } = getOptions(
32+
createReporterArgs.context,
33+
)
34+
35+
let optionsString = [
36+
isRequiredFirst && 'required-first',
37+
isInsensitive && 'insensitive',
38+
isNatural && 'natural',
39+
]
40+
.filter(Boolean)
41+
.join(', ')
42+
if (optionsString) optionsString += ' '
43+
3044
context.report({
3145
loc,
3246
messageId,
3347
data: {
3448
plural: unsortedCount > 1 ? 's' : '',
3549
unsortedCount,
3650
notice: getDeprecationMessage(context.id.split('/').at(-1)!),
51+
order,
52+
options: optionsString,
3753
},
3854
fix: fixerFunction,
3955
})
@@ -52,9 +68,6 @@ export function reportBodyNodes(
5268
finalIndicesToReport: boolean[],
5369
) {
5470
const { context, createReportPropertiesObject } = createReporterArgs
55-
const { isInsensitive, isNatural, isRequiredFirst, order } = getOptions(
56-
createReporterArgs.context,
57-
)
5871

5972
for (const [node, { finalIndex }] of nodePositions.entries()) {
6073
// If the node is not in the correct position, report it
@@ -65,15 +78,6 @@ export function reportBodyNodes(
6578
assert(loc, 'createReportObject return value must include a node location')
6679
assert(messageId, 'createReportObject return value must include a problem message')
6780

68-
let optionsString = [
69-
isRequiredFirst && 'required-first',
70-
isInsensitive && 'insensitive',
71-
isNatural && 'natural',
72-
]
73-
.filter(Boolean)
74-
.join(', ')
75-
if (optionsString) optionsString += ' '
76-
7781
context.report({
7882
loc,
7983
messageId,
@@ -84,9 +88,6 @@ export function reportBodyNodes(
8488
finalIndex + 1 < sortedBody.length
8589
? `before '${getPropertyName(sortedBody[finalIndex + 1])}'`
8690
: 'at the end',
87-
order,
88-
options: optionsString,
89-
notice: getDeprecationMessage(context.id),
9091
},
9192
})
9293
}

src/types/error.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export enum ErrorMessage {
2-
InterfaceParentInvalidOrder = `Found {{ unsortedCount }} key{{plural}} out of order.`,
3-
EnumParentInvalidOrder = `Found {{ unsortedCount }} member{{plural}} out of order.{{ notice }}`,
4-
InterfaceInvalidOrder = `Expected interface keys 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 }}`,
2+
InterfaceParentInvalidOrder = `Found {{ unsortedCount }} key{{plural}} out of {{ order }}ending {{ options }}order.`,
3+
EnumParentInvalidOrder = `Found {{ unsortedCount }} member{{plural}} out of {{ order }}ending {{ options }}order.{{ notice }}`,
4+
InterfaceInvalidOrder = `Property '{{ nodeName }}' should be {{ messageShouldBeWhere }}.`,
5+
EnumInvalidOrder = `Member '{{ nodeName }}' should be {{ messageShouldBeWhere }}.`,
66
}

src/utils/reportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function getUnsortedInfo(
4949
export function getDeprecationMessage(name: string) {
5050
switch (name) {
5151
case RuleNames.StringEnum:
52-
return `\nThis rule is deprecated. Use \`${PLUGIN_NAME}/${RuleNames.Enum}\` instead.`
52+
return `\nThis rule is deprecated: use \`${PLUGIN_NAME}/${RuleNames.Enum}\` instead.`
5353
default:
5454
return ''
5555
}

tests/helpers/cases/preprocess.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,21 @@ function processErrorArgs(
3737
}
3838

3939
if (!omitInferredErrorCount)
40-
errorMessages.push(getCountErrorString(category, errorArgs.length))
40+
errorMessages.push(getCountErrorString(category, optionsSetsKey, errorArgs.length))
4141

4242
for (const args of errorArgs) {
4343
// At this point args is number or string[]
4444
if (Array.isArray(args)) {
4545
switch (args.length) {
4646
case 1:
47-
errorMessages.push(getEndErrorString(category, optionsSetsKey, args[0]))
47+
errorMessages.push(getEndErrorString(category, args[0]))
4848
break
4949
case 2:
50-
errorMessages.push(
51-
getSwapErrorString(category, optionsSetsKey, args[0], args[1]),
52-
)
50+
errorMessages.push(getSwapErrorString(category, args[0], args[1]))
5351
break
5452
}
5553
} else {
56-
errorMessages.push(getCountErrorString(category, args))
54+
errorMessages.push(getCountErrorString(category, optionsSetsKey, args))
5755
}
5856
}
5957
return errorMessages

tests/helpers/strings.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export enum CaseCategory {
2828
function getCategoryErrorString(category: CaseCategory) {
2929
switch (category) {
3030
case CaseCategory.Interface:
31-
return 'interface keys'
31+
return 'Property'
3232
case CaseCategory.Enum:
3333
default:
34-
return 'enum members'
34+
return 'Member'
3535
}
3636
}
3737

@@ -45,27 +45,18 @@ function getCategoryParentErrorString(category: CaseCategory) {
4545
}
4646
}
4747

48-
export const getSwapErrorString = (
49-
category: CaseCategory,
50-
order: OptionsSetsKey,
51-
a: string,
52-
b: string,
53-
) => {
54-
return `Expected ${getCategoryErrorString(category)} to be in ${
55-
orderStrings[order]
56-
} order. '${a}' should be before '${b}'. Run autofix to sort entire body.`
48+
export const getSwapErrorString = (category: CaseCategory, a: string, b: string) => {
49+
return `${getCategoryErrorString(category)} '${a}' should be before '${b}'.`
5750
}
5851

59-
export const getEndErrorString = (
52+
export const getEndErrorString = (category: CaseCategory, a: string) =>
53+
`${getCategoryErrorString(category)} '${a}' should be at the end.`
54+
55+
export const getCountErrorString = (
6056
category: CaseCategory,
6157
order: OptionsSetsKey,
62-
a: string,
58+
count: number,
6359
) =>
64-
`Expected ${getCategoryErrorString(category)} to be in ${
65-
orderStrings[order]
66-
} order. '${a}' should be at the end. Run autofix to sort entire body.`
67-
68-
export const getCountErrorString = (category: CaseCategory, count: number) =>
6960
`Found ${count} ${getCategoryParentErrorString(category)}${
7061
count > 1 ? 's' : ''
71-
} out of order.`
62+
} out of ${orderStrings[order]} order.`

0 commit comments

Comments
 (0)