-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mstankowiak/master
Formatting as inspections - fixes #7
- Loading branch information
Showing
8 changed files
with
282 additions
and
103 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
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,88 @@ | ||
import * as path from 'path'; | ||
|
||
import { RuleFailure } from 'tslint'; | ||
import { getOutputMessage, TeamCityMessages } from '../util'; | ||
|
||
export function formatAsTests(failures: RuleFailure[], config: { [key: string]: string }) { | ||
const { reportName } = config; | ||
|
||
const output = []; | ||
let errorCount = 0; | ||
let warningCount = 0; | ||
|
||
output.push(getOutputMessage(TeamCityMessages.TEST_SUITE_STARTED, { report: reportName })); | ||
|
||
// group failures per file, instead of reporting each failure individually | ||
const failuresByFile = failures.reduce<{ | ||
[key: string]: { filePath?: string; messages?: Array<RuleFailure> }; | ||
}>((acc, f) => { | ||
const file = f.getFileName(); | ||
if (!acc[file]) acc[file] = { filePath: file, messages: [] }; | ||
acc[file].messages.push(f); | ||
return acc; | ||
}, {}); | ||
|
||
Object.values(failuresByFile).forEach(result => { | ||
const filePath = path.relative(process.cwd(), result.filePath); | ||
output.push( | ||
getOutputMessage(TeamCityMessages.TEST_STARTED, { report: reportName, file: filePath }), | ||
); | ||
|
||
const errorsList = []; | ||
const warningsList = []; | ||
|
||
result.messages.forEach(failure => { | ||
const startPos = failure.getStartPosition().getLineAndCharacter(); | ||
const formattedMessage = `line ${startPos.line}, col ${ | ||
startPos.character | ||
}, ${failure.getFailure()} (${failure.getRuleName()})`; | ||
|
||
const isError = failure.getRuleSeverity() === 'error'; | ||
if (!isError) { | ||
warningsList.push(formattedMessage); | ||
warningCount += 1; | ||
} else { | ||
errorsList.push(formattedMessage); | ||
errorCount += 1; | ||
} | ||
}); | ||
|
||
// Group errors and warnings together per file | ||
if (errorsList.length) { | ||
const errors = errorsList.join('\n'); | ||
output.push( | ||
getOutputMessage(TeamCityMessages.TEST_FAILED, { | ||
errors, | ||
report: reportName, | ||
file: filePath, | ||
}), | ||
); | ||
} | ||
|
||
if (warningsList.length) { | ||
const warnings = warningsList.join('\n'); | ||
output.push( | ||
getOutputMessage(TeamCityMessages.TEST_STD_OUT, { | ||
warnings, | ||
report: reportName, | ||
file: filePath, | ||
}), | ||
); | ||
} | ||
|
||
output.push( | ||
getOutputMessage(TeamCityMessages.TEST_FINISHED, { report: reportName, file: filePath }), | ||
); | ||
}); | ||
|
||
output.push(getOutputMessage(TeamCityMessages.TEST_SUITE_FINISHED, { report: reportName })); | ||
|
||
output.push( | ||
...(<Array<string>>getOutputMessage(TeamCityMessages.BUILD_STATISTIC_VALUE, { | ||
[config.errorStatisticsName]: errorCount, | ||
[config.warningStatisticsName]: warningCount, | ||
})), | ||
); | ||
|
||
return output.join('\n'); | ||
} |
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,62 @@ | ||
import * as path from 'path'; | ||
|
||
import { RuleFailure } from 'tslint'; | ||
import { getOutputMessage, TeamCityMessages } from '../util'; | ||
|
||
export function formatAsInspections(failures: RuleFailure[], config: { [key: string]: string }) { | ||
const { reportName } = config; | ||
|
||
const output = []; | ||
let errorCount = 0; | ||
let warningCount = 0; | ||
|
||
// group failures per file, instead of reporting each failure individually | ||
const failuresByRule = failures.reduce<{ | ||
[key: string]: { ruleName?: string; messages?: Array<RuleFailure> }; | ||
}>((acc, f) => { | ||
const ruleName = f.getRuleName(); | ||
if (!acc[ruleName]) acc[ruleName] = { ruleName, messages: [] }; | ||
acc[ruleName].messages.push(f); | ||
return acc; | ||
}, {}); | ||
|
||
Object.values(failuresByRule).forEach(result => { | ||
output.push( | ||
getOutputMessage(TeamCityMessages.INSPECTION_TYPE, { reportName, ruleName: result.ruleName }), | ||
); | ||
|
||
result.messages.forEach(failure => { | ||
const filePath = path.relative(process.cwd(), failure.getFileName()); | ||
const startPos = failure.getStartPosition().getLineAndCharacter(); | ||
const formattedMessage = `line ${startPos.line}, col ${ | ||
startPos.character | ||
}, ${failure.getFailure()}`; | ||
|
||
const isError = failure.getRuleSeverity() === 'error'; | ||
const severity = isError ? 'ERROR' : 'WARNING'; | ||
if (isError) { | ||
errorCount += 1; | ||
} else { | ||
warningCount += 1; | ||
} | ||
output.push( | ||
getOutputMessage(TeamCityMessages.INSPECTION, { | ||
formattedMessage, | ||
filePath, | ||
severity, | ||
ruleName: result.ruleName, | ||
line: startPos.line, | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
output.push( | ||
...(<Array<string>>getOutputMessage(TeamCityMessages.BUILD_STATISTIC_VALUE, { | ||
[config.errorStatisticsName]: errorCount, | ||
[config.warningStatisticsName]: warningCount, | ||
})), | ||
); | ||
|
||
return output.join('\n'); | ||
} |
Oops, something went wrong.