diff --git a/CHANGELOG.md b/CHANGELOG.md index b4051ae..a88a417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v6.2.2 + +* Fix: Extension ruins ASCII art definitions for grid-template-areas [#1](https://github.com/ronilaukkarinen/vscode-stylefmt/issues/1) + ## v6.2.1 * Fix: Media queries should be last by default diff --git a/lib/formatDecls.js b/lib/formatDecls.js index dd18178..cc88ed3 100644 --- a/lib/formatDecls.js +++ b/lib/formatDecls.js @@ -22,15 +22,17 @@ function formatDecls (rule, indent, indentWidth, stylelint) { decl.prop = decl.raws.before.trim().replace(/\n/g, '') + decl.prop } - decl.raws.between = ': ' - decl.raws.before = declarationEmptyLineBefore(stylelint, decl, indent, indentWidth, isSingleLine) + if (decl.prop !== 'grid-template-areas') { + decl.raws.between = ': ' + decl.raws.before = declarationEmptyLineBefore(stylelint, decl, indent, indentWidth, isSingleLine) - if (getProperty(stylelint, 'declaration-colon-space-before')) { - decl.raws.between = declarationColonSpaceBefore(stylelint, decl.raws.between) - } + if (getProperty(stylelint, 'declaration-colon-space-before')) { + decl.raws.between = declarationColonSpaceBefore(stylelint, decl.raws.between) + } - if (getProperty(stylelint, 'declaration-colon-space-after')) { - decl.raws.between = declarationColonSpaceAfter(stylelint, decl.raws.between) + if (getProperty(stylelint, 'declaration-colon-space-after')) { + decl.raws.between = declarationColonSpaceAfter(stylelint, decl.raws.between) + } } formatValues(decl, stylelint) diff --git a/lib/formatValues.js b/lib/formatValues.js index c23ace3..d40305f 100644 --- a/lib/formatValues.js +++ b/lib/formatValues.js @@ -10,11 +10,11 @@ function formatvalues (decl, stylelint) { var isString = /^("|').*("|')$/.test(decl.value) var isFunctionCall = /\w+\(.+\)/.test(decl.value) - if (decl.raws.value) { + if (decl.raws.value && decl.prop !== 'grid-template-areas') { decl.raws.value.raw = decl.raws.value.raw.trim() } - if (!isString) { + if (!isString && decl.prop !== 'grid-template-areas') { decl.value = decl.value.trim().replace(/\s+/g, ' ') } @@ -47,13 +47,15 @@ function formatvalues (decl, stylelint) { } if (!isFunctionCall) { - // format math operators before `$` or `(`. + // Format math operators before `$` or `(`. decl.value = decl.value.replace(/(?!^)[+\-*%](?=\$|\()/g, ' $& ') - // don't format "/" from a "font" shorthand property. + + // Don't format "/" from a "font" shorthand property. if (decl.prop !== 'font') { decl.value = decl.value.replace(/\/(?=\$|\(|\d)/g, ' $& ') } - // format "-" if it is between numbers + + // Format "-" if it is between numbers decl.value = decl.value.replace(/\d+-(?=\d)/g, function (value) { return value.replace(/-/g, ' $& ') })