Skip to content

Commit

Permalink
fix: add check for sx prop
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack committed Sep 17, 2024
1 parent 21102b7 commit b13f173
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/rules/no-sx-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,34 @@ module.exports = {
create(context) {
return {
JSXOpeningElement(node) {
if (node.name.type === 'JSXMemberExpression') {
if (node.name.object.type === 'JSXIdentifier' && node.name.property.type === 'JSXIdentifier') {
const name = `${node.name.object.name}.${node.name.property.name}`
if (forbidden.has(name)) {
context.report({
node,
messageId: 'sxProp',
})
}
}
let name = null

if (
node.name.type === 'JSXMemberExpression' &&
node.name.object.type === 'JSXIdentifier' &&
node.name.property.type === 'JSXIdentifier'
) {
name = `${node.name.object.name}.${node.name.property.name}`
} else if (node.name.type === 'JSXIdentifier') {
if (forbidden.has(node.name.name)) {
context.report({
node,
messageId: 'sxProp',
})
name = node.name.name
}

if (!forbidden.has(name)) {
return
}

const hasSxProp = node.attributes.some(attr => {
if (attr.name.type === 'JSXIdentifier' && attr.name.name === 'sx') {
return true
}
return false
})

if (hasSxProp) {
context.report({
node,
messageId: 'sxProp',
})
}
},
}
Expand Down

0 comments on commit b13f173

Please sign in to comment.