Skip to content

Commit

Permalink
Use parserServices.getDocumentFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Nov 13, 2019
1 parent aa75a86 commit 6a6543a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 5 additions & 6 deletions lib/rules/component-tags-order.js
Expand Up @@ -39,12 +39,11 @@ module.exports = {
},
create (context) {
const order = (context.options[0] && context.options[0].order) || DEFAULT_ORDER
const documentFragment = context.parserServices.getDocumentFragment && context.parserServices.getDocumentFragment()

function getTopLevelHTMLElements (node) {
const templateBody = node.templateBody
if (templateBody) {
const document = templateBody.parent
return document.children
function getTopLevelHTMLElements () {
if (documentFragment) {
return documentFragment.children
}
return []
}
Expand All @@ -70,7 +69,7 @@ module.exports = {
if (utils.hasInvalidEOF(node)) {
return
}
const elements = getTopLevelHTMLElements(node)
const elements = getTopLevelHTMLElements()

elements.forEach((element, index) => {
const expectedIndex = order.indexOf(element.name)
Expand Down
17 changes: 14 additions & 3 deletions tests/lib/rules/component-tags-order.js
Expand Up @@ -15,7 +15,7 @@ const RuleTester = require('eslint').RuleTester
// ------------------------------------------------------------------------------

const tester = new RuleTester({
parser: 'vue-eslint-parser'
parser: require.resolve('vue-eslint-parser')
})

tester.run('component-tags-order', rule, {
Expand Down Expand Up @@ -64,8 +64,6 @@ tester.run('component-tags-order', rule, {
options: [{ order: ['docs', 'script', 'template', 'style'] }]
},

// No template (can not check)
`<style></style><script></script>`,
`<script></script><style></style>`,

// Invalid EOF
Expand Down Expand Up @@ -201,6 +199,19 @@ tester.run('component-tags-order', rule, {
line: 5
}
]
},
// no <template>
{
code: `
<style></style>
<script></script>
`,
errors: [
{
message: 'The <script> should be above the <style> on line 2.',
line: 3
}
]
}
]
})

0 comments on commit 6a6543a

Please sign in to comment.