Skip to content

Commit 03d039f

Browse files
committed
feat: implement validate addon
1 parent 5b2dbd1 commit 03d039f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

addon/validate.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
var validateString = require('csstree-validator').validateString;
4+
5+
exports.addon = function (renderer) {
6+
if (process.env.NODE_ENV !== 'production') {
7+
require('./__dev__/warnOnMissingDependencies')('validate', renderer, ['putRaw']);
8+
}
9+
10+
if (process.env.NODE_ENV === 'production') {
11+
console.warn(
12+
'You are using nano-css "validate" in production. ' +
13+
'This addon is suggested to be used only in development.'
14+
);
15+
}
16+
17+
var putRaw = renderer.putRaw;
18+
19+
renderer.putRaw = function (rawCssRule) {
20+
var errors = validateString(rawCssRule)['<unknown>'];
21+
22+
if (errors.length) {
23+
errors.forEach(function (error) {
24+
console.error('Error in CSS: ' + error.message);
25+
console.error(error);
26+
// eslint-disable-next-line
27+
console.log(rawCssRule);
28+
});
29+
}
30+
31+
putRaw(rawCssRule);
32+
};
33+
};

0 commit comments

Comments
 (0)