2020-12-15 12:23:40 +08:00
|
|
|
const MESSAGE_ID = "jsx-identifier-case";
|
|
|
|
|
|
2026-06-16 02:09:45 +08:00
|
|
|
// To ignore variables, config ESLint like this
|
2020-12-15 12:23:40 +08:00
|
|
|
// {'prettier-internal-rules/jsx-identifier-case': ['error', 'name1', ... 'nameN']}
|
|
|
|
|
|
2025-02-16 15:36:06 +08:00
|
|
|
export default {
|
2020-12-15 12:23:40 +08:00
|
|
|
meta: {
|
|
|
|
|
type: "suggestion",
|
|
|
|
|
messages: {
|
|
|
|
|
[MESSAGE_ID]: "Please rename '{{name}}' to '{{fixed}}'.",
|
|
|
|
|
},
|
|
|
|
|
fixable: "code",
|
2022-10-16 10:14:38 +09:00
|
|
|
schema: {
|
|
|
|
|
type: "array",
|
|
|
|
|
uniqueItems: true,
|
|
|
|
|
},
|
2020-12-15 12:23:40 +08:00
|
|
|
},
|
|
|
|
|
create(context) {
|
|
|
|
|
const ignored = new Set(context.options);
|
|
|
|
|
return {
|
|
|
|
|
"Identifier[name=/JSX/]:not(ObjectExpression > Property.properties > .key)"(
|
|
|
|
|
node,
|
|
|
|
|
) {
|
|
|
|
|
const { name } = node;
|
|
|
|
|
|
|
|
|
|
if (ignored.has(name)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 19:55:24 +08:00
|
|
|
const fixed = name.replaceAll("JSX", "Jsx");
|
2020-12-15 12:23:40 +08:00
|
|
|
context.report({
|
|
|
|
|
node,
|
|
|
|
|
messageId: MESSAGE_ID,
|
|
|
|
|
data: { name, fixed },
|
|
|
|
|
fix: (fixer) => fixer.replaceText(node, fixed),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|