pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
vue/no-parsing-error |
disallow parsing errors in `<template>` |
v3.0.0 |
vue/no-parsing-error
disallow parsing errors in
<template>
- ⚙️ This rule is included in all of
"plugin:vue/vue3-essential"
,"plugin:vue/essential"
,"plugin:vue/vue3-strongly-recommended"
,"plugin:vue/strongly-recommended"
,"plugin:vue/vue3-recommended"
and"plugin:vue/recommended"
.
This rule reports syntax errors in <template>
. For example:
- Syntax errors of scripts in directives.
- Syntax errors of scripts in mustaches.
- Syntax errors of HTML.
- Invalid end tags.
- Attributes in end tags.
- …
- See also: WHATWG HTML spec
📖 Rule Details
This rule tries to parse directives/mustaches in <template>
by the parser which parses <script>
.
Then reports syntax errors if exist.
<template> <!-- ✗ BAD --> {{ . }} {{ foo bar }} <div :class="*abc*" / @click="def("> </span> </div id="ghi"> </template>
🔧 Options
{ "vue/no-parsing-error": ["error", { "abrupt-closing-of-empty-comment": true, "absence-of-digits-in-numeric-character-reference": true, "cdata-in-html-content": true, "character-reference-outside-unicode-range": true, "control-character-in-input-stream": true, "control-character-reference": true, "eof-before-tag-name": true, "eof-in-cdata": true, "eof-in-comment": true, "eof-in-tag": true, "incorrectly-closed-comment": true, "incorrectly-opened-comment": true, "invalid-first-character-of-tag-name": true, "missing-attribute-value": true, "missing-end-tag-name": true, "missing-semicolon-after-character-reference": true, "missing-whitespace-between-attributes": true, "nested-comment": true, "noncharacter-character-reference": true, "noncharacter-in-input-stream": true, "null-character-reference": true, "surrogate-character-reference": true, "surrogate-in-input-stream": true, "unexpected-character-in-attribute-name": true, "unexpected-character-in-unquoted-attribute-value": true, "unexpected-equals-sign-before-attribute-name": true, "unexpected-null-character": true, "unexpected-question-mark-instead-of-tag-name": true, "unexpected-solidus-in-tag": true, "unknown-named-character-reference": true, "end-tag-with-attributes": true, "duplicate-attribute": true, "end-tag-with-trailing-solidus": true, "non-void-html-element-start-tag-with-trailing-solidus": false, "x-invalid-end-tag": true, "x-invalid-namespace": true }] }
You can disable HTML syntax errors by options. Please see WHATWG HTML spec to know the details of HTML syntax errors.
Only non-void-html-element-start-tag-with-trailing-solidus
is disabled by default because Vue.js supports self-closing tags.
::: warning Note
This rule does not support all of those (E.g., it does not catch errors about DOCTYPE).
:::
The error codes which have x-
prefix are original of this rule because errors in tree construction phase have not codified yet.
x-invalid-end-tag
enables the errors about the end tags of elements which have not opened.x-invalid-namespace
enables the errors about invalidxmlns
attributes. See also step 10. of «create an element for a token».
📚 Further Reading
- WHATWG HTML spec
🚀 Version
This rule was introduced in eslint-plugin-vue v3.0.0
🔍 Implementation
- Rule source
- Test source
Parsing error: x-invalid-end-tag
Info
- Platform: macOS 10.13.2
- Vetur version: 0.11.5
- VS Code version: 1.19.0
Problem
[eslint-plugin-vue]
[vue/no-parsing-error]
Parsing error: x-invalid-end-tag
Reproducible Case
I used iview
<template>
<div>
<Form>
<FormItem>
<Input type="text" v-model="value">
</Input>
</FormItem>
</Form>
</div>
</template>
worked fine in 0.11.3
Please do provide a reproduction example.
I have updated a reproduction example.
Thanks for the hard work.
I’m seeing the parsing error as well. Using iview tag as well. Started after the recent upgrade to Visual Studio code 1.19.0 I think.
Vetur: 0.11.5
VS Code: 1.19.0
Ubuntu platform
[eslint-plugin-vue]
[vue/no-parsing-error]
Parsing error: x-invalid-end-tag.
Have the same problems too , @HerringtonDarkholme How can I disable this rule without affect other rules ?
@HerringtonDarkholme this doesn’t work for me. And the sequence of the plugins installation by yarn, and rules setting, «false» or the default «off» etc confused me quite a lot. Also, couldn’t find any clue about the vetur.validation.template on the vetur plug github page. Please help.
Info
Platform: macOS 10.13.4
Vetur version: 0.12.4
VS Code version: 1.23.1
@HerringtonDarkholme The same problem in here. Maybe we can switch off the vetur.validation.template: false
, but I think it is not good idea. Can we fix this one?
Just adding my me too:
This triggers the lint error
<template>
<p>
<h1>
Items
</h1>
</p>
</template>
Switching h1
for strong
makes it go away
<template>
<section class="container">
<p>
<strong>
Items
</strong>
</p>
</template>
Info
Platform: macOS 10.13.4
Vetur version: 0.12.4
VS Code version: 1.23.1
@HerringtonDarkholme The same problem in here. Maybe we can switch off the
vetur.validation.template: false
, but I think it is not good idea. Can we fix this one?
MenuItem -> menu-item
I’m under the same error, anyone knows how to fix this? is getting really annoying! How can I disable this? I’m creating Row and Col from iViewUI and is giving me that error on the enclosing </Col>
EDIT: Seems that it can be fixed by using for some ui elements, you need to add the prefix i-
Try this:
// .eslintrc.js
module.exports = {
//...
rules: {
'vue/no-parsing-error': [2, { 'x-invalid-end-tag': false }]
}
}
Then you need to run your project again.
Just adding my me too:
This triggers the lint error
<template> <p> <h1> Items </h1> </p> </template>
Switching
h1
forstrong
makes it go away<template> <section class="container"> <p> <strong> Items </strong> </p> </template>
Just had the same issue. I thought about it for a bit and realized that maybe it doesn’t make sense to put h1
,h2
,… inside a p
tag.
Just had the same issue. I thought about it for a bit and realized that maybe it doesn’t make sense to put h1,h2,… inside a p tag.
If that’s the case, then the error message should say that.
i have the same question, need your help, wu wu wu~~~
Same issue for this simple code: <p><div></div></p>
UPD: «fixed» it by replacing it with <div style="margin: 16px 0"><div></div></div>
I’m having this exact issue… don’t want to replace the p
tag with div
though.
У меня есть компонент Vue JS, как это
<template>
<footer class="main-footer">
<p> <address>Some address</address> </p>
</footer>
</template>
Когда я запускаю vue-cli-service lint
, он изменяет открытие <p>
на <p />
и выдает следующую ошибку
error: Parsing error: x-invalid-end-tag (vue/no-parsing-error) at src/components/Footer.vue:3:46:
1 | <template>
2 | <footer class="main-footer">
> 3 | <p /><address>Some address</address> </p>
| ^
На самом деле, в моем веб-шторме закрывающий </p>
отмечен красным Closing tag matches nothing
.
Я взял тег address
, и он отлично работает. Есть ли причина, по которой я не могу использовать адресную метку?
Вот мой .eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/recommended',
'@vue/standard'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
indent: ['error', 4],
'space-before-function-paren': ['warn', 'never'],
'vue/require-default-prop': 'off',
'vue/no-v-html': 'off',
'vue/html-indent': ['error', 4]
},
parserOptions: {
parser: 'babel-eslint'
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
jest: true
}
}
]
}
2 ответа
Лучший ответ
< Сильный > ТЛ ; др :
Ошибка в том, что вы помещаете тег </p>
, у которого нет начального тега <p>
. Это потому, что вы думаете, что начальный тег автоматически закрывается анализатором в соответствии с официальная спецификация HTML из-за тега <address>
, следующего за тегом <p>
.
Более длинный (начальный) ответ:
Это ожидаемое поведение, как указано в официальной спецификации (Стандарт HTML). Соответственно:
Конечный тег элемента
p
может быть опущен, если за элементомp
сразу же следуютaddress
,article
,aside
,blockquote
, { {X6}},div
,dl
,fieldset
,figcaption
,figure
,footer
,form
, {{X14 }},h2
,h3
,h4
,h5
,h6
,header
,hgroup
,hr
,main
,menu
,nav
,ol
,p
,pre
,section
,table
илиul
или если в родительском элементе больше нет содержимого, а родительский элемент является элементом HTML, который не являетсяa
,audio
,del
, {{ X35}},map
,noscript
илиvideo
или автономный пользовательский элемент.
Что заставляет ваш элемент <p>
автоматически закрываться, когда синтаксический анализатор встречает элемент <address>
.
Поскольку вы, очевидно, не хотите такого поведения, вам следует использовать <div>
вместо элемента <p>
здесь, хотя, учитывая разметку в вашем вопросе, возможно, вам следует полностью отказаться от оболочки (т.е.: footer > address
) .
1
tao
16 Май 2020 в 15:41