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

Fix behavior when endColumn or endLine is null #1217

Merged
merged 1 commit into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions spec/linter-eslint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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')
})
})
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {
Expand Down