From ca3d8da72e7426575c46e36de5f3bdf279f059ba Mon Sep 17 00:00:00 2001 From: anubra266 Date: Sun, 11 Feb 2024 10:45:00 -0600 Subject: [PATCH] Ignore template literals --- plugin/src/rules/no-margin-properties.ts | 59 +----------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/plugin/src/rules/no-margin-properties.ts b/plugin/src/rules/no-margin-properties.ts index 79407c1..6848918 100644 --- a/plugin/src/rules/no-margin-properties.ts +++ b/plugin/src/rules/no-margin-properties.ts @@ -1,6 +1,6 @@ -import { isPandaAttribute, isPandaIsh, isPandaProp, resolveLonghand } from '../utils/helpers' +import { isPandaAttribute, isPandaProp, resolveLonghand } from '../utils/helpers' import { type Rule, createRule } from '../utils' -import { isCallExpression, isIdentifier, isJSXIdentifier, isMemberExpression } from '../utils/nodes' +import { isIdentifier, isJSXIdentifier } from '../utils/nodes' import type { TSESTree } from '@typescript-eslint/utils' export const RULE_NAME = 'no-margin-properties' @@ -46,61 +46,6 @@ const rule: Rule = createRule({ sendReport(node.key) }, - - TaggedTemplateExpression(node) { - const handleExpression = (caller: string) => { - if (!isPandaIsh(caller, context)) return - - const quasis = node.quasi.quasis[0] - const styles = quasis.value.raw - - const propertyRegex = /([a-zA-Z-]+):/g - const propertyMatches = [...styles.matchAll(propertyRegex)] - const properties = propertyMatches.map((match) => match[1].trim()) - - properties.forEach((property, i, arr) => { - if (!property.includes('margin')) return - - // Avoid duplicate reports on the same token - if (arr.indexOf(property) < i) return - - let index = styles.indexOf(property) - - while (index !== -1) { - const start = quasis.range[0] + 1 + index - const end = start + property.length - - context.report({ - loc: { - start: context.sourceCode.getLocFromIndex(start), - end: context.sourceCode.getLocFromIndex(end), - }, - messageId: 'noMargin', - }) - - // Check for other occurences of the invalid token - index = styles.indexOf(property, index + 1) - } - }) - } - - // css`` - if (isIdentifier(node.tag)) { - handleExpression(node.tag.name) - } - - // styled.h1`` - if (isMemberExpression(node.tag)) { - if (!isIdentifier(node.tag.object)) return - handleExpression(node.tag.object.name) - } - - // styled(Comp)`` - if (isCallExpression(node.tag)) { - if (!isIdentifier(node.tag.callee)) return - handleExpression(node.tag.callee.name) - } - }, } }, })