Skip to content

Commit ea09562

Browse files
committed
Component data must be a function.
1 parent 67fccd8 commit ea09562

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/rules/component-data.js

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

2222
return Object.assign({},
23-
{
24-
// give me methods
25-
},
2623
utils.executeOnVueComponent(context, properties => {
27-
24+
const dataPropertiesNode = properties
25+
.filter(p =>
26+
p.key.type === 'Identifier' &&
27+
p.key.name === 'data' &&
28+
p.value.type !== 'FunctionExpression' &&
29+
p.value.type !== 'ArrowFunctionExpression'
30+
)
31+
32+
dataPropertiesNode.forEach(cp => {
33+
context.report({
34+
node: cp.value,
35+
message: 'Component `data` must be a function.'
36+
})
37+
})
2838
})
2939
)
3040
}

tests/lib/rules/component-data.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ruleTester.run('component-data', rule, {
6464
foo: 'bar'
6565
}
6666
}
67-
})
67+
}
6868
`,
6969
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
7070
}
@@ -82,7 +82,8 @@ ruleTester.run('component-data', rule, {
8282
`,
8383
parserOptions: { ecmaVersion: 6 },
8484
errors: [{
85-
message: 'Fill me in.'
85+
message: 'Component `data` must be a function.',
86+
line: 3
8687
}]
8788
},
8889
{
@@ -96,7 +97,8 @@ ruleTester.run('component-data', rule, {
9697
`,
9798
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
9899
errors: [{
99-
message: 'Fill me in.'
100+
message: 'Component `data` must be a function.',
101+
line: 3
100102
}]
101103
}
102104
]

0 commit comments

Comments
 (0)