Skip to content

Commit 26a63e1

Browse files
committed
Use parserServices.getDocumentFragment
1 parent 6524079 commit 26a63e1

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Diff for: lib/rules/component-tags-order.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ module.exports = {
3939
},
4040
create (context) {
4141
const order = (context.options[0] && context.options[0].order) || DEFAULT_ORDER
42+
const documentFragment = context.parserServices.getDocumentFragment && context.parserServices.getDocumentFragment()
4243

43-
function getTopLevelHTMLElements (node) {
44-
const templateBody = node.templateBody
45-
if (templateBody) {
46-
const document = templateBody.parent
47-
return document.children
44+
function getTopLevelHTMLElements () {
45+
if (documentFragment) {
46+
return documentFragment.children
4847
}
4948
return []
5049
}
@@ -70,7 +69,7 @@ module.exports = {
7069
if (utils.hasInvalidEOF(node)) {
7170
return
7271
}
73-
const elements = getTopLevelHTMLElements(node)
72+
const elements = getTopLevelHTMLElements()
7473

7574
elements.forEach((element, index) => {
7675
const expectedIndex = order.indexOf(element.name)

Diff for: tests/lib/rules/component-tags-order.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const RuleTester = require('eslint').RuleTester
1515
// ------------------------------------------------------------------------------
1616

1717
const tester = new RuleTester({
18-
parser: 'vue-eslint-parser'
18+
parser: require.resolve('vue-eslint-parser')
1919
})
2020

2121
tester.run('component-tags-order', rule, {
@@ -64,8 +64,6 @@ tester.run('component-tags-order', rule, {
6464
options: [{ order: ['docs', 'script', 'template', 'style'] }]
6565
},
6666

67-
// No template (can not check)
68-
`<style></style><script></script>`,
6967
`<script></script><style></style>`,
7068

7169
// Invalid EOF
@@ -201,6 +199,19 @@ tester.run('component-tags-order', rule, {
201199
line: 5
202200
}
203201
]
202+
},
203+
// no <template>
204+
{
205+
code: `
206+
<style></style>
207+
<script></script>
208+
`,
209+
errors: [
210+
{
211+
message: 'The <script> should be above the <style> on line 2.',
212+
line: 3
213+
}
214+
]
204215
}
205216
]
206217
})

0 commit comments

Comments
 (0)