-
-
Save mysticatea/ce6ec16ace13192be1adc5d2f600eb29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Toru Nagashima <https://github.com/mysticatea> | |
* @copyright 2017 Toru Nagashima. All rights reserved. | |
* See LICENSE file in root directory for full license. | |
*/ | |
"use strict" | |
//------------------------------------------------------------------------------ | |
// Requirements | |
//------------------------------------------------------------------------------ | |
const utils = require("./utils") | |
//------------------------------------------------------------------------------ | |
// Helpers | |
//------------------------------------------------------------------------------ | |
/** | |
* Define this rule. | |
* @param {RuleContext} context The rule context. | |
* @returns {object} The AST visitor of this rule. | |
*/ | |
function create(context) { | |
utils.registerTemplateBodyVisitor(context, { | |
"HTMLAttribute[directive=true][key.name='else']"(node) { | |
if (utils.hasDirective(node.parent, "if")) { | |
context.report({ | |
node, | |
loc: node.loc, | |
message: "'v-else' directives disallow being with 'v-if' directives. You may want 'v-else-if' directives.", | |
}) | |
} | |
if (utils.hasDirective(node.parent, "else-if")) { | |
context.report({ | |
node, | |
loc: node.loc, | |
message: "'v-else' directives disallow being with 'v-else-if' directives.", | |
}) | |
} | |
if (!utils.prevElementHasIf(node.parent.parent)) { | |
context.report({ | |
node, | |
loc: node.loc, | |
message: "'v-else' directives require being preceded by a 'v-if' or 'v-else-if' directive.", | |
}) | |
} | |
if (node.key.argument) { | |
context.report({ | |
node, | |
loc: node.loc, | |
message: "'v-else' directives require no argument.", | |
}) | |
} | |
if (node.key.modifiers.length > 0) { | |
context.report({ | |
node, | |
loc: node.loc, | |
message: "'v-else' directives require no modifier.", | |
}) | |
} | |
if (node.value) { | |
context.report({ | |
node, | |
loc: node.loc, | |
message: "'v-else' directives require no attribute value.", | |
}) | |
} | |
}, | |
}) | |
return {} | |
} | |
//------------------------------------------------------------------------------ | |
// Exports | |
//------------------------------------------------------------------------------ | |
module.exports = {create} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment