Skip to content

Commit 2466553

Browse files
committed
Merge branch 'master' into patch-15-html-attributes-casing
2 parents 50dce57 + 39c9df5 commit 2466553

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3330
-529
lines changed

docs/rules/no-dupe-keys.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Prevents duplication of field names (no-dupe-keys)
2+
3+
This rule prevents to use duplicated names.
4+
5+
## :book: Rule Details
6+
7+
This rule is aimed at preventing duplicated property names.
8+
9+
:-1: Examples of **incorrect** code for this rule:
10+
11+
```js
12+
export default {
13+
props: {
14+
foo: String
15+
},
16+
computed: {
17+
foo: {
18+
get () {
19+
}
20+
}
21+
},
22+
data: {
23+
foo: null
24+
},
25+
methods: {
26+
foo () {
27+
}
28+
}
29+
}
30+
```
31+
32+
:+1: Examples of **correct** code for this rule:
33+
34+
```js
35+
export default {
36+
props: ['foo'],
37+
computed: {
38+
bar () {
39+
}
40+
},
41+
data () {
42+
return {
43+
dat: null
44+
}
45+
},
46+
methods: {
47+
test () {
48+
}
49+
}
50+
}
51+
```
52+
53+
## :wrench: Options
54+
55+
This rule has an object option:
56+
57+
`"groups"`: [] (default) array of additional groups to search for duplicates.
58+
59+
### Example:
60+
61+
```
62+
vue/no-dupe-keys: [2, {
63+
groups: ['asyncComputed']
64+
}]
65+
```
66+
67+
:-1: Examples of **incorrect** code for this configuration
68+
69+
```js
70+
export default {
71+
computed: {
72+
foo () {}
73+
},
74+
asyncComputed: {
75+
foo () {}
76+
}
77+
}
78+
```

docs/rules/no-parsing-error.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Disallow parsing errors in `<template>` (no-parsing-error)
22

3-
This rule reports syntax errors in directives/mustaches of `<template>`.
3+
This rule reports syntax errors in `<template>`. For example:
4+
5+
- Syntax errors of scripts in directives.
6+
- Syntax errors of scripts in mustaches.
7+
- Syntax errors of HTML.
8+
- Invalid end tags.
9+
- Attributes in end tags.
10+
- ...
11+
- See also: https://html.spec.whatwg.org/multipage/parsing.html#parse-errors
412

513
## :book: Rule Details
614

@@ -25,4 +33,56 @@ Then reports syntax errors if exist.
2533

2634
## :wrench: Options
2735

