Skip to content

Commit 4b21061

Browse files
fix: no-arbitrary-value rule is too broad (#342)
* fix: handle JSXNamespacedName * 3.15.2-beta.0 * fix: no-arbitrary-value rule is too broad * 3.15.2-beta.1 * docs: changelog
1 parent 83a587f commit 4b21061

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ You can can the same information on your favorite command line software as well.
4141

4242
## Latest changelog
4343

44+
- fix: [`no-arbitrary-value` rule is too broad](https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/318)
4445
- fix: [support `tag.div` and `tag(Component)`](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/302) (by [nihalgonsalves](https://github.com/nihalgonsalves) 🙏)
4546
- feat: [**support flat config and ESLint 9**](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/330) (by [kazupon](https://github.com/kazupon) 🙏)
4647
- feat: new rule [**`no-unnecessary-arbitrary-value`**](docs/rules/no-unnecessary-arbitrary-value.md) 🎉

lib/rules/no-arbitrary-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ module.exports = {
133133
const forbidden = [];
134134
classNames.forEach((cls, idx) => {
135135
const parsed = groupUtil.parseClassname(cls, [], mergedConfig, idx);
136-
if (/\[.*\]/i.test(parsed.name)) {
136+
if (/\[.*\]/i.test(parsed.body)) {
137137
forbidden.push(parsed.name);
138138
}
139139
});

lib/util/ast.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function isClassAttribute(node, classRegex) {
3636
case 'TextAttribute':
3737
name = node.name;
3838
break;
39+
case 'JSXAttribute':
40+
if (node.name.type === 'JSXNamespacedName') {
41+
const ns = node.name.namespace.name || '';
42+
name = (ns.length ? ns + ':' : '') + node.name.name.name;
43+
} else {
44+
name = node.name.name;
45+
}
46+
break;
3947
default:
4048
name = node.name.name;
4149
}
@@ -185,7 +193,7 @@ function extractRangeFromNode(node) {
185193
return [node.valueSpan.fullStart.offset, node.valueSpan.end.offset];
186194
}
187195
if (node.value === undefined) {
188-
return [0,0];
196+
return [0, 0];
189197
}
190198
switch (node.value.type) {
191199
case 'JSXExpressionContainer':

tests/lib/rules/no-arbitrary-value.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ ruleTester.run("no-arbitrary-value", rule, {
6363
code: `<div class="w-[10px]">Skip class attribute</div>`,
6464
options: skipClassAttributeOptions,
6565
},
66+
{
67+
code: `<div class="data-[state=open]:pb-8">Issue #318</div>`,
68+
},
6669
],
6770

6871
invalid: [

0 commit comments

Comments
 (0)