2018-10-01 14:38:06 +00:00
|
|
|
/* global importScripts parseMozFormat parserlib CSSLint require workerUtil */
|
2018-10-01 14:03:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-01 14:38:06 +00:00
|
|
|
importScripts('/js/worker-util.js');
|
|
|
|
const {createAPI, loadScript} = workerUtil;
|
|
|
|
|
2018-10-01 14:03:17 +00:00
|
|
|
createAPI({
|
|
|
|
csslint: (code, config) => {
|
2018-10-01 14:38:06 +00:00
|
|
|
loadScript('/vendor-overwrites/csslint/parserlib.js', '/vendor-overwrites/csslint/csslint.js');
|
2018-10-01 14:03:17 +00:00
|
|
|
return CSSLint.verify(code, config).messages
|
|
|
|
.map(m => Object.assign(m, {rule: {id: m.rule.id}}));
|
|
|
|
},
|
|
|
|
stylelint: (code, config) => {
|
2018-10-01 14:38:06 +00:00
|
|
|
loadScript('/vendor/stylelint-bundle/stylelint-bundle.min.js');
|
2018-10-01 14:03:17 +00:00
|
|
|
return require('stylelint').lint({code, config});
|
|
|
|
},
|
|
|
|
getStylelintRules,
|
|
|
|
getCsslintRules
|
|
|
|
});
|
|
|
|
|
|
|
|
function getCsslintRules() {
|
2018-10-01 14:38:06 +00:00
|
|
|
loadScript('/vendor-overwrites/csslint/csslint.js');
|
2018-10-01 14:03:17 +00:00
|
|
|
return CSSLint.getRules().map(rule => {
|
|
|
|
const output = {};
|
|
|
|
for (const [key, value] of Object.entries(rule)) {
|
|
|
|
if (typeof value !== 'function') {
|
|
|
|
output[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStylelintRules() {
|
2018-10-01 14:38:06 +00:00
|
|
|
loadScript('/vendor/stylelint-bundle/stylelint-bundle.min.js');
|
2018-10-01 14:03:17 +00:00
|
|
|
const stylelint = require('stylelint');
|
|
|
|
const options = {};
|
|
|
|
const rxPossible = /\bpossible:("(?:[^"]*?)"|\[(?:[^\]]*?)\]|\{(?:[^}]*?)\})/g;
|
|
|
|
const rxString = /"([-\w\s]{3,}?)"/g;
|
|
|
|
for (const id of Object.keys(stylelint.rules)) {
|
|
|
|
const ruleCode = String(stylelint.rules[id]);
|
|
|
|
const sets = [];
|
|
|
|
let m, mStr;
|
|
|
|
while ((m = rxPossible.exec(ruleCode))) {
|
|
|
|
const possible = m[1];
|
|
|
|
const set = [];
|
|
|
|
while ((mStr = rxString.exec(possible))) {
|
|
|
|
const s = mStr[1];
|
|
|
|
if (s.includes(' ')) {
|
|
|
|
set.push(...s.split(/\s+/));
|
|
|
|
} else {
|
|
|
|
set.push(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (possible.includes('ignoreAtRules')) {
|
|
|
|
set.push('ignoreAtRules');
|
|
|
|
}
|
|
|
|
if (possible.includes('ignoreShorthands')) {
|
|
|
|
set.push('ignoreShorthands');
|
|
|
|
}
|
|
|
|
if (set.length) {
|
|
|
|
sets.push(set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sets.length) {
|
|
|
|
options[id] = sets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|