Skip to content

Commit 4b5eb72

Browse files
author
maranran
authored
Merge pull request #12 from sawa-zen/update-eslint-parser
Update vue-eslint-parser
2 parents 79aef6c + c3a2bfa commit 4b5eb72

14 files changed

+432
-180
lines changed

lib/rules/alt-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ module.exports = {
142142
}
143143
}, altRule.create(context))
144144
}
145-
}
145+
}

lib/rules/anchor-has-content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ module.exports = {
3737
}
3838
}, anchorRule.create(context))
3939
}
40-
}
40+
}

lib/rules/click-events-have-key-events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
},
1919
create (context) {
2020
return VueUtils.defineTemplateBodyVisitor(context, {
21-
"VAttribute[directive=true][key.name='on'][key.argument='click']" (node) {
21+
"VAttribute[directive=true][key.name.name='on'][key.argument.name='click']" (node) {
2222
const requiredEvents = ['keydown', 'keyup', 'keypress'];
2323
const element = node.parent.parent;
2424
if (VueUtils.isCustomComponent(element)) {
@@ -42,4 +42,4 @@ module.exports = {
4242
}
4343
}, JsxRule.create(context))
4444
}
45-
}
45+
}

lib/rules/no-access-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
return VueUtils.defineTemplateBodyVisitor(context, {
2828
"VAttribute" (node) {
2929
const isAccesskey = (!node.directive && node.key.name ==='accesskey')
30-
|| (node.key.name === 'bind' && node.key.argument === 'accesskey')
30+
|| (node.key.name.name === 'bind' && node.key.argument.name === 'accesskey')
3131
if (!isAccesskey) {
3232
return;
3333
}

lib/rules/no-autofocus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
return VueUtils.defineTemplateBodyVisitor(context, {
2626
"VAttribute" (node) {
2727
const isAutofocus = (!node.directive && node.key.name ==='autofocus')
28-
|| (node.key.name === 'bind' && node.key.argument === 'autofocus')
28+
|| (node.key.name.name === 'bind' && node.key.argument.name === 'autofocus')
2929
if (!isAutofocus) {
3030
return;
3131
}
@@ -46,4 +46,4 @@ module.exports = {
4646
}
4747
}, JsxRule.create(context))
4848
}
49-
}
49+
}

lib/rules/no-onchange.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = {
2323
},
2424
create (context) {
2525
return VueUtils.defineTemplateBodyVisitor(context, {
26-
"VAttribute[directive=true][key.name='on'][key.argument='change']" (node) {
26+
"VAttribute[directive=true][key.name.name='on'][key.argument.name='change']" (node) {
2727
const element = node.parent.parent;
2828
const nodeType = utils.getElementType(element);
2929

@@ -41,4 +41,4 @@ module.exports = {
4141
}
4242
}, JsxRule.create(context))
4343
}
44-
}
44+
}

lib/rules/tabindex-no-positive.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ module.exports = {
2323
create (context) {
2424
return VueUtils.defineTemplateBodyVisitor(context, {
2525
"VAttribute" (node) {
26-
const tabindex = (!node.directive && node.key.name ==='tabindex')
27-
|| (node.key.name === 'bind' && node.key.argument === 'tabindex')
26+
let tabindex;
27+
if (node.directive) {
28+
tabindex = node.key.argument.name === 'tabindex';
29+
} else {
30+
tabindex = node.key.name === 'tabindex';
31+
}
32+
2833
if (!tabindex) {
2934
return;
3035
}
36+
3137
const value = utils.getAttributeValue(node);
32-
// 获得value
3338
if (value.type || +value <= 0) {
3439
return;
3540
}

lib/utils/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ module.exports = {
5555
return (ariaLabelProp && this.hasAttributeValue(ariaLabelProp)) || (arialLabelledByProp && this.hasAttributeValue(arialLabelledByProp));
5656
},
5757
getAttribute (node, attr) {
58-
return utils.getAttribute(node, attr) || utils.getDirective(node, 'bind', attr);
58+
return utils.getAttribute(node, attr) || this.getDirective(node, 'bind', attr);
59+
},
60+
getDirective (node, name, argument) {
61+
assert(node && node.type === 'VElement')
62+
return node.startTag.attributes.find(a => {
63+
return (
64+
a.directive &&
65+
a.key.name.name === name &&
66+
(argument === undefined || a.key.argument.name === argument)
67+
);
68+
})
5969
},
6070
getElementType (node) { // return tagName
6171
assert(node && node.type === 'VElement');
@@ -83,13 +93,13 @@ module.exports = {
8393
hasAnyDirective (node, keyArray) {
8494
assert(node && node.type === 'VElement');
8595
return keyArray.some((key) => {
86-
return utils.getDirective(node, key);
96+
return this.getDirective(node, key);
8797
});
8898
},
8999
hasAnyEvent (node, events) {
90100
assert(node && node.type === 'VElement');
91101
return events.some((event) => {
92-
return utils.getDirective(node, 'on', event);
102+
return this.getDirective(node, 'on', event);
93103
});
94104
},
95105
hasAttributeValue (node) {
@@ -228,4 +238,4 @@ module.exports = {
228238
})
229239
return implicitRole
230240
}
231-
}
241+
}

0 commit comments

Comments
 (0)