a6fbc9db11
* turns out codemirror lint addon doesn't open an overall op, instead it creates an op for each marker. * also, now there's no need to disable the lint option when initializing codemirror
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/* global CodeMirror linterConfig */
|
|
'use strict';
|
|
|
|
(() => {
|
|
CodeMirror.registerHelper('lint', 'csslint', invokeHelper);
|
|
CodeMirror.registerHelper('lint', 'stylelint', invokeHelper);
|
|
|
|
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,
|
|
})),
|
|
};
|
|
|
|
function invokeHelper(code, options, cm) {
|
|
const config = linterConfig.getCurrent();
|
|
return linterConfig.invokeWorker({code, config})
|
|
.then(cookResults[linterConfig.getName()])
|
|
.then(results => {
|
|
if (options && typeof options.preUpdateLinting === 'function') {
|
|
options.preUpdateLinting(cm);
|
|
}
|
|
return results;
|
|
});
|
|
}
|
|
})();
|