List unused custom properties
// list unused custom properties | |
// $ node list-unused-custom-properties.js <FILENAME> | |
const fs = require("fs"); | |
const postcss = require("postcss"); | |
const css = postcss.parse(fs.readFileSync(process.argv[2], "utf8")); | |
const customProperties = {}; | |
css.walkDecls(decl => { | |
if (decl.prop.startsWith("--")) { | |
customProperties[decl.prop] = 0; | |
} | |
const variables = decl.value.match(/\bvar\(.*?\)/g); | |
if (!variables) { | |
return; | |
} | |
variables.forEach(variable => { | |
const customProperty = variable.replace(/var\((.*?)\)/, "$1"); | |
delete customProperties[customProperty]; | |
}); | |
}); | |
console.log(customProperties); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
This works against a concatenated CSS file only.