Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vue-eslint-parser #12

Merged
merged 12 commits into from
May 17, 2019
2 changes: 1 addition & 1 deletion lib/rules/alt-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ module.exports = {
}
}, altRule.create(context))
}
}
}
2 changes: 1 addition & 1 deletion lib/rules/anchor-has-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ module.exports = {
}
}, anchorRule.create(context))
}
}
}
4 changes: 2 additions & 2 deletions lib/rules/click-events-have-key-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
},
create (context) {
return VueUtils.defineTemplateBodyVisitor(context, {
"VAttribute[directive=true][key.name='on'][key.argument='click']" (node) {
"VAttribute[directive=true][key.name.name='on'][key.argument.name='click']" (node) {
const requiredEvents = ['keydown', 'keyup', 'keypress'];
const element = node.parent.parent;
if (VueUtils.isCustomComponent(element)) {
Expand All @@ -42,4 +42,4 @@ module.exports = {
}
}, JsxRule.create(context))
}
}
}
2 changes: 1 addition & 1 deletion lib/rules/no-access-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
return VueUtils.defineTemplateBodyVisitor(context, {
"VAttribute" (node) {
const isAccesskey = (!node.directive && node.key.name ==='accesskey')
|| (node.key.name === 'bind' && node.key.argument === 'accesskey')
|| (node.key.name.name === 'bind' && node.key.argument.name === 'accesskey')
if (!isAccesskey) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-autofocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
return VueUtils.defineTemplateBodyVisitor(context, {
"VAttribute" (node) {
const isAutofocus = (!node.directive && node.key.name ==='autofocus')
|| (node.key.name === 'bind' && node.key.argument === 'autofocus')
|| (node.key.name.name === 'bind' && node.key.argument.name === 'autofocus')
if (!isAutofocus) {
return;
}
Expand All @@ -46,4 +46,4 @@ module.exports = {
}
}, JsxRule.create(context))
}
}
}
4 changes: 2 additions & 2 deletions lib/rules/no-onchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
},
create (context) {
return VueUtils.defineTemplateBodyVisitor(context, {
"VAttribute[directive=true][key.name='on'][key.argument='change']" (node) {
"VAttribute[directive=true][key.name.name='on'][key.argument.name='change']" (node) {
const element = node.parent.parent;
const nodeType = utils.getElementType(element);

Expand All @@ -41,4 +41,4 @@ module.exports = {
}
}, JsxRule.create(context))
}
}
}
11 changes: 8 additions & 3 deletions lib/rules/tabindex-no-positive.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ module.exports = {
create (context) {
return VueUtils.defineTemplateBodyVisitor(context, {
"VAttribute" (node) {
const tabindex = (!node.directive && node.key.name ==='tabindex')
|| (node.key.name === 'bind' && node.key.argument === 'tabindex')
let tabindex;
if (node.directive) {
tabindex = node.key.argument.name === 'tabindex';
} else {
tabindex = node.key.name === 'tabindex';
}

if (!tabindex) {
return;
}

const value = utils.getAttributeValue(node);
// 获得value
if (value.type || +value <= 0) {
return;
}
Expand Down
18 changes: 14 additions & 4 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ module.exports = {
return (ariaLabelProp && this.hasAttributeValue(ariaLabelProp)) || (arialLabelledByProp && this.hasAttributeValue(arialLabelledByProp));
},
getAttribute (node, attr) {
return utils.getAttribute(node, attr) || utils.getDirective(node, 'bind', attr);
return utils.getAttribute(node, attr) || this.getDirective(node, 'bind', attr);
},
getDirective (node, name, argument) {
assert(node && node.type === 'VElement')
return node.startTag.attributes.find(a => {
return (
a.directive &&
a.key.name.name === name &&
(argument === undefined || a.key.argument.name === argument)
);
})
},
getElementType (node) { // return tagName
assert(node && node.type === 'VElement');
Expand Down Expand Up @@ -83,13 +93,13 @@ module.exports = {
hasAnyDirective (node, keyArray) {
assert(node && node.type === 'VElement');
return keyArray.some((key) => {
return utils.getDirective(node, key);
return this.getDirective(node, key);
});
},
hasAnyEvent (node, events) {
assert(node && node.type === 'VElement');
return events.some((event) => {
return utils.getDirective(node, 'on', event);
return this.getDirective(node, 'on', event);
});
},
hasAttributeValue (node) {
Expand Down Expand Up @@ -228,4 +238,4 @@ module.exports = {
})
return implicitRole
}
}
}