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

Commit

Permalink
Add severity support for vso formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoedermayr committed Nov 12, 2018
1 parent 1012e56 commit e057fc5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/formatters/vsoFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ export class Formatter extends AbstractFormatter {
const outputLines = failures.map((failure: RuleFailure) => {
const fileName = failure.getFileName();
const failureString = failure.getFailure();
const failureSeverity = failure.getRuleSeverity();
const lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
const line = lineAndCharacter.line + 1;
const character = lineAndCharacter.character + 1;
const code = failure.getRuleName();
const properties = `sourcepath=${fileName};linenumber=${line};columnnumber=${character};code=${code};`;

return `##vso[task.logissue type=warning;${properties}]${failureString}`;
return `##vso[task.logissue type=${failureSeverity};${properties}]${failureString}`;
});

return `${outputLines.join("\n")}\n`;
Expand Down
42 changes: 35 additions & 7 deletions test/formatters/vsoFormatterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe("VSO Formatter", () => {
];

const expectedResult =
getFailureString(TEST_FILE, 1, 1, "first failure", "first-name") +
getFailureString(TEST_FILE, 2, 12, "mid failure", "mid-name") +
getFailureString(TEST_FILE, 9, 2, "last failure", "last-name");
getFailureString(TEST_FILE, 1, 1, "first failure", "first-name", "error") +
getFailureString(TEST_FILE, 2, 12, "mid failure", "mid-name", "error") +
getFailureString(TEST_FILE, 9, 2, "last failure", "last-name", "error");

const actualResult = formatter.format(failures);
assert.equal(actualResult, expectedResult);
Expand All @@ -75,16 +75,42 @@ describe("VSO Formatter", () => {
];

const expectedResult =
getFailureString(TEST_FILE, 1, 1, "first failure", "first-name") +
getFailureString(TEST_FILE, 2, 12, "mid failure", "mid-name") +
getFailureString(TEST_FILE, 9, 2, "last failure", "last-name");
getFailureString(TEST_FILE, 1, 1, "first failure", "first-name", "error") +
getFailureString(TEST_FILE, 2, 12, "mid failure", "mid-name", "error") +
getFailureString(TEST_FILE, 9, 2, "last failure", "last-name", "error");

const fixed = failures.slice();

const actualResult = formatter.format(failures, fixed);
assert.equal(actualResult, expectedResult);
});

it("outputs correct severity", () => {
const maxPosition = sourceFile.getFullWidth();

const failures = [
createFailure(sourceFile, 0, 1, "first failure", "first-name", undefined, "error"),
createFailure(sourceFile, 32, 36, "mid failure", "mid-name", undefined, "warning"),
createFailure(
sourceFile,
maxPosition - 1,
maxPosition,
"last failure",
"last-name",
undefined,
"error",
),
];

const expectedResult =
getFailureString(TEST_FILE, 1, 1, "first failure", "first-name", "error") +
getFailureString(TEST_FILE, 2, 12, "mid failure", "mid-name", "warning") +
getFailureString(TEST_FILE, 9, 2, "last failure", "last-name", "error");

const actualResult = formatter.format(failures);
assert.equal(actualResult, expectedResult);
});

it("handles no failures", () => {
const result = formatter.format([]);
assert.equal(result, "\n");
Expand All @@ -96,7 +122,9 @@ describe("VSO Formatter", () => {
character: number,
reason: string,
code: string,
severity: string,
) {
return `##vso[task.logissue type=warning;sourcepath=${file};linenumber=${line};columnnumber=${character};code=${code};]${reason}\n`;
const properties = `sourcepath=${file};linenumber=${line};columnnumber=${character};code=${code};`;
return `##vso[task.logissue type=${severity};${properties}]${reason}\n`;
}
});

0 comments on commit e057fc5

Please sign in to comment.