From 06b6cee7cd4469c25ad672432682105f1ddeab61 Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Fri, 29 Apr 2022 18:17:18 -0400 Subject: [PATCH] Support logs with color output --- .github/problem-matcher.json | 10 +-- CHANGELOG.md | 2 + __tests__/problemMatcher.test.ts | 121 +++++++++++++++++++++---------- 3 files changed, 91 insertions(+), 42 deletions(-) diff --git a/.github/problem-matcher.json b/.github/problem-matcher.json index b0cf76b..5c63d08 100644 --- a/.github/problem-matcher.json +++ b/.github/problem-matcher.json @@ -8,11 +8,11 @@ "file": 1 }, { - "regexp": "^\\s+((\\d+):(\\d+))?\\s+(✖|×)\\s+(.*)\\s{3,}(.*)$", - "line": 2, - "column": 3, - "message": 5, - "code": 6, + "regexp": "^\\s+(?:(?:\\u001b\\[\\d+m)*(\\d+):(\\d+)(?:\\u001b\\[\\d+m)*)?\\s+(?:\\u001b\\[\\d+m)*(?:✖|×)(?:\\u001b\\[\\d+m)*\\s+(.*)\\s{2,}(?:\\u001b\\[\\d+m)*([^\\u001b]*)(?:\\u001b\\[\\d+m)*$", + "line": 1, + "column": 2, + "message": 3, + "code": 4, "loop": true } ] diff --git a/CHANGELOG.md b/CHANGELOG.md index 90b6ddf..f34d760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Support logs with color output (`FORCE_COLOR=true`) + ## [1.3.0](https://github.com/xt0rted/stylelint-problem-matcher/compare/v1.2.0...v1.3.0) - 2022-04-28 - Bumped `@actions/core` from 1.2.2 to 1.7.0 diff --git a/__tests__/problemMatcher.test.ts b/__tests__/problemMatcher.test.ts index a89b9b9..b1c8e6f 100644 --- a/__tests__/problemMatcher.test.ts +++ b/__tests__/problemMatcher.test.ts @@ -37,7 +37,10 @@ describe("problemMatcher", () => { }); }); - describe("violation pattern", () => { + describe.each([ + "✖", + "×", + ])("violation pattern using '%s'", (icon) => { let pattern: ProblemPattern; let regexp: RegExp; @@ -46,44 +49,88 @@ describe("problemMatcher", () => { regexp = new RegExp(pattern.regexp); }); - it("matches violations", () => { - const reportOutput = [ - "scss/_test.scss", - " 11:16 × Unexpected unit length-zero-no-unit", - " 11:28 × Unexpected unit length-zero-no-unit", - ]; - - const results = matchResults(reportOutput, regexp); - - expect(results.length).toEqual(2); - }); - - it("matches violations without line numbers", () => { - const reportOutput = [ - "scss/_test.scss", - " × Unexpected Unicode BOM unicode-bom", - " 11:16 × Unexpected unit length-zero-no-unit", - " 11:28 × Unexpected unit length-zero-no-unit", - ]; - - const results = matchResults(reportOutput, regexp); - - expect(results.length).toEqual(3); + describe("without color output", () => { + it("matches violations", () => { + const reportOutput = [ + "scss/_test.scss", + ` 11:16 ${icon} Unexpected unit length-zero-no-unit`, + ` 11:28 ${icon} Unexpected unit length-zero-no-unit`, + ]; + + const results = matchResults(reportOutput, regexp); + + expect(results.length).toEqual(2); + }); + + it("matches violations without line numbers", () => { + const reportOutput = [ + "scss/_test.scss", + ` ${icon} Unexpected Unicode BOM unicode-bom`, + ` 11:16 ${icon} Unexpected unit length-zero-no-unit`, + ` 11:28 ${icon} Unexpected unit length-zero-no-unit`, + ]; + + const results = matchResults(reportOutput, regexp); + + expect(results.length).toEqual(3); + }); + + it("matches violation details", () => { + const reportOutput = [ + "scss/_test.scss", + ` 11:16 ${icon} Unexpected unit length-zero-no-unit`, + ]; + + const results = matchResults(reportOutput, regexp); + + expect(results.length).toEqual(1); + expect(results[0][pattern.line!]).toEqual("11"); + expect(results[0][pattern.column!]).toEqual("16"); + expect(results[0][pattern.message!]).toEqual("Unexpected unit "); + expect(results[0][pattern.code!]).toEqual("length-zero-no-unit"); + }); }); - it("matches violation details", () => { - const reportOutput = [ - "scss/_test.scss", - " 11:16 × Unexpected unit length-zero-no-unit", - ]; - - const results = matchResults(reportOutput, regexp); - - expect(results.length).toEqual(1); - expect(results[0][pattern.line]).toEqual("11"); - expect(results[0][pattern.column]).toEqual("16"); - expect(results[0][pattern.message]).toEqual("Unexpected unit "); - expect(results[0][pattern.code]).toEqual("length-zero-no-unit"); + describe("with color output", () => { + it("matches violations", () => { + const reportOutput = [ + "scss/_test.scss", + ` \u001B[2m11:16\u001B[22m \u001B[31m\u001B[31m${icon}\u001B[39m Unexpected unit \u001B[2mlength-zero-no-unit\u001B[22m`, + ` \u001B[2m11:28\u001B[22m \u001B[31m\u001B[31m${icon}\u001B[39m Unexpected unit \u001B[2mlength-zero-no-unit\u001B[22m`, + ]; + + const results = matchResults(reportOutput, regexp); + + expect(results.length).toEqual(2); + }); + + it("matches violations without line numbers", () => { + const reportOutput = [ + "scss/_test.scss", + ` \u001B[31m\u001B[31m${icon}\u001B[39m Unexpected Unicode BOM \u001B[2municode-bom\u001B[22m`, + ` \u001B[2m11:16\u001B[22m \u001B[31m\u001B[31m${icon}\u001B[39m Unexpected unit \u001B[2mlength-zero-no-unit\u001B[22m`, + ` \u001B[2m11:28\u001B[22m \u001B[31m\u001B[31m${icon}\u001B[39m Unexpected unit \u001B[2mlength-zero-no-unit\u001B[22m`, + ]; + + const results = matchResults(reportOutput, regexp); + + expect(results.length).toEqual(3); + }); + + it("matches violation details", () => { + const reportOutput = [ + "scss/_test.scss", + ` \u001B[2m11:16\u001B[22m \u001B[31m\u001B[31m${icon}\u001B[39m Unexpected unit \u001B[2mlength-zero-no-unit\u001B[22m`, + ]; + + const results = matchResults(reportOutput, regexp); + + expect(results.length).toEqual(1); + expect(results[0][pattern.line!]).toEqual("11"); + expect(results[0][pattern.column!]).toEqual("16"); + expect(results[0][pattern.message!]).toEqual("Unexpected unit "); + expect(results[0][pattern.code!]).toEqual("length-zero-no-unit"); + }); }); }); });