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