From 40760c621600779263830d05dead32015ab7ee83 Mon Sep 17 00:00:00 2001 From: Matt Lyons Date: Mon, 7 Jan 2019 11:15:57 -0500 Subject: [PATCH] fix: behavior when endColumn or endLine is null Fixes #1197, #1196, #1195, #1192 --- spec/linter-eslint-spec.js | 22 ++++++++++++++++++++++ src/helpers.js | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/spec/linter-eslint-spec.js b/spec/linter-eslint-spec.js index 1516e405..48d69c6a 100644 --- a/spec/linter-eslint-spec.js +++ b/spec/linter-eslint-spec.js @@ -8,6 +8,8 @@ import rimraf from 'rimraf' import { beforeEach, it, fit } from 'jasmine-fix' import linterEslint from '../src/main' +import { processESLintMessages } from '../src/helpers' + const fixturesDir = path.join(__dirname, 'fixtures') const fixtures = { @@ -706,3 +708,23 @@ describe('The eslint provider for Linter', () => { ))) }) }) + +describe('processESLintMessages', () => { + it('handles messages with null endColumn', async () => { + // Get a editor instance with at least a single line + const editor = await atom.workspace.open(paths.good) + + const result = await processESLintMessages([{ + column: null, + endColumn: null, + line: 1, + endLine: null, + message: 'Test Null endColumn', + nodeType: 'Block', + ruleId: 'test-null-endcolumn', + severity: 2, + }], editor, false) + + expect(result[0].excerpt).toBe('Test Null endColumn') + }) +}) diff --git a/src/helpers.js b/src/helpers.js index 2b6eac9d..68b3bd3e 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -274,7 +274,7 @@ export async function processESLintMessages(messages, textEditor, showRule) { keep doing so in later uses. */ const msgLine = line - 1 - if (typeof endColumn !== 'undefined' && typeof endLine !== 'undefined') { + if (typeof endColumn === 'number' && typeof endLine === 'number') { eslintFullRange = true // Here we always want the column to be a number msgCol = Math.max(0, column - 1) @@ -283,7 +283,7 @@ export async function processESLintMessages(messages, textEditor, showRule) { } else { // We want msgCol to remain undefined if it was initially so // `generateRange` will give us a range over the entire line - msgCol = typeof column !== 'undefined' ? column - 1 : column + msgCol = typeof column === 'number' ? column - 1 : column } let ret = {