Skip to content

Commit 5901983

Browse files
committed
Update rule
1 parent de72849 commit 5901983

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

lib/rules/prop-specificity.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,29 @@ function create (context) {
2929

3030
let nodes = []
3131
const type = node.value.type
32-
if (type === 'ObjectExpression') {
32+
if (type === 'ObjectExpression') { // props: {
3333
nodes = node.value.properties.map(cp => {
3434
const key = cp.key.name
3535
let value
36-
if (cp.value.type === 'ObjectExpression') {
36+
if (cp.value.type === 'ObjectExpression') { // foo: {
3737
value = cp.value.properties
3838
.filter(p =>
3939
p.key.type === 'Identifier' &&
40+
p.key.name === 'type' &&
4041
p.value.type === 'FunctionExpression'
4142
)
4243
.map(p => p.value.body)[0]
43-
} else if (type === 'ArrayExpression') {
44+
} else if (cp.value.type === 'ArrayExpression') { // foo: [
45+
if (cp.value.elements) {
4446

45-
} // TODO: literal
47+
}
48+
} else if (cp.value.type === 'FunctionExpression' || cp.value.type === 'ArrowFunctionExpression') {
49+
} else {
50+
value = cp
51+
}
4652
return { key, value }
4753
})
48-
} else if (type === 'ArrayExpression') {
54+
} else if (type === 'ArrayExpression') { // props: [
4955
// nodes = node.elements
5056
}
5157

@@ -67,7 +73,17 @@ function create (context) {
6773
utils.executeOnVueInstance(context, properties => {
6874
const data = getPropTypes(properties)
6975
if (data.type === 'ObjectExpression') {
70-
76+
data.nodes.forEach(cp => {
77+
if (!cp.value) {
78+
context.report({
79+
node: data.node,
80+
message: 'Prop "{{name}}" definitions should always be as detailed with at least type(s).',
81+
data: {
82+
name: cp.key
83+
}
84+
})
85+
}
86+
})
7187
} else if (data.type === 'ArrayExpression') {
7288
context.report({
7389
node: data.node,

tests/lib/rules/prop-specificity.js

+17
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ ruleTester.run('prop-specificity', rule, {
8686
message: 'Prop "foo" definitions should always be as detailed with at least type(s).',
8787
line: 4
8888
}]
89+
},
90+
{
91+
filename: 'test.vue',
92+
code: `
93+
export default {
94+
props: {
95+
foo: {
96+
type: []
97+
}
98+
}
99+
}
100+
`,
101+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
102+
errors: [{
103+
message: 'Prop "foo" definitions should always be as detailed with at least type(s).',
104+
line: 4
105+
}]
89106
}
90107
]
91108
})

0 commit comments

Comments
 (0)