Skip to content
Merged
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 formatting
  • Loading branch information
adamwathan committed Apr 16, 2019
commit de1884fdd935e12aa9587c3e31c234999f601eb6
17 changes: 9 additions & 8 deletions src/lib/formatNodes.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down