Skip to content

Commit 3dd381f

Browse files
rewrite rule
1 parent 1aa1de6 commit 3dd381f

File tree

2 files changed

+139
-93
lines changed

2 files changed

+139
-93
lines changed

lib/rules/force-types-on-object-props.js

+8-27
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,6 @@ const utils = require('../utils')
1313
// Helpers
1414
// ------------------------------------------------------------------------------
1515

16-
/**
17-
* Check if all keys and values from second object are resent in first object
18-
*
19-
* @param {{ [key: string]: any }} a object to
20-
* @param {{ [key: string]: any }} b The string to escape.
21-
* @returns {boolean} Returns the escaped string.
22-
*/
23-
const isLooksLike = (a, b) =>
24-
a &&
25-
b &&
26-
Object.keys(b).every((bKey) => {
27-
const bVal = b[bKey]
28-
const aVal = a[bKey]
29-
if (typeof bVal === 'function') {
30-
return bVal(aVal)
31-
}
32-
return bVal == null || /^[bns]/.test(typeof bVal)
33-
? bVal === aVal
34-
: isLooksLike(aVal, bVal)
35-
})
36-
3716
/**
3817
* @param {ComponentProp} property
3918
* @param {RuleContext} context
@@ -44,7 +23,8 @@ const checkProperty = (property, context) => {
4423
}
4524

4625
if (
47-
isLooksLike(property.value, { type: 'Identifier', name: 'Object' }) &&
26+
property.value.type === 'Identifier' &&
27+
property.value.name === 'Object' &&
4828
property.node.value.type !== 'TSAsExpression'
4929
) {
5030
context.report({
@@ -58,16 +38,18 @@ const checkProperty = (property, context) => {
5838
property.value.type === 'ObjectExpression' &&
5939
property.node.value.type === 'ObjectExpression'
6040
) {
61-
const typePropert = property.node.value.properties.find(
41+
const typeProperty = property.node.value.properties.find(
6242
(prop) =>
6343
prop.type === 'Property' &&
6444
prop.key.type === 'Identifier' &&
6545
prop.key.name === 'type'
6646
)
6747
if (
68-
typePropert &&
69-
typePropert.type === 'Property' &&
70-
isLooksLike(typePropert.value, { type: 'Identifier', name: 'Object' })
48+
typeProperty &&
49+
typeProperty.type === 'Property' &&
50+
typeProperty.value.type === 'Identifier' &&
51+
typeProperty.value.name === 'Object'
52+
// isLooksLike(typeProperty.value, { type: 'Identifier', name: 'Object' })
7153
) {
7254
context.report({
7355
node: property.node,
@@ -134,7 +116,6 @@ module.exports = {
134116
type: 'suggestion',
135117
docs: {
136118
description: 'enforce adding type declarations to object props',
137-
categories: ['base'],
138119
recommended: false,
139120
url: 'https://eslint.vuejs.org/rules/force-types-on-object-props.html'
140121
},

0 commit comments

Comments
 (0)