maxItems: 2
}
]
+ },
+
+ messages: {
+ expectedAllPropertiesShorthanded: "Expected shorthand for all properties.",
+ expectedLiteralMethodLongform: "Expected longform method syntax for string literal keys.",
+ expectedPropertyShorthand: "Expected property shorthand.",
+ expectedPropertyLongform: "Expected longform property syntax.",
+ expectedMethodShorthand: "Expected method shorthand.",
+ expectedMethodLongform: "Expected longform method syntax.",
+ unexpectedMix: "Unexpected mix of shorthand and non-shorthand properties."
}
},
// We have at least 1 shorthand property
if (shorthandProperties.length > 0) {
- context.report({ node, message: "Unexpected mix of shorthand and non-shorthand properties." });
+ context.report({ node, messageId: "unexpectedMix" });
} else if (checkRedundancy) {
/*
const canAlwaysUseShorthand = properties.every(isRedundant);
if (canAlwaysUseShorthand) {
- context.report({ node, message: "Expected shorthand for all properties." });
+ context.report({ node, messageId: "expectedAllPropertiesShorthanded" });
}
}
}
// Checks for property/method shorthand.
if (isConciseProperty) {
if (node.method && (APPLY_NEVER || AVOID_QUOTES && isStringLiteral(node.key))) {
- const message = APPLY_NEVER ? "Expected longform method syntax." : "Expected longform method syntax for string literal keys.";
+ const messageId = APPLY_NEVER ? "expectedMethodLongform" : "expectedLiteralMethodLongform";
// { x() {} } should be written as { x: function() {} }
context.report({
node,
- message,
+ messageId,
fix: fixer => makeFunctionLongform(fixer, node)
});
} else if (APPLY_NEVER) {
// { x } should be written as { x: x }
context.report({
node,
- message: "Expected longform property syntax.",
+ messageId: "expectedPropertyLongform",
fix: fixer => fixer.insertTextAfter(node.key, `: ${node.key.name}`)
});
}
) {
context.report({
node,
- message: "Expected method shorthand.",
+ messageId: "expectedMethodShorthand",
fix: fixer => makeFunctionShorthand(fixer, node)
});
}
// {x: x} should be written as {x}
context.report({
node,
- message: "Expected property shorthand.",
+ messageId: "expectedPropertyShorthand",
fix(fixer) {
return fixer.replaceText(node, node.value.name);
}
// {"x": x} should be written as {x}
context.report({
node,
- message: "Expected property shorthand.",
+ messageId: "expectedPropertyShorthand",
fix(fixer) {
return fixer.replaceText(node, node.value.name);
}