Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Add support for endLine and endColumn
Browse files Browse the repository at this point in the history
Add support for creating a full range from an ESLint message if it
specifies an `endLine` and `endColumn`. Also adds a `validatePoint` helper
function to check that these coordinates given from ESLint are valid since
we no longer have the checking built into `helpers.rangeFromLineNumber`.
  • Loading branch information
Arcanemagus committed Sep 21, 2016
1 parent 6505411 commit e8a5cb0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/helpers.js
Expand Up @@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.spawnWorker = spawnWorker;
exports.showError = showError;
exports.validatePoint = validatePoint;

var _child_process = require('child_process');

Expand Down Expand Up @@ -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!');
}
}
12 changes: 11 additions & 1 deletion lib/main.js
Expand Up @@ -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;
Expand All @@ -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 + ')'));
}
Expand Down
8 changes: 8 additions & 0 deletions src/helpers.js
Expand Up @@ -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!`)
}
}
19 changes: 13 additions & 6 deletions src/main.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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})` +
Expand Down

0 comments on commit e8a5cb0

Please sign in to comment.