1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

drop!: vue demo rule

This commit is contained in:
Marvin Hagemeister 2024-12-03 11:36:27 +01:00
parent a15c1165d6
commit 008e24937f
2 changed files with 42 additions and 2 deletions

10
foo.js
View file

@ -1 +1,11 @@
const foo = "baz123";
/* ✓ GOOD */
Vue.component("todo-item", {
// ...
});
/* ✗ BAD */
Vue.component("Todo", {
// ...
});

View file

@ -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("<name>", ...)`
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}"`,
});
}
}
},
};
},
},
},
};