diff --git a/lib/helpers.js b/lib/helpers.js index 83cadaed..defbae7a 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.spawnWorker = spawnWorker; exports.showError = showError; +exports.validatePoint = validatePoint; var _child_process = require('child_process'); @@ -61,3 +62,11 @@ function showError(givenMessage) { dismissable: true }); } + +function validatePoint(textEditor, line, col) { + var buffer = textEditor.getBuffer(); + // Clip the given point to a valid one, and check if it equals the original + if (!buffer.clipPosition([line, col]).isEqual([line, col])) { + throw new Error(line + ':' + col + ' isn\'t a valid point!'); + } +} diff --git a/lib/main.js b/lib/main.js index 41f69d9a..1a7e330d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -141,6 +141,8 @@ module.exports = { var ruleId = _ref.ruleId; var column = _ref.column; var fix = _ref.fix; + var endLine = _ref.endLine; + var endColumn = _ref.endColumn; var textBuffer = textEditor.getBuffer(); var linterFix = null; @@ -152,8 +154,16 @@ module.exports = { }; } var range = void 0; + var msgLine = line - 1; + var msgCol = column ? column - 1 : column; try { - range = Helpers.rangeFromLineNumber(textEditor, line - 1, column ? column - 1 : column); + if (endColumn && endLine) { + (0, _helpers.validatePoint)(textEditor, msgLine, msgCol); + (0, _helpers.validatePoint)(textEditor, endLine - 1, endColumn - 1); + range = [[msgLine, msgCol], [endLine - 1, endColumn - 1]]; + } else { + range = Helpers.rangeFromLineNumber(textEditor, msgLine, msgCol); + } } catch (err) { throw new Error('Cannot mark location in editor for (' + ruleId + ') - (' + message + ')' + (' at line (' + line + ') column (' + column + ')')); } diff --git a/src/helpers.js b/src/helpers.js index 00467285..681f9ebe 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -46,3 +46,11 @@ export function showError(givenMessage, givenDetail = null) { dismissable: true }) } + +export function validatePoint(textEditor, line, col) { + const buffer = textEditor.getBuffer() + // Clip the given point to a valid one, and check if it equals the original + if (!buffer.clipPosition([line, col]).isEqual([line, col])) { + throw new Error(`${line}:${col} isn't a valid point!`) + } +} diff --git a/src/main.js b/src/main.js index d825bc23..c9638bd1 100644 --- a/src/main.js +++ b/src/main.js @@ -4,8 +4,7 @@ import escapeHTML from 'escape-html' import ruleURI from 'eslint-rule-documentation' // eslint-disable-next-line import/no-extraneous-dependencies import { CompositeDisposable, Range } from 'atom' - -import { spawnWorker, showError } from './helpers' +import { spawnWorker, showError, validatePoint } from './helpers' module.exports = { activate() { @@ -119,7 +118,9 @@ module.exports = { */ return null } - return response.map(({ message, line, severity, ruleId, column, fix }) => { + return response.map(({ + message, line, severity, ruleId, column, fix, endLine, endColumn } + ) => { const textBuffer = textEditor.getBuffer() let linterFix = null if (fix) { @@ -133,10 +134,16 @@ module.exports = { } } let range + const msgLine = line - 1 + const msgCol = column ? column - 1 : column try { - range = Helpers.rangeFromLineNumber( - textEditor, line - 1, column ? column - 1 : column - ) + if (endColumn && endLine) { + validatePoint(textEditor, msgLine, msgCol) + validatePoint(textEditor, endLine - 1, endColumn - 1) + range = [[msgLine, msgCol], [endLine - 1, endColumn - 1]] + } else { + range = Helpers.rangeFromLineNumber(textEditor, msgLine, msgCol) + } } catch (err) { throw new Error( `Cannot mark location in editor for (${ruleId}) - (${message})` +