move linter worker loaders to edit/
This commit is contained in:
parent
9cdacc85ec
commit
26f673f30d
|
@ -1,7 +1,9 @@
|
|||
/* global parserlib CSSLint parseMozFormat */
|
||||
/* global importScripts parserlib CSSLint parseMozFormat */
|
||||
'use strict';
|
||||
|
||||
self.importScripts('./parserlib.js');
|
||||
const CSSLINT_PATH = '/vendor-overwrites/csslint/';
|
||||
importScripts(CSSLINT_PATH + 'parserlib.js');
|
||||
|
||||
parserlib.css.Tokens[parserlib.css.Tokens.COMMENT].hide = false;
|
||||
|
||||
self.onmessage = ({data}) => {
|
||||
|
@ -14,7 +16,7 @@ self.onmessage = ({data}) => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!self.CSSLint) self.importScripts('./csslint.js');
|
||||
if (!self.CSSLint) self.importScripts(CSSLINT_PATH + 'csslint.js');
|
||||
|
||||
switch (action) {
|
||||
case 'getAllRuleIds':
|
|
@ -20,8 +20,8 @@ var linterConfig = {
|
|||
stylelint: 'editorStylelintConfig',
|
||||
},
|
||||
worker: {
|
||||
csslint: {path: '/vendor-overwrites/csslint/csslint-loader.js'},
|
||||
stylelint: {path: '/vendor-overwrites/stylelint/stylelint-bundle.min.js'},
|
||||
csslint: {path: '/edit/csslint-loader.js'},
|
||||
stylelint: {path: '/edit/stylelint-loader.js'},
|
||||
},
|
||||
allRuleIds: {
|
||||
csslint: null,
|
||||
|
|
58
edit/stylelint-loader.js
Normal file
58
edit/stylelint-loader.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* global require importScripts */
|
||||
'use strict';
|
||||
|
||||
importScripts('/vendor/stylelint-bundle/stylelint-bundle.min.js');
|
||||
|
||||
const stylelint = require('stylelint');
|
||||
|
||||
self.onmessage = ({data: {action = 'run', code, config}}) => {
|
||||
switch (action) {
|
||||
case 'getAllRuleIds':
|
||||
// the functions are non-tranferable
|
||||
self.postMessage(Object.keys(stylelint.rules));
|
||||
return;
|
||||
case 'getAllRuleOptions':
|
||||
self.postMessage(getAllRuleOptions());
|
||||
return;
|
||||
case 'run':
|
||||
stylelint.lint({code, config}).then(results =>
|
||||
self.postMessage(results));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
function getAllRuleOptions() {
|
||||
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;
|
||||
}
|
|
@ -600,7 +600,7 @@ var usercss = (() => {
|
|||
|
||||
function invokeWorker(message) {
|
||||
if (!worker.queue) {
|
||||
worker.instance = new Worker('/vendor-overwrites/csslint/csslint-loader.js');
|
||||
worker.instance = new Worker('/edit/csslint-loader.js');
|
||||
worker.queue = [];
|
||||
worker.instance.onmessage = ({data}) => {
|
||||
worker.queue.shift().resolve(data.__ERROR__ ? Promise.reject(data.__ERROR__) : data);
|
||||
|
|
Loading…
Reference in New Issue
Block a user