Skip to content

Commit 9096846

Browse files
authored
Prevent data leakage in no-dupe-keys rule (#317)
1 parent dfcd26e commit 9096846

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Diff for: lib/rules/no-dupe-keys.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ const utils = require('../utils')
1313
const GROUP_NAMES = ['props', 'computed', 'data', 'methods']
1414

1515
function create (context) {
16-
const usedNames = []
17-
1816
const options = context.options[0] || {}
1917
const groups = new Set(GROUP_NAMES.concat(options.groups || []))
2018

@@ -23,7 +21,9 @@ function create (context) {
2321
// ----------------------------------------------------------------------
2422

2523
return utils.executeOnVue(context, (obj) => {
24+
const usedNames = []
2625
const properties = utils.iterateProperties(obj, groups)
26+
2727
for (const o of properties) {
2828
if (usedNames.indexOf(o.name) !== -1) {
2929
context.report({
@@ -34,6 +34,7 @@ function create (context) {
3434
}
3535
})
3636
}
37+
3738
usedNames.push(o.name)
3839
}
3940
})

Diff for: tests/lib/rules/no-dupe-keys.js

+20
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ ruleTester.run('no-dupe-keys', rule, {
8080
}
8181
`,
8282
parserOptions: { ecmaVersion: 8, sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true }}
83+
},
84+
85+
{
86+
filename: 'test.js',
87+
code: `
88+
// @vue/component
89+
export const compA = {
90+
props: {
91+
propA: String
92+
}
93+
}
94+
95+
// @vue/component
96+
export const compB = {
97+
props: {
98+
propA: String
99+
}
100+
}
101+
`,
102+
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
83103
}
84104
],
85105

0 commit comments

Comments
 (0)