Skip to content

Commit

Permalink
fixed highlighting of parse error
Browse files Browse the repository at this point in the history
fixed highlighting of unknown properties
  • Loading branch information
smelukov committed Jan 19, 2017
1 parent f683978 commit 9239223
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,44 @@ export function activate() {
require('atom-package-deps').install('csstree-validator');
}

const TYPE_WARNING = 'Warning';
const TYPE_ERROR = 'Error';
const SEVERITY_WARNING = 'warning';
const SEVERITY_ERROR = 'error';

function lint(editor, filePath) {
let report = validateString(editor.getText());

return Object.keys(report)
.reduce((r, c) => r.concat(report[c]), [])
.map(warning => {
let range = new Range();
let type = TYPE_WARNING;
let severity = SEVERITY_WARNING;

range.start = new Point(warning.line - 1, warning.column - 1);

if (warning.loc) {
let endLine = warning.loc.end.line - 1;
let endColumn = warning.loc.end.column - 1;

range.start = new Point(warning.loc.start.line - 1, warning.loc.start.column - 1);
range.end = new Point(warning.loc.end.line - 1, warning.loc.end.column - 1);
if (!warning.message.indexOf('Unknown property')) {
range.end = new Point(range.start.row, range.start.column + warning.property.length);
} else {
range.end = new Point(endLine, endColumn);
}
} else {
type = TYPE_ERROR;
severity = SEVERITY_ERROR;
range.end = new Point(range.start.row, range.start.column + 1);
}

return {
type: 'Warning',
severity: 'warning',
text: warning.message,
type,
severity,
range,
filePath
filePath,
text: warning.message
}
});
}
Expand Down

0 comments on commit 9239223

Please sign in to comment.