From de1884fdd935e12aa9587c3e31c234999f601eb6 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Tue, 16 Apr 2019 11:49:12 -0400 Subject: [PATCH] Fix formatting --- src/lib/formatNodes.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/formatNodes.js b/src/lib/formatNodes.js index 06ac59a43..6ff7fc40b 100644 --- a/src/lib/formatNodes.js +++ b/src/lib/formatNodes.js @@ -1,11 +1,12 @@ -function indentRecursive(node, indentLevel = 0) { - node.each && node.each((child, i) => { - if (!child.raws.before || child.raws.before.includes('\n')) { - child.raws.before = `${ node.type === 'rule' || i === 0 ? '\n' : '\n\n'}${' '.repeat(indentLevel)}` - } - child.raws.after = `\n${' '.repeat(indentLevel)}` - indentRecursive(child, indentLevel + 1) - }) +function indentRecursive(node, indent = 0) { + node.each && + node.each((child, i) => { + if (!child.raws.before || child.raws.before.includes('\n')) { + child.raws.before = `\n${node.type !== 'rule' && i > 0 ? '\n' : ''}${' '.repeat(indent)}` + } + child.raws.after = `\n${' '.repeat(indent)}` + indentRecursive(child, indent + 1) + }) } export default function formatNodes(root) {