-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
csslint.js
38 lines (34 loc) · 1.25 KB
/
csslint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Copyright (c) 2013, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
HTMLHint.addRule({
id: 'csslint',
description: 'Scan css with csslint.',
init: function(parser, reporter, options){
var self = this;
parser.addListener('cdata', function(event){
if(event.tagName.toLowerCase() === 'style'){
var cssVerify;
if(typeof exports === 'object' && require){
cssVerify = require("csslint").CSSLint.verify;
}
else{
cssVerify = CSSLint.verify;
}
if(options !== undefined){
var styleLine = event.line - 1,
styleCol = event.col - 1;
try{
var messages = cssVerify(event.raw, options).messages;
messages.forEach(function(error){
var line = error.line;
reporter[error.type==='warning'?'warn':'error']('['+error.rule+'] '+error.message, styleLine + line, (line === 1 ? styleCol : 0) + error.col, self, '');
});
}
catch(e){}
}
}
});
}
});