forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Visual Studio compatible formatter (fixes eslint#4708)
- Loading branch information
1 parent
3dcd374
commit 38450af
Showing
3 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @fileoverview VisualStudio reporter | ||
* @author Ronald Pijnacker | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Helper Functions | ||
//------------------------------------------------------------------------------ | ||
|
||
/** | ||
* Returns the severity of warning or error | ||
* @param {object} message message object to examine | ||
* @returns {string} severity level | ||
* @private | ||
*/ | ||
function getMessageType(message) { | ||
if (message.fatal || message.severity === 2) { | ||
return "[Error] "; | ||
} else { | ||
return "[Warning]"; | ||
} | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
// Public Interface | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function(results) { | ||
|
||
var output = "", | ||
total = 0; | ||
|
||
results.forEach(function(result) { | ||
|
||
var messages = result.messages; | ||
total += messages.length; | ||
|
||
messages.forEach(function(message) { | ||
|
||
output += result.filePath; | ||
output += "(" + (message.line || 0); | ||
output += "," + (message.column || 0); | ||
output += "):\t" + getMessageType(message); | ||
output += " " + message.message; | ||
output += message.ruleId ? "\t(" + message.ruleId + ")" : ""; | ||
output += "\n"; | ||
|
||
}); | ||
|
||
}); | ||
|
||
if (total > 0) { | ||
output += "\n" + total + " problem" + (total !== 1 ? "s" : ""); | ||
} | ||
|
||
return output; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* @fileoverview Tests for VisualStudio format. | ||
* @author Ronald Pijnacker | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var assert = require("chai").assert, | ||
formatter = require("../../../lib/formatters/visualstudio"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
describe("formatter:visualstudio", function() { | ||
describe("when passed no messages", function() { | ||
var code = [{ | ||
filePath: "foo.js", | ||
messages: [] | ||
}]; | ||
|
||
it("should return nothing", function() { | ||
var result = formatter(code); | ||
assert.equal(result, ""); | ||
}); | ||
}); | ||
|
||
describe("when passed a single message", function() { | ||
var code = [{ | ||
filePath: "foo.js", | ||
messages: [{ | ||
message: "Unexpected foo.", | ||
severity: 2, | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}] | ||
}]; | ||
|
||
it("should return a string in the format filename(x,y):\t[Error] z for errors", function() { | ||
var result = formatter(code); | ||
assert.equal(result, "foo.js(5,10):\t[Error] Unexpected foo.\t(foo)\n\n1 problem"); | ||
}); | ||
|
||
it("should return a string in the format filename(x,y):\t[Warning] z for warnings", function() { | ||
code[0].messages[0].severity = 1; | ||
var result = formatter(code); | ||
assert.equal(result, "foo.js(5,10):\t[Warning] Unexpected foo.\t(foo)\n\n1 problem"); | ||
}); | ||
}); | ||
|
||
describe("when passed a fatal error message", function() { | ||
var code = [{ | ||
filePath: "foo.js", | ||
messages: [{ | ||
fatal: true, | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}] | ||
}]; | ||
|
||
it("should return a string in the format filename(x,y):\t[Error] z", function() { | ||
var result = formatter(code); | ||
assert.equal(result, "foo.js(5,10):\t[Error] Unexpected foo.\t(foo)\n\n1 problem"); | ||
}); | ||
}); | ||
|
||
describe("when passed multiple messages", function() { | ||
var code = [{ | ||
filePath: "foo.js", | ||
messages: [{ | ||
message: "Unexpected foo.", | ||
severity: 2, | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}, { | ||
message: "Unexpected bar.", | ||
severity: 1, | ||
line: 6, | ||
column: 11, | ||
ruleId: "bar" | ||
}] | ||
}]; | ||
|
||
it("should return a string with multiple entries", function() { | ||
var result = formatter(code); | ||
assert.equal(result, "foo.js(5,10):\t[Error] Unexpected foo.\t(foo)\nfoo.js(6,11):\t[Warning] Unexpected bar.\t(bar)\n\n2 problems"); | ||
}); | ||
}); | ||
|
||
describe("when passed multiple files with 1 message each", function() { | ||
var code = [{ | ||
filePath: "foo.js", | ||
messages: [{ | ||
message: "Unexpected foo.", | ||
severity: 2, | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}] | ||
}, { | ||
filePath: "bar.js", | ||
messages: [{ | ||
message: "Unexpected bar.", | ||
severity: 1, | ||
line: 6, | ||
column: 11, | ||
ruleId: "bar" | ||
}] | ||
}]; | ||
|
||
it("should return a string with multiple entries", function() { | ||
var result = formatter(code); | ||
assert.equal(result, "foo.js(5,10):\t[Error] Unexpected foo.\t(foo)\nbar.js(6,11):\t[Warning] Unexpected bar.\t(bar)\n\n2 problems"); | ||
}); | ||
}); | ||
|
||
describe("when passed one file not found message", function() { | ||
var code = [{ | ||
filePath: "foo.js", | ||
messages: [{ | ||
fatal: true, | ||
message: "Couldn't find foo.js." | ||
}] | ||
}]; | ||
|
||
it("should return a string without line and column", function() { | ||
var result = formatter(code); | ||
assert.equal(result, "foo.js(0,0):\t[Error] Couldn't find foo.js.\n\n1 problem"); | ||
}); | ||
}); | ||
}); |