28-
Nothing.
36+
```json
37+
{
38+
"vue/no-parsing-error": ["error", {
39+
"abrupt-closing-of-empty-comment": false,
40+
"absence-of-digits-in-numeric-character-reference": false,
41+
"cdata-in-html-content": false,
42+
"character-reference-outside-unicode-range": false,
43+
"control-character-in-input-stream": false,
44+
"control-character-reference": false,
45+
"eof-before-tag-name": false,
46+
"eof-in-cdata": false,
47+
"eof-in-comment": false,
48+
"eof-in-tag": false,
49+
"incorrectly-closed-comment": false,
50+
"incorrectly-opened-comment": false,
51+
"invalid-first-character-of-tag-name": false,
52+
"missing-attribute-value": false,
53+
"missing-end-tag-name": false,
54+
"missing-semicolon-after-character-reference": false,
55+
"missing-whitespace-between-attributes": false,
56+
"nested-comment": false,
57+
"noncharacter-character-reference": false,
58+
"noncharacter-in-input-stream": false,
59+
"null-character-reference": false,
60+
"surrogate-character-reference": false,
61+
"surrogate-in-input-stream": false,
62+
"unexpected-character-in-attribute-name": false,
63+
"unexpected-character-in-unquoted-attribute-value": false,
64+
"unexpected-equals-sign-before-attribute-name": false,
65+
"unexpected-null-character": false,
66+
"unexpected-question-mark-instead-of-tag-name": false,
67+
"unexpected-solidus-in-tag": false,
68+
"unknown-named-character-reference": false,
69+
"end-tag-with-attributes": false,
70+
"duplicate-attribute": false,
71+
"end-tag-with-trailing-solidus": false,
72+
"non-void-html-element-start-tag-with-trailing-solidus": false,
73+
"x-invalid-end-tag": false,
74+
"x-invalid-namespace": false
75+
}]
76+
}
77+
```
78+
79+
You can enable HTML syntax errors by opt-in.
80+
81+
For example, if `"x-invalid-end-tag": true` is given then this rule will catch the end tags of elements which have not opened.
82+
The error codes are defined in [WHATWG spec](https://html.spec.whatwg.org/multipage/parsing.html#parse-errors), but this rule does not support all of those (E.g., it does not catch errors about DOCTYPE).
83+
Also, The codes which have `x-` prefix are original in this rule because errors in tree construction phase have not codified yet.
84+
85+
- `x-invalid-end-tag` enables the errors about the end tags of elements which have not opened.
86+
- `x-invalid-namespace` enables the errors about invalid `xmlns` attributes. See also [step 10. of "create an element for a token"](https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token).
87+
88+
> TODO(mysticatea): I will revisit errors in tree construction phase after those are codified.

docs/rules/no-reservered-keys.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Prevent overwrite reserved keys (no-reservered-keys)
2+
3+
This rule prevents to use reserved names from to avoid conflicts and unexpected behavior.
4+
5+
## Rule Details
6+
7+
:-1: Examples of **incorrect** code for this rule:
8+
9+
```js
10+
export default {
11+
props: {
12+
$el: String
13+
},
14+
computed: {
15+
$on: {
16+
get () {
17+
}
18+
}
19+
},
20+
data: {
21+
_foo: null
22+
},
23+
methods: {
24+
$nextTick () {
25+
}
26+
}
27+
}
28+
```
29+
30+
## :wrench: Options
31+
32+
This rule has an object option:
33+
34+
`"reserved"`: [] (default) array of dissalowed names inside `groups`.
35+
36+
`"groups"`: [] (default) array of additional groups to search for duplicates.
37+
38+
### Example:
39+
40+
```
41+
vue/no-dupe-keys: [2, {
42+
reserved: ['foo']
43+
}]
44+
```
45+
46+
:-1: Examples of **incorrect** code for this configuration
47+
48+
```js
49+
export default {
50+
computed: {
51+
foo () {}
52+
}
53+
}
54+
```

docs/rules/require-prop-types.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Prop definitions should be detailed (require-prop-types)
2+
3+
In committed code, prop definitions should always be as detailed as possible, specifying at least type(s).
4+
5+
## :book: Rule Details
6+
7+
This rule enforces that a `props` statement contains type definition.
8+
9+
:-1: Examples of **incorrect** code for this rule:
10+
11+
```js
12+
export default {
13+
props: ['status']
14+
}
15+
```
16+
17+
:+1: Examples of **correct** code for this rule:
18+
19+
```js
20+
export default {
21+
props: {
22+
status: String
23+
}
24+
}
25+
```
26+
27+
```js
28+
export default {
29+
props: {
30+
status: {
31+
type: String,
32+
required: true,
33+
validate: function (value) {
34+
return ['syncing', 'synced', 'version-conflict', 'error'].indexOf(value) !== -1
35+
}
36+
}
37+
}
38+
}
39+
```
40+
## :wrench: Options
41+
42+
Nothing.

lib/rules/html-end-tags.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ const utils = require('../utils')
1919
* Creates AST event handlers for html-end-tags.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {
2626
VElement (node) {
27-
const name = node.startTag.id.name
27+
const name = node.name
2828
const isVoid = utils.isVoidElementName(name)
2929
const hasEndTag = node.endTag != null
3030

lib/rules/html-no-self-closing.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,27 @@ const utils = require('../utils')
1919
* Creates AST event handlers for html-no-self-closing.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
utils.registerTemplateBodyVisitor(context, {
26-
'VStartTag[selfClosing=true]' (node) {
27-
if (!utils.isSvgElementName(node.id.name) && !utils.isMathMLElementName(node.id.name)) {
28-
const pos = node.range[1] - 2
29-
context.report({
30-
node,
31-
loc: node.loc,
32-
message: 'Self-closing should not be used.',
33-
fix: (fixer) => fixer.removeRange([pos, pos + 1])
34-
})
26+
'VElement' (node) {
27+
if (utils.isSvgElementName(node.name)) {
28+
return
3529
}
30+
31+
const sourceCode = context.parserServices.getTemplateBodyTokenStore(context)
32+
const lastToken = sourceCode.getLastToken(node.startTag)
33+
if (lastToken.type !== 'HTMLSelfClosingTagClose') {
34+
return
35+
}
36+
37+
context.report({
38+
node: lastToken,
39+
loc: lastToken.loc,
40+
message: 'Self-closing should not be used.',
41+
fix: (fixer) => fixer.removeRange([lastToken.range[0], lastToken.range[0] + 1])
42+
})
3643
}
3744
})
3845

@@ -49,8 +56,10 @@ module.exports = {
4956
docs: {
5057
description: 'disallow self-closing elements.',
5158
category: 'Best Practices',
52-
recommended: false
59+
recommended: false,
60+
replacedBy: []
5361
},
62+
deprecated: true,
5463
fixable: 'code',
5564
schema: []
5665
}

lib/rules/html-quotes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for html-quotes.
2020
*
2121
* @param {RuleContext} context - The rule context.
22-
* @returns {object} AST event handlers.
22+
* @returns {Object} AST event handlers.
2323
*/
2424
function create (context) {
2525
const sourceCode = context.getSourceCode()

lib/rules/name-property-casing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function create (context) {
2121

2222
return utils.executeOnVue(context, (obj) => {
2323
const node = obj.properties
24-
.filter(item => (
24+
.find(item => (
2525
item.type === 'Property' &&
2626
item.key.name === 'name' &&
2727
item.value.type === 'Literal'
28-
))[0]
28+
))
2929

3030
if (!node) return
3131

lib/rules/no-confusing-v-for-v-if.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ function isUsingIterationVar (vIf) {
3434
* Creates AST event handlers for no-confusing-v-for-v-if.
3535
*
3636
* @param {RuleContext} context - The rule context.
37-
* @returns {object} AST event handlers.
37+
* @returns {Object} AST event handlers.
3838
*/
3939
function create (context) {
4040
utils.registerTemplateBodyVisitor(context, {
4141
"VAttribute[directive=true][key.name='if']" (node) {
42-
if (utils.hasDirective(node.parent, 'for') && !isUsingIterationVar(node)) {
42+
const element = node.parent.parent
43+
44+
if (utils.hasDirective(element, 'for') && !isUsingIterationVar(node)) {
4345
context.report({
4446
node,
4547
loc: node.loc,

0 commit comments

Comments
 (0)