2018-07-10 07:55:16 +00:00
|
|
|
/* global importScripts parserlib CSSLint parseMozFormat */
|
2017-12-26 20:39:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-07-10 07:55:16 +00:00
|
|
|
const CSSLINT_PATH = '/vendor-overwrites/csslint/';
|
|
|
|
importScripts(CSSLINT_PATH + 'parserlib.js');
|
|
|
|
|
2017-12-26 20:39:52 +00:00
|
|
|
parserlib.css.Tokens[parserlib.css.Tokens.COMMENT].hide = false;
|
|
|
|
|
2018-01-06 06:48:56 +00:00
|
|
|
self.onmessage = ({data}) => {
|
|
|
|
|
|
|
|
const {action = 'run'} = data;
|
2017-12-26 20:39:52 +00:00
|
|
|
|
|
|
|
if (action === 'parse') {
|
|
|
|
if (!self.parseMozFormat) self.importScripts('/js/moz-parser.js');
|
2018-01-06 06:48:56 +00:00
|
|
|
self.postMessage(parseMozFormat(data));
|
2017-12-26 20:39:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-06 06:48:56 +00:00
|
|
|
|
2018-07-10 07:55:16 +00:00
|
|
|
if (!self.CSSLint) self.importScripts(CSSLINT_PATH + 'csslint.js');
|
2017-12-26 20:39:52 +00:00
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case 'getAllRuleIds':
|
|
|
|
// the functions are non-tranferable and we need only an id
|
|
|
|
self.postMessage(CSSLint.getRules().map(rule => rule.id));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'getAllRuleInfos':
|
|
|
|
// the functions are non-tranferable
|
|
|
|
self.postMessage(CSSLint.getRules().map(rule => JSON.parse(JSON.stringify(rule))));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'run': {
|
2018-01-06 06:48:56 +00:00
|
|
|
const {code, config} = data;
|
2017-12-26 20:39:52 +00:00
|
|
|
const results = CSSLint.verify(code, config).messages
|
|
|
|
//.filter(m => !m.message.includes('/*[[') && !m.message.includes(']]*/'))
|
|
|
|
.map(m => Object.assign(m, {rule: {id: m.rule.id}}));
|
|
|
|
self.postMessage(results);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|