separate 'rule' property in lint annotations

This commit is contained in:
tophf 2017-08-31 21:36:18 +03:00
parent 7f9c377d33
commit ec01914f17
2 changed files with 8 additions and 7 deletions

View File

@ -6,7 +6,8 @@ CodeMirror.registerHelper('lint', 'csslint', code =>
.messages.map(message => ({ .messages.map(message => ({
from: CodeMirror.Pos(message.line - 1, message.col - 1), from: CodeMirror.Pos(message.line - 1, message.col - 1),
to: CodeMirror.Pos(message.line - 1, message.col), to: CodeMirror.Pos(message.line - 1, message.col),
message: message.message + ` (${message.rule.id})`, message: message.message,
rule: message.rule.id,
severity : message.type severity : message.type
})) }))
); );
@ -24,7 +25,9 @@ CodeMirror.registerHelper('lint', 'stylelint', code =>
to: CodeMirror.Pos(warning.line - 1, warning.column), to: CodeMirror.Pos(warning.line - 1, warning.column),
message: warning.text message: warning.text
.replace('Unexpected ', '') .replace('Unexpected ', '')
.replace(/^./, firstLetter => firstLetter.toUpperCase()), .replace(/^./, firstLetter => firstLetter.toUpperCase())
.replace(/\s*\([^(]+\)$/, ''), // strip the rule,
rule: warning.text.replace(/^.*?\s*\(([^(]+)\)$/, '$1'),
severity : warning.severity severity : warning.severity
})); }));
}) })

View File

@ -237,16 +237,14 @@ function updateLintReport(cm, delay) {
const pos = isActiveLine ? 'cursor' : (info.from.line + ',' + info.from.ch); const pos = isActiveLine ? 'cursor' : (info.from.line + ',' + info.from.ch);
// rule name added in parentheses at the end; extract it out for the info popup // rule name added in parentheses at the end; extract it out for the info popup
const text = info.message; const text = info.message;
const parenPos = text.endsWith(')') ? text.lastIndexOf('(') : text.length; const title = escapeHtml(text + `\n(${info.rule})`, {limit: 1000});
const ruleName = text.slice(parenPos + 1, -1); const message = escapeHtml(text, {limit: 100});
const title = escapeHtml(text);
const message = escapeHtml(text.substr(0, Math.min(100, parenPos)), {limit: 100});
if (isActiveLine || oldMarkers[pos] === message) { if (isActiveLine || oldMarkers[pos] === message) {
delete oldMarkers[pos]; delete oldMarkers[pos];
} }
newMarkers[pos] = message; newMarkers[pos] = message;
return `<tr class="${info.severity}"> return `<tr class="${info.severity}">
<td role="severity" data-rule="${ruleName}"> <td role="severity" data-rule="${info.rule}">
<div class="CodeMirror-lint-marker-${info.severity}">${info.severity}</div> <div class="CodeMirror-lint-marker-${info.severity}">${info.severity}</div>
</td> </td>
<td role="line">${info.from.line + 1}</td> <td role="line">${info.from.line + 1}</td>