Skip to content

Commit b53a8e0

Browse files
committed
Implement rule
1 parent 5901983 commit b53a8e0

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/rules/prop-specificity.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,21 @@ function create (context) {
3232
if (type === 'ObjectExpression') { // props: {
3333
nodes = node.value.properties.map(cp => {
3434
const key = cp.key.name
35-
let value
35+
let hasType = true
3636
if (cp.value.type === 'ObjectExpression') { // foo: {
37-
value = cp.value.properties
37+
hasType = !!(cp.value.properties
3838
.filter(p =>
3939
p.key.type === 'Identifier' &&
4040
p.key.name === 'type' &&
41-
p.value.type === 'FunctionExpression'
42-
)
43-
.map(p => p.value.body)[0]
41+
(
42+
p.value.type !== 'ArrayExpression' ||
43+
p.value.elements.length > 0
44+
)
45+
)[0])
4446
} else if (cp.value.type === 'ArrayExpression') { // foo: [
45-
if (cp.value.elements) {
46-
47-
}
48-
} else if (cp.value.type === 'FunctionExpression' || cp.value.type === 'ArrowFunctionExpression') {
49-
} else {
50-
value = cp
47+
hasType = cp.value.elements.length > 0
5148
}
52-
return { key, value }
49+
return { key, node: cp, hasType }
5350
})
5451
} else if (type === 'ArrayExpression') { // props: [
5552
// nodes = node.elements
@@ -74,9 +71,9 @@ function create (context) {
7471
const data = getPropTypes(properties)
7572
if (data.type === 'ObjectExpression') {
7673
data.nodes.forEach(cp => {
77-
if (!cp.value) {
74+
if (!cp.hasType) {
7875
context.report({
79-
node: data.node,
76+
node: cp.node || data.node,
8077
message: 'Prop "{{name}}" definitions should always be as detailed with at least type(s).',
8178
data: {
8279
name: cp.key

0 commit comments

Comments
 (0)