Consistent Jsx case in variables (#9871)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-12-15 12:23:40 +08:00
1 parent 099ba04327
commit 89402482ee
12 files changed
+109 -61

No files matched your search

@@ -4,6 +4,7 @@ module.exports = {
rules: {
"better-parent-property-check-in-needs-parens": require("./better-parent-property-check-in-needs-parens"),
"directly-loc-start-end": require("./directly-loc-start-end"),
"jsx-identifier-case": require("./jsx-identifier-case"),
"no-node-comments": require("./no-node-comments"),
"prefer-fast-path-each": require("./prefer-fast-path-each"),
"require-json-extensions": require("./require-json-extensions"),
@@ -0,0 +1,46 @@
"use strict";
const MESSAGE_ID = "jsx-identifier-case";
// To ignore variables, config eslint like this
// {'prettier-internal-rules/jsx-identifier-case': ['error', 'name1', ... 'nameN']}
module.exports = {
meta: {
type: "suggestion",
docs: {
url:
"https://github.com/prettier/prettier/blob/master/scripts/eslint-plugin-prettier-internal-rules/jsx-identifier-case.js",
},
messages: {
[MESSAGE_ID]: "Please rename '{{name}}' to '{{fixed}}'.",
},
fixable: "code",
},
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;
}
const fixed = name.replace(/JSX/g, "Jsx");
context.report({
node,
messageId: MESSAGE_ID,
data: { name, fixed },
fix: (fixer) => fixer.replaceText(node, fixed),
});
},
};
},
schema: {
type: "array",
uniqueItems: true,
},
};