eslint-plugin-react-native-require-testid
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -12,20 +12,29 @@ module.exports = { | ||
}, | ||
create(context) { | ||
return { | ||
JSXOpeningElement(node) { | ||
const elementName = node.name.name; | ||
const hasTestIDAttribute = node.attributes.some( | ||
(attr) => | ||
attr.type === "JSXAttribute" && | ||
attr.name.name === "testID" | ||
); | ||
if(!hasTestIDAttribute) { | ||
context.report({ | ||
node, | ||
message: `React Native component <${elementName}> should have a testID attribute.`, | ||
}); | ||
} | ||
rules: { | ||
"testid-missing": { | ||
create(context) { | ||
return { | ||
JSXOpeningElement(node) { | ||
const { name, attributes } = node; | ||
if (!name || !name.name) { | ||
return; // Return early if name or name.name is undefined | ||
} | ||
const componentName = name.name; | ||
const hasTestIDAttribute = attributes.some( | ||
(attribute) => | ||
attribute.name && attribute.name.name === "testID" // Check if attribute.name is defined before accessing its name property | ||
); | ||
if (!hasTestIDAttribute) { | ||
context.report({ | ||
node: name, | ||
message: `React Native component <${componentName}> should have a testID attribute.`, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
}, | ||
}, | ||
}; |
{ | ||
"name": "eslint-plugin-react-native-require-testid", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -16,7 +16,7 @@ # eslint-plugin-react-native-require-testid | ||
{ | ||
"plugins": ["react-native-enforce-testid"], | ||
"plugins": ["react-native-require-testid"], | ||
"rules": { | ||
"react-native-enforce-testid/testid-missing": "error" | ||
"react-native-require-testid/testid-missing": "error" | ||
} | ||
} | ||
``` |
2138
42