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 Oct 6, 2016
1 parent fb7436c commit b616e09
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/helpers.js
Expand Up @@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
exports.spawnWorker = spawnWorker;
exports.showError = showError;
exports.idsToIgnoredRules = idsToIgnoredRules;
exports.validatePoint = validatePoint;

var _child_process = require('child_process');

Expand Down Expand Up @@ -74,3 +75,11 @@ function idsToIgnoredRules() {
return ids;
}, {});
}

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 @@ -167,6 +167,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 @@ -178,8 +180,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 @@ -56,3 +56,11 @@ export function idsToIgnoredRules(ruleIds = []) {
return ids
}, {})
}

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!`)
}
}
18 changes: 13 additions & 5 deletions src/main.js
Expand Up @@ -6,7 +6,7 @@ import ruleURI from 'eslint-rule-documentation'
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable, Range } from 'atom'

import { spawnWorker, showError, idsToIgnoredRules } from './helpers'
import { spawnWorker, showError, idsToIgnoredRules, validatePoint } from './helpers'

// Configuration
const scopes = []
Expand Down Expand Up @@ -150,7 +150,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 @@ -164,10 +166,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 b616e09

Please sign in to comment.