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

Commit

Permalink
fix: behavior when endColumn or endLine is null
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlyons0 committed Feb 3, 2019
1 parent 0de1865 commit 40760c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit 40760c6

Please sign in to comment.