Skip to content

Commit a9635d7

Browse files
FIX: enforces-shorthand false positive francoismassart#91
1 parent 0964105 commit a9635d7

File tree

3 files changed

+309
-299
lines changed

3 files changed

+309
-299
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ If you enjoy my work you can:
3333

3434
## Latest changelog
3535

36+
- FIX: [FIX: `enforces-shorthand` false positive](https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/91)
37+
3638
- FIX: [`snap-x` and `snap-mandatory` are conflicting classes](https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/90)
3739

3840
- New rule: [`enforces-shorthand`](docs/rules/enforces-shorthand.md) merging multiple classnames when possible

lib/rules/enforces-shorthand.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,27 @@ module.exports = {
305305
}
306306
let validatedClassNamesValue = union.join(isSingleLine ? ' ' : '\n');
307307
const originalPatched = isSingleLine ? originalClassNamesValue.trim() : originalClassNamesValue;
308-
troubles.forEach((issue) => {
309-
if (originalPatched !== validatedClassNamesValue) {
310-
validatedClassNamesValue = prefix + validatedClassNamesValue + suffix;
311-
context.report({
312-
node: node,
313-
messageId: 'shorthandCandidateDetected',
314-
data: {
315-
classnames: issue[0].join(', '),
316-
shorthand: issue[1],
317-
},
318-
fix: function (fixer) {
319-
return fixer.replaceTextRange([start, end], validatedClassNamesValue);
320-
},
321-
});
322-
}
323-
});
308+
troubles
309+
.filter((trouble) => {
310+
// Only valid issue if there are classes to replace
311+
return trouble[0].length;
312+
})
313+
.forEach((issue) => {
314+
if (originalPatched !== validatedClassNamesValue) {
315+
validatedClassNamesValue = prefix + validatedClassNamesValue + suffix;
316+
context.report({
317+
node: node,
318+
messageId: 'shorthandCandidateDetected',
319+
data: {
320+
classnames: issue[0].join(', '),
321+
shorthand: issue[1],
322+
},
323+
fix: function (fixer) {
324+
return fixer.replaceTextRange([start, end], validatedClassNamesValue);
325+
},
326+
});
327+
}
328+
});
324329
};
325330

326331
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)