mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
drop!: vue demo rule
This commit is contained in:
parent
a15c1165d6
commit
008e24937f
2 changed files with 42 additions and 2 deletions
10
foo.js
10
foo.js
|
@ -1 +1,11 @@
|
||||||
const foo = "baz123";
|
const foo = "baz123";
|
||||||
|
|
||||||
|
/* ✓ GOOD */
|
||||||
|
Vue.component("todo-item", {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ✗ BAD */
|
||||||
|
Vue.component("Todo", {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
34
plugin.js
34
plugin.js
|
@ -4,11 +4,12 @@ const RULE1_NAME = "first-rule";
|
||||||
|
|
||||||
const rule = {
|
const rule = {
|
||||||
create(context) {
|
create(context) {
|
||||||
|
console.log("GOGO", context);
|
||||||
console.log("Hello from", `${PLUGIN_NAME}/${RULE1_NAME}`);
|
console.log("Hello from", `${PLUGIN_NAME}/${RULE1_NAME}`);
|
||||||
context.report({
|
context.report({
|
||||||
span: {
|
span: {
|
||||||
start: 6,
|
start: 7,
|
||||||
end: 9,
|
end: 10,
|
||||||
},
|
},
|
||||||
message: "Error from " + `${PLUGIN_NAME}/${RULE1_NAME}`,
|
message: "Error from " + `${PLUGIN_NAME}/${RULE1_NAME}`,
|
||||||
data: {
|
data: {
|
||||||
|
@ -64,6 +65,35 @@ export default {
|
||||||
name: PLUGIN_NAME,
|
name: PLUGIN_NAME,
|
||||||
rules: {
|
rules: {
|
||||||
[RULE1_NAME]: rule,
|
[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}"`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue