Skip to content

Commit 164b2ae

Browse files
armano2michalsnik
authored andcommitted
Fix small mistake in require-valid-default-prop (vuejs#143)
* Fix small mistakes in `require-valid-default-prop` - Improve coverage for FunctionExpression and ArrowFunctionExpression - Fix traversing over many types (return -> continue) * Cleanup code
1 parent a1fd26b commit 164b2ae

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lib/rules/require-valid-default-prop.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,20 @@ module.exports = {
102102

103103
for (const prop of properties) {
104104
const type = getPropertyNode(prop.value, 'type')
105-
if (!type) {
106-
return
107-
}
105+
if (!type) continue
108106

109107
const typeNames = new Set(getTypes(type.value)
110108
.map(item => item === 'Object' || item === 'Array' ? 'Function' : item) // Object and Array require function
111109
.filter(item => NATIVE_TYPES.has(item)))
112110

113-
if (typeNames.size === 0) { // There is no native types detected
114-
return
115-
}
111+
// There is no native types detected
112+
if (typeNames.size === 0) continue
116113

117114
const def = getPropertyNode(prop.value, 'default')
118-
if (!def) return
115+
if (!def) continue
119116

120117
const defType = getValueType(def.value)
121-
if (typeNames.has(defType)) return
118+
if (!defType || typeNames.has(defType)) continue
122119

123120
context.report({
124121
node: def,

tests/lib/rules/require-valid-default-prop.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ruleTester.run('require-valid-default-prop', rule, {
6565
foo: null,
6666
foo: Number,
6767
foo: [String, Number],
68+
foo: { type: Number, default: VAR_BAR },
6869
foo: { type: Number, default: 100 },
6970
foo: { type: [String, Number], default: '' },
7071
foo: { type: [String, Number], default: 0 },

0 commit comments

Comments
 (0)