Skip to content

Commit

Permalink
Prevent data leakage in no-dupe-keys rule (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsnik committed Jan 2, 2018
1 parent dfcd26e commit 9096846
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const utils = require('../utils')
const GROUP_NAMES = ['props', 'computed', 'data', 'methods']

function create (context) {
const usedNames = []

const options = context.options[0] || {}
const groups = new Set(GROUP_NAMES.concat(options.groups || []))

Expand All @@ -23,7 +21,9 @@ function create (context) {
// ----------------------------------------------------------------------

return utils.executeOnVue(context, (obj) => {
const usedNames = []
const properties = utils.iterateProperties(obj, groups)

for (const o of properties) {
if (usedNames.indexOf(o.name) !== -1) {
context.report({
Expand All @@ -34,6 +34,7 @@ function create (context) {
}
})
}

usedNames.push(o.name)
}
})
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ ruleTester.run('no-dupe-keys', rule, {
}
`,
parserOptions: { ecmaVersion: 8, sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true }}
},

{
filename: 'test.js',
code: `
// @vue/component
export const compA = {
props: {
propA: String
}
}
// @vue/component
export const compB = {
props: {
propA: String
}
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
}
],

Expand Down

0 comments on commit 9096846

Please sign in to comment.