Skip to content

Commit ca3d8da

Browse files
committed
Ignore template literals
1 parent 6c2004d commit ca3d8da

File tree

1 file changed

+2
-57
lines changed

1 file changed

+2
-57
lines changed

plugin/src/rules/no-margin-properties.ts

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { isPandaAttribute, isPandaIsh, isPandaProp, resolveLonghand } from '../utils/helpers'
1+
import { isPandaAttribute, isPandaProp, resolveLonghand } from '../utils/helpers'
22
import { type Rule, createRule } from '../utils'
3-
import { isCallExpression, isIdentifier, isJSXIdentifier, isMemberExpression } from '../utils/nodes'
3+
import { isIdentifier, isJSXIdentifier } from '../utils/nodes'
44
import type { TSESTree } from '@typescript-eslint/utils'
55

66
export const RULE_NAME = 'no-margin-properties'
@@ -46,61 +46,6 @@ const rule: Rule = createRule({
4646

4747
sendReport(node.key)
4848
},
49-
50-
TaggedTemplateExpression(node) {
51-
const handleExpression = (caller: string) => {
52-
if (!isPandaIsh(caller, context)) return
53-
54-
const quasis = node.quasi.quasis[0]
55-
const styles = quasis.value.raw
56-
57-
const propertyRegex = /([a-zA-Z-]+):/g
58-
const propertyMatches = [...styles.matchAll(propertyRegex)]
59-
const properties = propertyMatches.map((match) => match[1].trim())
60-
61-
properties.forEach((property, i, arr) => {
62-
if (!property.includes('margin')) return
63-
64-
// Avoid duplicate reports on the same token
65-
if (arr.indexOf(property) < i) return
66-
67-
let index = styles.indexOf(property)
68-
69-
while (index !== -1) {
70-
const start = quasis.range[0] + 1 + index
71-
const end = start + property.length
72-
73-
context.report({
74-
loc: {
75-
start: context.sourceCode.getLocFromIndex(start),
76-
end: context.sourceCode.getLocFromIndex(end),
77-
},
78-
messageId: 'noMargin',
79-
})
80-
81-
// Check for other occurences of the invalid token
82-
index = styles.indexOf(property, index + 1)
83-
}
84-
})
85-
}
86-
87-
// css``
88-
if (isIdentifier(node.tag)) {
89-
handleExpression(node.tag.name)
90-
}
91-
92-
// styled.h1``
93-
if (isMemberExpression(node.tag)) {
94-
if (!isIdentifier(node.tag.object)) return
95-
handleExpression(node.tag.object.name)
96-
}
97-
98-
// styled(Comp)``
99-
if (isCallExpression(node.tag)) {
100-
if (!isIdentifier(node.tag.callee)) return
101-
handleExpression(node.tag.callee.name)
102-
}
103-
},
10449
}
10550
},
10651
})

0 commit comments

Comments
 (0)