diff --git a/foo.js b/foo.js index 11a11b1af9..38a3427efe 100644 --- a/foo.js +++ b/foo.js @@ -1 +1,11 @@ const foo = "baz123"; + +/* ✓ GOOD */ +Vue.component("todo-item", { + // ... +}); + +/* ✗ BAD */ +Vue.component("Todo", { + // ... +}); diff --git a/plugin.js b/plugin.js index 283a969cc4..492803f6a1 100644 --- a/plugin.js +++ b/plugin.js @@ -4,11 +4,12 @@ const RULE1_NAME = "first-rule"; const rule = { create(context) { + console.log("GOGO", context); console.log("Hello from", `${PLUGIN_NAME}/${RULE1_NAME}`); context.report({ span: { - start: 6, - end: 9, + start: 7, + end: 10, }, message: "Error from " + `${PLUGIN_NAME}/${RULE1_NAME}`, data: { @@ -64,6 +65,35 @@ export default { name: PLUGIN_NAME, rules: { [RULE1_NAME]: rule, + "vue/multi-word-component-names": { + create(context) { + return { + CallExpression(node) { + // Check for component name in `Vue.component("", ...)` + if ( + node.callee.type === "MemberExpression" && + node.callee.object.type === "Identifier" && + node.callee.object.value === "Vue" && + node.callee.property.type === "Identifier" && + node.callee.property.value === "component" && + node.arguments.length > 0 && + node.arguments[0].expression.type === "StringLiteral" + ) { + const name = node.arguments[0].expression.value; + + const numUpper = name.length - name.replace(/[A-Z]/g, "").length; + if (!name.includes("-") || numUpper.length < 2) { + context.report({ + node: node.arguments[0].expression, + message: + `Component names must be composed of multiple words, but got "${name}"`, + }); + } + } + }, + }; + }, + }, }, };