Skip to content

Commit

Permalink
Utilize ESLint’s endLine and endColumn
Browse files Browse the repository at this point in the history
Consider the following code snippet:

    function fn () {
      let x = 1
      return x
      x = 3
    }

By utilizing ESLint’s `endLine` and `endColumn` properties, we highlight the whole fourth line (`x = 3`) since it is unreachable code.
  • Loading branch information
sonicdoe committed Aug 27, 2017
1 parent 24e76ae commit e5d31dc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/utils/linter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const getRuleURI = require('eslint-rule-documentation')
const generateRange = require('atom-linter').generateRange

function getRange (textEditor, line, col, src, lineStart) {
function getRange (textEditor, line, col, endLine, endCol, src, lineStart) {
line = typeof line !== 'undefined' ? parseInt((line - 1) + lineStart, 10) : 0
col = typeof col !== 'undefined' ? parseInt(col - 1, 10) : 0
endLine = typeof endLine !== 'undefined' ? parseInt((endLine - 1) + lineStart, 10) : null
endCol = typeof endCol !== 'undefined' ? parseInt(endCol - 1, 10) : null
src = src || ''
src = src.substring(0, col)

if (endLine && endCol) {
return [[line, col], [endLine, endCol]]
}

return generateRange(textEditor, line, col)
}

Expand All @@ -30,7 +36,15 @@ module.exports = function (err, output) {
excerpt: msg.message,
location: {
file: self.filePath,
position: getRange(self.textEditor, msg.line, msg.column, msg.source, self.lineStart)
position: getRange(
self.textEditor,
msg.line,
msg.column,
msg.endLine,
msg.endColumn,
msg.source,
self.lineStart
)
}
}

Expand Down

0 comments on commit e5d31dc

Please sign in to comment.