2017-08-28 05:22:19 +00:00
|
|
|
/* global CodeMirror CSSLint stylelint linterConfig */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
CodeMirror.registerHelper('lint', 'csslint', code =>
|
2017-08-29 21:05:07 +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),
|
|
|
|
message: message.message + ` (${message.rule.id})`,
|
|
|
|
severity : message.type
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
|
|
|
|
CodeMirror.registerHelper('lint', 'stylelint', code =>
|
|
|
|
stylelint.lint({
|
|
|
|
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 ', '')
|
|
|
|
.replace(/^./, firstLetter => firstLetter.toUpperCase()),
|
|
|
|
severity : warning.severity
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
);
|