From df0158da84be2d7bc5c10c6c4901c3b0f22d158e Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Tue, 9 Jan 2018 21:43:39 +0100 Subject: [PATCH] stylish-formatter: make filename clickable (#3491) Ref: https://github.com/palantir/tslint/issues/3460#issuecomment-342396889 --- src/formatters/stylishFormatter.ts | 7 +++---- test/formatters/stylishFormatterTests.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/formatters/stylishFormatter.ts b/src/formatters/stylishFormatter.ts index 3b2a097d62b..3b927327de6 100644 --- a/src/formatters/stylishFormatter.ts +++ b/src/formatters/stylishFormatter.ts @@ -62,11 +62,13 @@ export class Formatter extends AbstractFormatter { for (const failure of failures) { const fileName = failure.getFileName(); + const lineAndCharacter = failure.getStartPosition().getLineAndCharacter(); + let positionTuple = `${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`; // Output the name of each file once if (currentFile !== fileName) { outputLines.push(""); - outputLines.push(fileName); + outputLines.push(`${fileName}${chalk.hidden(`:${positionTuple}`)}`); currentFile = fileName; } @@ -79,9 +81,6 @@ export class Formatter extends AbstractFormatter { ruleName = chalk.grey(ruleName); // Lines - const lineAndCharacter = failure.getStartPosition().getLineAndCharacter(); - - let positionTuple = `${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`; positionTuple = this.pad(positionTuple, positionMaxSize); positionTuple = failure.getRuleSeverity() === "warning" diff --git a/test/formatters/stylishFormatterTests.ts b/test/formatters/stylishFormatterTests.ts index 4e8381fbb30..603ceef26fe 100644 --- a/test/formatters/stylishFormatterTests.ts +++ b/test/formatters/stylishFormatterTests.ts @@ -47,7 +47,7 @@ describe("Stylish Formatter", () => { const maxPositionTuple = `${maxPositionObj.line + 1}:${maxPositionObj.character + 1}`; const expectedResult = dedent` - formatters/stylishFormatter.test.ts + formatters/stylishFormatter.test.ts\u001b[8m:1:1\u001b[28m \u001b[31mERROR: 1:1\u001b[39m \u001b[90mfirst-name\u001b[39m \u001b[33mfirst failure\u001b[39m \u001b[31mERROR: 1:1\u001b[39m \u001b[90mfull-name \u001b[39m \u001b[33mfull failure\u001b[39m \u001b[31mERROR: 1:3\u001b[39m \u001b[90mescape \u001b[39m \u001b[33m&<>'\" should be escaped\u001b[39m