2017-11-28 17:03:50 +00:00
|
|
|
/* global CodeMirror linterConfig */
|
2017-08-28 05:22:19 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-01 00:49:09 +00:00
|
|
|
(() => {
|
|
|
|
CodeMirror.registerHelper('lint', 'csslint', invokeHelper);
|
|
|
|
CodeMirror.registerHelper('lint', 'stylelint', invokeHelper);
|
2017-08-28 05:22:19 +00:00
|
|
|
|
2017-12-01 00:49:09 +00:00
|
|
|
const cookResults = {
|
|
|
|
csslint: results =>
|
|
|
|
results.map(({line, col: ch, message, rule, type: severity}) => line && {
|
|
|
|
message,
|
|
|
|
from: {line: line - 1, ch: ch - 1},
|
|
|
|
to: {line: line - 1, ch},
|
|
|
|
rule: rule.id,
|
|
|
|
severity,
|
|
|
|
}).filter(Boolean),
|
|
|
|
|
|
|
|
stylelint: ({results}) =>
|
|
|
|
!results[0] && [] ||
|
|
|
|
results[0].warnings.map(({line, column: ch, text, severity}) => ({
|
|
|
|
from: {line: line - 1, ch: ch - 1},
|
|
|
|
to: {line: line - 1, ch},
|
|
|
|
message: text
|
|
|
|
.replace('Unexpected ', '')
|
|
|
|
.replace(/^./, firstLetter => firstLetter.toUpperCase())
|
|
|
|
.replace(/\s*\([^(]+\)$/, ''), // strip the rule,
|
|
|
|
rule: text.replace(/^.*?\s*\(([^(]+)\)$/, '$1'),
|
|
|
|
severity,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
2018-03-03 20:11:15 +00:00
|
|
|
function invokeHelper(code) {
|
2017-12-01 00:49:09 +00:00
|
|
|
const config = linterConfig.getCurrent();
|
|
|
|
return linterConfig.invokeWorker({code, config})
|
2018-03-03 20:11:15 +00:00
|
|
|
.then(cookResults[linterConfig.getName()]);
|
2017-12-01 00:49:09 +00:00
|
|
|
}
|
|
|
|
})();
|