Skip to content

Commit

Permalink
fix: #111
Browse files Browse the repository at this point in the history
  • Loading branch information
francoismassart committed Jan 27, 2022
1 parent 5f0eefa commit e8119ca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lib/config/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,11 @@ module.exports.groups = [
},
],
},
{
type: 'Deprecated Border Opacity',
members: 'border\\-opacity\\-(?<value>${borderOpacity})',
deprecated: true,
},
{
type: 'Border Style',
members: 'border\\-(solid|dashed|dotted|double|hidden|none)',
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/migration-from-tailwind-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const parserUtil = require('../util/parser');
const CLASSNAME_NOT_NEEDED_MSG = `Classname '{{classnames}}' is not needed in Tailwind CSS v3!`;
const CLASSNAMES_NOT_NEEDED_MSG = `Classnames '{{classnames}}' are not needed in Tailwind CSS v3!`;
const CLASSNAME_CHANGED_MSG = `Classname '{{deprecated}}' should be updated to '{{updated}}' in Tailwind CSS v3!`;
const BG_OPACITY_DEPRECATED_MSG = `Classname '{{classname}}' should be replaced by an opacity suffix (eg. '/{{value}}')`;
const OPACITY_CLASS_DEPRECATED_MSG = `Classname '{{classname}}' should be replaced by an opacity suffix (eg. '/{{value}}')`;

module.exports = {
meta: {
Expand All @@ -35,7 +35,7 @@ module.exports = {
classnameNotNeeded: CLASSNAME_NOT_NEEDED_MSG,
classnamesNotNeeded: CLASSNAMES_NOT_NEEDED_MSG,
classnameChanged: CLASSNAME_CHANGED_MSG,
bgOpacityDeprecated: BG_OPACITY_DEPRECATED_MSG,
classnameOpacityDeprecated: OPACITY_CLASS_DEPRECATED_MSG,
},
fixable: 'code',
schema: [
Expand Down Expand Up @@ -185,7 +185,7 @@ module.exports = {
const fixRegex = new RegExp(`decoration\-${boxVal}`);
outdated.push([cls, cls.replace(fixRegex, `box-decoration\-${boxVal}`)]);
}
let bgOpacityRes = /^(bg|ring)\-opacity\-(?<value>\d{1,})$/i.exec(suffix);
let bgOpacityRes = /^(bg|border|ring)\-opacity\-(?<value>\d{1,})$/i.exec(suffix);
if (bgOpacityRes && bgOpacityRes.groups && bgOpacityRes.groups.value) {
const opacityVal = bgOpacityRes.groups.value;
deprecatedBgOpacity.push([cls, opacityVal]);
Expand Down Expand Up @@ -233,7 +233,7 @@ module.exports = {
deprecatedBgOpacity.forEach((bgClass) => {
context.report({
node,
messageId: 'bgOpacityDeprecated',
messageId: 'classnameOpacityDeprecated',
data: {
classname: bgClass[0],
value: bgClass[1],
Expand Down
1 change: 1 addition & 0 deletions lib/util/groupMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function generateOptions(propName, keys, config, isNegative = false) {
}
return '(' + escapedKeys.join('|') + ')';
case 'backgroundOpacity':
case 'borderOpacity':
case 'opacity':
case 'ringOpacity':
// 0 ... .5 ... 1
Expand Down
13 changes: 10 additions & 3 deletions tests/lib/rules/migration-from-tailwind-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ ruleTester.run("migration-from-tailwind-2", rule, {
code: `<div class="bg-opacity-50">bg-opacity</div>`,
errors: [
{
messageId: "bgOpacityDeprecated",
messageId: "classnameOpacityDeprecated",
data: {
classname: "bg-opacity-50",
value: "50",
Expand All @@ -165,15 +165,22 @@ ruleTester.run("migration-from-tailwind-2", rule, {
],
},
{
code: `<div class="ring-opacity-50">ring-opacity</div>`,
code: `<div class="ring-opacity-50 border-opacity-50">ring-opacity</div>`,
errors: [
{
messageId: "bgOpacityDeprecated",
messageId: "classnameOpacityDeprecated",
data: {
classname: "ring-opacity-50",
value: "50",
},
},
{
messageId: "classnameOpacityDeprecated",
data: {
classname: "border-opacity-50",
value: "50",
},
},
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-custom-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ ruleTester.run("no-custom-classname", rule, {
},
{
code: `
<div class="decoration-clone decoration-slice flex-grow flex-shrink overflow-clip overflow-ellipsis bg-opacity-50 transform scale-50">Deprecated classnames yet still supported for now</div>`,
<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>`,
},
],

Expand Down

0 comments on commit e8119ca

Please sign in to comment.