Add styled component rule (#1261)

* Add StyledComponent rule

* update doc

* update doc

* update doc
This commit is contained in:
Weiko
2023-08-17 20:58:02 -07:00
committed by GitHub
parent 390e70a196
commit 9b34a0ff3d
70 changed files with 433 additions and 354 deletions

View File

@ -0,0 +1,32 @@
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Warn when StyledComponents are not prefixed with Styled',
},
recommended: true,
fixable: 'code',
schema: [],
},
create: function(context) {
return {
VariableDeclarator: node => {
const templateExpr = node.init
if (templateExpr?.type !== 'TaggedTemplateExpression') {
return;
}
const tag = templateExpr.tag
const tagged = tag.type === 'MemberExpression' ? tag.object
: tag.type === 'CallExpression' ? tag.callee
: null
if (tagged?.name === 'styled') {
const variable = node.id;
if (variable?.name.startsWith('Styled')) {
return;
}
context.report({ node, message: `'${variable.name}' is a StyledComponent and is not prefixed with Styled.` });
}
},
}
}
};