Skip to content

Commit

Permalink
fix: no-arbitrary-value rule is too broad (#342)
Browse files Browse the repository at this point in the history
* fix: handle JSXNamespacedName

* 3.15.2-beta.0

* fix: no-arbitrary-value rule is too broad

* 3.15.2-beta.1

* docs: changelog
  • Loading branch information
francoismassart authored Jun 6, 2024
1 parent 83a587f commit 4b21061
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ You can can the same information on your favorite command line software as well.

## Latest changelog

- fix: [`no-arbitrary-value` rule is too broad](https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/318)
- fix: [support `tag.div` and `tag(Component)`](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/302) (by [nihalgonsalves](https://github.com/nihalgonsalves) 🙏)
- feat: [**support flat config and ESLint 9**](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/330) (by [kazupon](https://github.com/kazupon) 🙏)
- feat: new rule [**`no-unnecessary-arbitrary-value`**](docs/rules/no-unnecessary-arbitrary-value.md) 🎉
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-arbitrary-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = {
const forbidden = [];
classNames.forEach((cls, idx) => {
const parsed = groupUtil.parseClassname(cls, [], mergedConfig, idx);
if (/\[.*\]/i.test(parsed.name)) {
if (/\[.*\]/i.test(parsed.body)) {
forbidden.push(parsed.name);
}
});
Expand Down
10 changes: 9 additions & 1 deletion lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ function isClassAttribute(node, classRegex) {
case 'TextAttribute':
name = node.name;
break;
case 'JSXAttribute':
if (node.name.type === 'JSXNamespacedName') {
const ns = node.name.namespace.name || '';
name = (ns.length ? ns + ':' : '') + node.name.name.name;
} else {
name = node.name.name;
}
break;
default:
name = node.name.name;
}
Expand Down Expand Up @@ -185,7 +193,7 @@ function extractRangeFromNode(node) {
return [node.valueSpan.fullStart.offset, node.valueSpan.end.offset];
}
if (node.value === undefined) {
return [0,0];
return [0, 0];
}
switch (node.value.type) {
case 'JSXExpressionContainer':
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/no-arbitrary-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ ruleTester.run("no-arbitrary-value", rule, {
code: `<div class="w-[10px]">Skip class attribute</div>`,
options: skipClassAttributeOptions,
},
{
code: `<div class="data-[state=open]:pb-8">Issue #318</div>`,
},
],

invalid: [
Expand Down

0 comments on commit 4b21061

Please sign in to comment.