Skip to content

Commit 5992614

Browse files
committed
Rename rule and add support for experimentalObjectRestSpread
1 parent 8f4c945 commit 5992614

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

docs/rules/component-data.md renamed to docs/rules/no-shared-component-data.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Enforces that a component data must be a function (component-data)
1+
# Enforces that a component data must be a function (no-shared-component-data)
22

33
When using the data property on a component (i.e. anywhere except on `new Vue`), the value must be a function that returns an object.
44

lib/rules/component-data.js renamed to lib/rules/no-shared-component-data.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
const utils = require('../utils')
88

99
function create (context) {
10-
// variables should be defined here
11-
12-
// ----------------------------------------------------------------------
13-
// Helpers
14-
// ----------------------------------------------------------------------
15-
16-
// any helper functions should go here or else delete this section
17-
1810
// ----------------------------------------------------------------------
1911
// Public
2012
// ----------------------------------------------------------------------
@@ -23,9 +15,11 @@ function create (context) {
2315
utils.executeOnVueComponent(context, (obj) => {
2416
obj.properties
2517
.filter(p =>
18+
p.type === 'Property' &&
2619
p.key.type === 'Identifier' &&
2720
p.key.name === 'data' &&
28-
p.value.type !== 'FunctionExpression'
21+
p.value.type !== 'FunctionExpression' &&
22+
p.value.type !== 'Identifier'
2923
).forEach(cp => {
3024
context.report({
3125
node: cp.value,

tests/lib/rules/component-data.js renamed to tests/lib/rules/no-shared-component-data.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
// Requirements
99
// ------------------------------------------------------------------------------
1010

11-
var rule = require('../../../lib/rules/component-data')
11+
const rule = require('../../../lib/rules/no-shared-component-data')
1212

1313
const RuleTester = require('eslint').RuleTester
1414

1515
// ------------------------------------------------------------------------------
1616
// Tests
1717
// ------------------------------------------------------------------------------
1818

19-
var ruleTester = new RuleTester()
20-
ruleTester.run('component-data', rule, {
19+
const ruleTester = new RuleTester()
20+
ruleTester.run('no-shared-component-data', rule, {
2121

2222
valid: [
2323
{
@@ -67,6 +67,24 @@ ruleTester.run('component-data', rule, {
6767
}
6868
`,
6969
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
70+
},
71+
{
72+
filename: 'test.vue',
73+
code: `
74+
export default {
75+
...foo
76+
}
77+
`,
78+
parserOptions: { ecmaVersion: 6, sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true }}
79+
},
80+
{
81+
filename: 'test.vue',
82+
code: `
83+
export default {
84+
data
85+
}
86+
`,
87+
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
7088
}
7189
],
7290

0 commit comments

Comments
 (0)