Skip to content

Commit

Permalink
Temporary stash for issue #112
Browse files Browse the repository at this point in the history
  • Loading branch information
francoismassart committed Jan 30, 2022
1 parent 66aff45 commit cecadd1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
73 changes: 30 additions & 43 deletions lib/util/groupMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function generateOptionalOpacitySuffix(config) {
function generateOptions(propName, keys, config, isNegative = false) {
const opacitySuffixes = generateOptionalOpacitySuffix(config);
const genericArbitraryOption = '\\[(.*)\\]';
const supportArbitrary = !isNegative;
const defaultKeyIndex = keys.findIndex((v) => v === 'DEFAULT');
if (defaultKeyIndex > -1) {
keys.splice(defaultKeyIndex, 1);
Expand Down Expand Up @@ -86,43 +85,39 @@ function generateOptions(propName, keys, config, isNegative = false) {
// Colors can use segments like 'indigo' and 'indigo-light'
// https://tailwindcss.com/docs/customizing-colors#color-object-syntax
const options = [];
// Conditionnaly generates the opacity suffix
const opacitySuffix = supportArbitrary ? opacitySuffixes : '';
keys.forEach((k) => {
const color = config.theme[propName][k] || config.theme.colors[k];
if (typeof color === 'string') {
options.push(escapeSpecialChars(k) + opacitySuffix);
options.push(escapeSpecialChars(k) + opacitySuffixes);
} else {
const variants = Object.keys(color).map((colorKey) => escapeSpecialChars(colorKey));
const defaultIndex = variants.findIndex((v) => v === 'DEFAULT');
const hasDefault = defaultIndex > -1;
if (hasDefault) {
variants.splice(defaultIndex, 1);
}
options.push(k + '(\\-(' + variants.join('|') + '))' + (hasDefault ? '?' : '') + opacitySuffix);
options.push(k + '(\\-(' + variants.join('|') + '))' + (hasDefault ? '?' : '') + opacitySuffixes);
}
});
if (supportArbitrary) {
const arbitraryColors = [...color.mergedColorValues];
switch (propName) {
case 'fill':
// Forbidden prefixes
arbitraryColors.push(`(?!(angle|length|list)\:).{1,}`);
break;
case 'gradientColorStops':
arbitraryColors.push(color.RGBAPercentages); // RGBA % 0.5[%]
arbitraryColors.push(color.optionalColorPrefixedVar);
arbitraryColors.push(color.notHSLAPlusWildcard);
break;
case 'textColor':
arbitraryColors.push(color.RGBAPercentages); // RGBA % 0.5[%]
arbitraryColors.push(color.mandatoryColorPrefixed);
break;
default:
arbitraryColors.push(color.mandatoryColorPrefixed);
}
options.push(`\\[(${arbitraryColors.join('|')})\\]`);
const arbitraryColors = [...color.mergedColorValues];
switch (propName) {
case 'fill':
// Forbidden prefixes
arbitraryColors.push(`(?!(angle|length|list)\:).{1,}`);
break;
case 'gradientColorStops':
arbitraryColors.push(color.RGBAPercentages); // RGBA % 0.5[%]
arbitraryColors.push(color.optionalColorPrefixedVar);
arbitraryColors.push(color.notHSLAPlusWildcard);
break;
case 'textColor':
arbitraryColors.push(color.RGBAPercentages); // RGBA % 0.5[%]
arbitraryColors.push(color.mandatoryColorPrefixed);
break;
default:
arbitraryColors.push(color.mandatoryColorPrefixed);
}
options.push(`\\[(${arbitraryColors.join('|')})\\]`);
return '(' + options.join('|') + ')';
case 'borderWidth':
case 'divideWidth':
Expand Down Expand Up @@ -176,12 +171,10 @@ function generateOptions(propName, keys, config, isNegative = false) {
case 'transformOrigin':
case 'scale':
case 'cursor':
if (supportArbitrary) {
// All units
escapedKeys.push(length.mergedUnitsRegEx);
// Forbidden prefixes
escapedKeys.push(`\\[(?!(angle|color|length|list)\:).{1,}\\]`);
}
// All units
escapedKeys.push(length.mergedUnitsRegEx);
// Forbidden prefixes
escapedKeys.push(`\\[(?!(angle|color|length|list)\:).{1,}\\]`);
return '(' + escapedKeys.join('|') + ')';
case 'backdropHueRotate':
case 'hueRotate':
Expand All @@ -193,12 +186,10 @@ function generateOptions(propName, keys, config, isNegative = false) {
case 'space':
case 'textIndent':
case 'translate':
if (supportArbitrary) {
// All units
escapedKeys.push(length.mergedUnitsRegEx);
// Forbidden prefixes
escapedKeys.push(`\\[(?!(angle|color|length|list)\:).{1,}\\]`);
}
// All units
escapedKeys.push(length.mergedUnitsRegEx);
// Forbidden prefixes
escapedKeys.push(`\\[(?!(angle|color|length|list)\:).{1,}\\]`);
return '(' + escapedKeys.join('|') + ')';
case 'backgroundOpacity':
case 'borderOpacity':
Expand All @@ -211,9 +202,7 @@ function generateOptions(propName, keys, config, isNegative = false) {
escapedKeys.push(`\\[var\\(\\-\\-[A-Za-z\\-]{1,}\\)\\]`);
return '(' + escapedKeys.join('|') + ')';
case 'rotate':
if (supportArbitrary) {
escapedKeys.push(`\\[(${angle.mergedAngleValues.join('|')})\\]`);
}
escapedKeys.push(`\\[(${angle.mergedAngleValues.join('|')})\\]`);
return '(' + escapedKeys.join('|') + ')';
case 'gridTemplateColumns':
case 'gridColumn':
Expand Down Expand Up @@ -253,9 +242,7 @@ function generateOptions(propName, keys, config, isNegative = false) {
return '(' + escapedKeys.join('|') + ')';
case 'order':
case 'zIndex':
if (supportArbitrary) {
escapedKeys.push(genericArbitraryOption);
}
escapedKeys.push(genericArbitraryOption);
return '(' + escapedKeys.join('|') + ')';
case 'fontWeight':
case 'typography':
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-custom-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ ruleTester.run("no-custom-classname", rule, {
code: `
<div class="decoration-clone decoration-slice flex-grow flex-shrink overflow-clip overflow-ellipsis bg-opacity-50 border-opacity-100 transform scale-50">Deprecated classnames yet still supported for now</div>`,
},
{
code: `
<div class="-ml-[1px] mr-[-1px]">Negative arbitrary value</div>`,
},
],

invalid: [
Expand Down

0 comments on commit cecadd1

Please sign in to comment.