Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Output more location data in lint errors #645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/lexical_linter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = class LexicalLinter extends BaseLinter
lintToken: (token) ->
[type, value, { first_line: lineNumber }] = token

@token = token
@tokensByLine[lineNumber] ?= []
@tokensByLine[lineNumber].push(token)
# CoffeeScript loses line numbers of interpolations and multi-line
Expand All @@ -64,4 +65,5 @@ module.exports = class LexicalLinter extends BaseLinter
attrs.lineNumber ?= @lineNumber
attrs.lineNumber += 1
attrs.line = @tokenApi.lines[attrs.lineNumber - 1]
attrs.location ?= @token[2]
super ruleName, attrs
1 change: 1 addition & 0 deletions src/rules/cyclomatic_complexity.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = class CyclomaticComplexity
context: complexity + 1
lineNumber: node.locationData.first_line + 1
lineNumberEnd: node.locationData.last_line + 1
location: node.locationData
}
@errors.push error if error

Expand Down
8 changes: 7 additions & 1 deletion src/rules/indentation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ module.exports = class Indentation
if dotIndent % expected isnt 0
return {
context: "Expected #{expected} got #{got}"
expected: expected
actual: got
}

return undefined
Expand Down Expand Up @@ -97,7 +99,11 @@ module.exports = class Indentation

# Now check the indentation.
if not ignoreIndent and not (expected in numIndents)
return { context: "Expected #{expected} got #{numIndents[0]}" }
return {
context: "Expected #{expected} got #{numIndents[0]}"
expected: expected
actual: numIndents[0]
}

# Return true if the current token is inside of an array.
inArray: () ->
Expand Down
1 change: 1 addition & 0 deletions src/rules/missing_fat_arrows.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = class MissingFatArrows
(@needsFatArrow node)
error = @astApi.createError
lineNumber: node.locationData.first_line + 1
location: node.locationData
@errors.push error

node.eachChild (child) => @lintNode child,
Expand Down
1 change: 1 addition & 0 deletions src/rules/no_empty_functions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ module.exports = class NoEmptyFunctions
if isEmptyCode node, astApi
error = astApi.createError
lineNumber: node.locationData.first_line + 1
location: node.locationData
@errors.push error
node.eachChild (child) => @lintNode child, astApi
1 change: 1 addition & 0 deletions src/rules/no_private_function_fat_arrows.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = class NoPrivateFunctionFatArrows
if @isFatArrowCode(node) and node in functions
error = @astApi.createError
lineNumber: node.locationData.first_line + 1
location: node.locationData
@errors.push error

node.eachChild (child) => @lintNode child,
Expand Down
1 change: 1 addition & 0 deletions src/rules/no_unnecessary_fat_arrows.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = class NoUnnecessaryFatArrows
if (@isFatArrowCode node) and (not @needsFatArrow node)
error = @astApi.createError
lineNumber: node.locationData.first_line + 1
location: node.locationData
@errors.push error
node.eachChild (child) => @lintNode child

Expand Down