Skip to content

Commit

Permalink
feat: implement validate addon
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 23, 2018
1 parent 5b2dbd1 commit 03d039f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions addon/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var validateString = require('csstree-validator').validateString;

exports.addon = function (renderer) {
if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('validate', renderer, ['putRaw']);
}

if (process.env.NODE_ENV === 'production') {
console.warn(
'You are using nano-css "validate" in production. ' +
'This addon is suggested to be used only in development.'
);
}

var putRaw = renderer.putRaw;

renderer.putRaw = function (rawCssRule) {
var errors = validateString(rawCssRule)['<unknown>'];

if (errors.length) {
errors.forEach(function (error) {
console.error('Error in CSS: ' + error.message);
console.error(error);
// eslint-disable-next-line
console.log(rawCssRule);
});
}

putRaw(rawCssRule);
};
};

0 comments on commit 03d039f

Please sign in to comment.