Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: issue with leading/trailing spaces (multiline)
  • Loading branch information
francoismassart committed Jan 6, 2022
commit 0714fc635c8300ec3386a100c8162f53def94fcc
6 changes: 2 additions & 4 deletions lib/rules/enforces-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ module.exports = {
return;
}

classNames = attrUtil.sanitizeClassnames(classNames);
// Init assets before sorting
const parsed = [];
// Move each classname inside its dedicated group

classNames.forEach((className, index) => {
parsed.push(groupUtil.parseClassname(className, targetGroups, mergedConfig, index));
});
Expand Down Expand Up @@ -297,7 +295,7 @@ module.exports = {
});

// Generates the validated attribute value
const union = validated.map((val) => val.name);
const union = validated.map((val) => val.leading + val.name + val.trailing);

if (before !== null) {
union.unshift(before);
Expand Down
24 changes: 20 additions & 4 deletions lib/util/groupMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,22 @@ function findInGroup(name, group, config, parentType = null) {
* @returns {Object} Parsed infos
*/
function parseClassname(name, arr, config, index = null) {
const classPrefixes = getPrefixes(name, config.separator);
const classSuffix = getSuffix(name, config.separator);
const leadingRe = new RegExp('^(?<leading>\\s*)');
const trailingRe = new RegExp('(?<trailing>\\s*)$');
let leading = '';
let core = '';
let trailing = '';
const leadingRes = leadingRe.exec(name);
if (leadingRes && leadingRes.groups) {
leading = leadingRes.groups.leading || '';
}
const trailingRes = trailingRe.exec(name);
if (trailingRes && trailingRes.groups) {
trailing = trailingRes.groups.trailing || '';
}
core = name.substring(leading.length, name.length - trailing.length);
const classPrefixes = getPrefixes(core, config.separator);
const classSuffix = getSuffix(core, config.separator);
let slot = null;
arr.forEach((group) => {
if (slot === null) {
Expand All @@ -509,15 +523,17 @@ function parseClassname(name, arr, config, index = null) {
const value = slot ? slot.value : '';
const isNegative = value[0] === '-';
const off = isNegative ? 1 : 0;
const body = name.substr(0, name.length - value.length + off).substr(variants.length + off);
const body = core.substr(0, core.length - value.length + off).substr(variants.length + off);
return {
index: index,
name: name,
name: core,
variants: variants,
parentType: slot ? slot.group : '',
body: body,
value: value,
shorthand: slot ? slot.shorthand : '',
leading: leading,
trailing: trailing,
};
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"bugs": "https://github.com/francoismassart/eslint-plugin-tailwindcss/issues",
"main": "lib/index.js",
"scripts": {
"wip": "mocha tests/lib/rules/enforces-shorthand.js",
"test": "mocha tests --recursive"
},
"files": [
Expand Down
Loading