Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no-arbitrary-value rule is too broad #342

Merged
merged 6 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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