Skip to content

Commit 56d5f2d

Browse files
committed
Merge branch 'master' into patch-22-render-return
2 parents 76bf945 + 39c9df5 commit 56d5f2d

37 files changed

+729
-52
lines changed

docs/rules/no-dupe-keys.md

+78
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-reservered-keys.md

+54
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+
```

lib/rules/html-end-tags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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, {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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, {

lib/rules/html-quotes.js

+1-1
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/no-confusing-v-for-v-if.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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, {

lib/rules/no-dupe-keys.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @fileoverview Prevents duplication of field names.
3+
* @author Armano
4+
*/
5+
'use strict'
6+
7+
const utils = require('../utils')
8+
9+
// ------------------------------------------------------------------------------
10+
// Rule Definition
11+
// ------------------------------------------------------------------------------
12+
13+
const GROUP_NAMES = ['props', 'computed', 'data', 'methods']
14+
15+
function create (context) {
16+
const usedNames = []
17+
18+
const options = context.options[0] || {}
19+
const groups = new Set(GROUP_NAMES.concat(options.groups || []))
20+
21+
// ----------------------------------------------------------------------
22+
// Public
23+
// ----------------------------------------------------------------------
24+
25+
return utils.executeOnVue(context, (obj) => {
26+
const properties = utils.iterateProperties(obj, groups)
27+
for (const o of properties) {
28+
if (usedNames.indexOf(o.name) !== -1) {
29+
context.report({
30+
node: o.node,
31+
message: "Duplicated key '{{name}}'.",
32+
data: {
33+
name: o.name
34+
}
35+
})
36+
}
37+
usedNames.push(o.name)
38+
}
39+
})
40+
}
41+
42+
// ------------------------------------------------------------------------------
43+
// Rule Definition
44+
// ------------------------------------------------------------------------------
45+
46+
module.exports = {
47+
meta: {
48+
docs: {
49+
description: 'Prevents duplication of field names.',
50+
category: 'Possible Errors',
51+
recommended: false
52+
},
53+
fixable: null, // or "code" or "whitespace"
54+
schema: [
55+
{
56+
type: 'object',
57+
properties: {
58+
groups: {
59+
type: 'array'
60+
}
61+
},
62+
additionalProperties: false
63+
}
64+
]
65+
},
66+
67+
create
68+
}

lib/rules/no-duplicate-attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getName (attribute) {
3434
* Creates AST event handlers for no-duplicate-attributes.
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
const names = new Set()

lib/rules/no-invalid-template-root.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-template-root.
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/no-invalid-v-bind.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const VALID_MODIFIERS = new Set(['prop', 'camel', 'sync'])
2121
* Creates AST event handlers for no-invalid-v-bind.
2222
*
2323
* @param {RuleContext} context - The rule context.
24-
* @returns {object} AST event handlers.
24+
* @returns {Object} AST event handlers.
2525
*/
2626
function create (context) {
2727
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-cloak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-cloak.
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, {

lib/rules/no-invalid-v-else-if.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-else-if.
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, {

lib/rules/no-invalid-v-else.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-else.
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, {

lib/rules/no-invalid-v-for.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function checkKey (context, vFor, element) {
7474
* Creates AST event handlers for no-invalid-v-for.
7575
*
7676
* @param {RuleContext} context - The rule context.
77-
* @returns {object} AST event handlers.
77+
* @returns {Object} AST event handlers.
7878
*/
7979
function create (context) {
8080
const sourceCode = context.getSourceCode()

lib/rules/no-invalid-v-html.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-html.
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, {

lib/rules/no-invalid-v-if.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-if.
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, {

lib/rules/no-invalid-v-model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getVariable (name, leafNode) {
7777
* Creates AST event handlers for no-invalid-v-model.
7878
*
7979
* @param {RuleContext} context - The rule context.
80-
* @returns {object} AST event handlers.
80+
* @returns {Object} AST event handlers.
8181
*/
8282
function create (context) {
8383
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-on.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const VERB_MODIFIERS = new Set([
2828
* Creates AST event handlers for no-invalid-v-on.
2929
*
3030
* @param {RuleContext} context - The rule context.
31-
* @returns {object} AST event handlers.
31+
* @returns {Object} AST event handlers.
3232
*/
3333
function create (context) {
3434
utils.registerTemplateBodyVisitor(context, {

lib/rules/no-invalid-v-once.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-once.
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, {

lib/rules/no-invalid-v-pre.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-pre.
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, {

lib/rules/no-invalid-v-show.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-show.
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, {

lib/rules/no-invalid-v-text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const utils = require('../utils')
1919
* Creates AST event handlers for no-invalid-v-text.
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, {

lib/rules/no-parsing-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const DEFAULT_OPTIONS = Object.freeze(Object.assign(Object.create(null), {
5454
* Creates AST event handlers for no-parsing-error.
5555
*
5656
* @param {RuleContext} context - The rule context.
57-
* @returns {object} AST event handlers.
57+
* @returns {Object} AST event handlers.
5858
*/
5959
function create (context) {
6060
const options = Object.assign({}, DEFAULT_OPTIONS, context.options[0] || {})

0 commit comments

Comments
 (0)