2017-08-28 05:22:19 +00:00
|
|
|
/* global CodeMirror CSSLint stylelint linterConfig */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
CodeMirror.registerHelper('lint', 'csslint', code =>
|
2017-09-13 13:26:22 +00:00
|
|
|
CSSLint.verify(code, deepCopy(linterConfig.getCurrent('csslint')))
|
2017-08-28 05:22:19 +00:00
|
|
|
.messages.map(message => ({
|
|
|
|
from: CodeMirror.Pos(message.line - 1, message.col - 1),
|
|
|
|
to: CodeMirror.Pos(message.line - 1, message.col),
|
2017-08-31 18:36:18 +00:00
|
|
|
message: message.message,
|
|
|
|
rule: message.rule.id,
|
2017-08-28 05:22:19 +00:00
|
|
|
severity : message.type
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
|
|
|
|
CodeMirror.registerHelper('lint', 'stylelint', code =>
|
2017-09-13 13:26:22 +00:00
|
|
|
stylelint.lint({
|
2017-08-28 05:22:19 +00:00
|
|
|
code,
|
2017-08-29 21:05:07 +00:00
|
|
|
config: deepCopy(linterConfig.getCurrent('stylelint')),
|
2017-08-28 05:22:19 +00:00
|
|
|
}).then(({results}) => {
|
|
|
|
if (!results[0]) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return results[0].warnings.map(warning => ({
|
|
|
|
from: CodeMirror.Pos(warning.line - 1, warning.column - 1),
|
|
|
|
to: CodeMirror.Pos(warning.line - 1, warning.column),
|
|
|
|
message: warning.text
|
|
|
|
.replace('Unexpected ', '')
|
2017-08-31 18:36:18 +00:00
|
|
|
.replace(/^./, firstLetter => firstLetter.toUpperCase())
|
|
|
|
.replace(/\s*\([^(]+\)$/, ''), // strip the rule,
|
|
|
|
rule: warning.text.replace(/^.*?\s*\(([^(]+)\)$/, '$1'),
|
2017-08-28 05:22:19 +00:00
|
|
|
severity : warning.severity
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
);
|