mirror of
https://github.com/bendtherules/eslint-plugin-no-classname-with-stylename.git
synced 2026-08-18 13:53:24 +00:00
Fix tests and attr type check
This commit is contained in:
@@ -38,14 +38,16 @@ module.exports = {
|
||||
|
||||
return {
|
||||
"JSXOpeningElement": function (node) {
|
||||
console.log(node.attributes);
|
||||
|
||||
const hasClassNameWithoutExpr = node.attributes.some((attr) => (
|
||||
attr.type === "JSXIdentifier" && attr.name.name === "className" &&
|
||||
attr.name.type === "JSXIdentifier" && attr.name.name === "className" &&
|
||||
(attr.value === null || attr.value.type !== 'JSXExpressionContainer')
|
||||
));
|
||||
const hasStyleName = node.attributes.some((attr) => attr.type === "JSXIdentifier" && attr.name.name === "styleName");
|
||||
const hasStyleName = node.attributes.some((attr) => attr.name.type === "JSXIdentifier" && attr.name.name === "styleName");
|
||||
|
||||
if (hasClassNameWithoutExpr && hasStyleName) {
|
||||
const nodeAttrClassName = node.attributes.find((attr) => attr.type === "JSXIdentifier" && attr.name.name === "className");
|
||||
const nodeAttrClassName = node.attributes.find((attr) => attr.name.type === "JSXIdentifier" && attr.name.name === "className");
|
||||
context.report(nodeAttrClassName, reportText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ var ruleTester = new RuleTester({
|
||||
parserOptions: {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
}
|
||||
},
|
||||
ecmaVersion: 7,
|
||||
}
|
||||
});
|
||||
ruleTester.run("no-classname-with-stylename", rule, {
|
||||
@@ -30,6 +31,8 @@ ruleTester.run("no-classname-with-stylename", rule, {
|
||||
"<span styleName='my-card' />",
|
||||
"<span className='card' />",
|
||||
"<span className={123} styleName='my-card' />",
|
||||
"<span {...({a:1})} className={'card'} styleName='my-card' />",
|
||||
"<span {...someVar} className={'card'} styleName='my-card' />",
|
||||
"<span className={'card'} styleName='my-card' />",
|
||||
"<span className={true ? 'card' : 'no-card'} styleName='my-card' />"
|
||||
// give me some code that won't trigger a warning
|
||||
@@ -53,6 +56,19 @@ ruleTester.run("no-classname-with-stylename", rule, {
|
||||
errors: [{
|
||||
// message: "Disallow string className alongwith styleName in the same JSX tag",
|
||||
}]
|
||||
},
|
||||
{
|
||||
code: "<span {...({qwe:234})} className='card' styleName='my-card' />",
|
||||
errors: [{
|
||||
// message: "Disallow string className alongwith styleName in the same JSX tag",
|
||||
}]
|
||||
},
|
||||
{
|
||||
code: "<span {...someVar} className='card' styleName='my-card' />",
|
||||
errors: [{
|
||||
// message: "Disallow string className alongwith styleName in the same JSX tag",
|
||||
}]
|
||||
}
|
||||
|
||||
]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user