So detecting mismatches between classes in styles and templates works. The next nice feature to have would probably be an optional autoremoval.
This needs probably separate plugins as it would work roughly like this:
function symdiffHtmlAutoremove(fileContent, classesToRemove) {
var ast = htmlParser.parse(fileContent);
walkAst(function(node) {
if (node.type === CLASS_ATTR) {
node.content = node.content.replace(classesToRemove, '');
});
});
return htmlParser.stringify(ast); // also unclear if that exists already for various parsers
});
Now the question is what to do with the cleaned up CSS string. Obviously we would save it somewhere. For file handling we have the task runner plugins. So it seems to be the simplest solution to add a new configuration to them:
// gulp-symdiff, that is
symdiff({
templates: [symdiffHtml],
css: [symdiffCss],
autoremove: [symdiffHtmlAutoremove (..optional other autoremovers)]
})
We can just feed all file contents to all autoremovers! One will work and the output we save to the destination folder. If none works, we just copy the file there. If more than one works, we make a lot of noise.
Details to be clarified:
- Should the autoremover throw if it can't parse the file or return null/empty string? Not sure yet of the benefits.
- People organize their project folders sometimes in crazy ways, so the file destination definition has to be very flexible. Look at how others do it. Do we have to care about this actually? In Gulp we would just emit the clean string and be done.
- Check which parsers out there implement ast->string
So detecting mismatches between classes in styles and templates works. The next nice feature to have would probably be an optional autoremoval.
This needs probably separate plugins as it would work roughly like this:
Now the question is what to do with the cleaned up CSS string. Obviously we would save it somewhere. For file handling we have the task runner plugins. So it seems to be the simplest solution to add a new configuration to them:
We can just feed all file contents to all autoremovers! One will work and the output we save to the destination folder. If none works, we just copy the file there. If more than one works, we make a lot of noise.
Details to be clarified: