Skip to content

Commit

Permalink
Match errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xt0rted committed Apr 29, 2022
1 parent e938eb1 commit 3f54025
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 70 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Updated to run on Node 16
- Converted to es modules
- Updated problem matcher to support errors and warnings
- The problem matcher owner changed from `stylelint` to `stylelint-error` and the new one is `stylelint-warning`

## [1.3.0](https://github.com/xt0rted/stylelint-problem-matcher/compare/v1.2.0...v1.3.0) - 2022-04-28

Expand Down
222 changes: 161 additions & 61 deletions __tests__/problemMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,94 +10,194 @@ import type {
} from "github-actions-problem-matcher-typings";

describe("problemMatcher", () => {
let problemMatcher: ProblemMatcher;
let problemMatcherDocument: ProblemMatcherDocument;

beforeAll(async () => {
const matcherFile = fileURLToPath(new URL("../src/problem-matcher.json", import.meta.url));
const fileContents = await readFile(matcherFile, { encoding: "utf8" });
const problemMatcherDocument = JSON.parse(fileContents) as ProblemMatcherDocument;

problemMatcher = problemMatcherDocument.problemMatcher[0];
problemMatcherDocument = JSON.parse(fileContents);
});

it("has the correct owner", () => {
expect(problemMatcher.owner).toEqual("stylelint");
it("has two matchers", () => {
expect(problemMatcherDocument.problemMatcher.length).toEqual(2);
});

it("has two patterns", () => {
expect(problemMatcher.pattern.length).toEqual(2);
});

describe("file pattern", () => {
let pattern: ProblemPattern;
let regexp: RegExp;
describe("error matcher", () => {
let problemMatcher: ProblemMatcher;

beforeEach(() => {
pattern = problemMatcher.pattern[0];
regexp = new RegExp(pattern.regexp);
beforeAll(() => {
problemMatcher = problemMatcherDocument.problemMatcher[0];
});

it("matches file path", () => {
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);
it("has the correct owner", () => {
expect(problemMatcher.owner).toEqual("stylelint-error");
});

expect(results.length).toEqual(1);
expect(results[0][pattern.file!]).toEqual("scss/_test.scss");
it("has two patterns", () => {
expect(problemMatcher.pattern.length).toEqual(2);
});

describe("file pattern", () => {
let pattern: ProblemPattern;
let regexp: RegExp;

beforeEach(() => {
pattern = problemMatcher.pattern[0];
regexp = new RegExp(pattern.regexp);
});

it("matches file path", () => {
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(1);
expect(results[0][pattern.file!]).toEqual("scss/_test.scss");
});
});

describe("violation pattern", () => {
let pattern: ProblemPattern;
let regexp: RegExp;

beforeEach(() => {
pattern = problemMatcher.pattern[1];
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);
});

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("violation pattern", () => {
let pattern: ProblemPattern;
let regexp: RegExp;
describe("warning matcher", () => {
let problemMatcher: ProblemMatcher;

beforeEach(() => {
pattern = problemMatcher.pattern[1];
regexp = new RegExp(pattern.regexp);
beforeAll(() => {
problemMatcher = problemMatcherDocument.problemMatcher[1];
});

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);
it("has the correct owner", () => {
expect(problemMatcher.owner).toEqual("stylelint-warning");
});

expect(results.length).toEqual(2);
it("has two patterns", () => {
expect(problemMatcher.pattern.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",
];
describe("file pattern", () => {
let pattern: ProblemPattern;
let regexp: RegExp;

const results = matchResults(reportOutput, regexp);
beforeEach(() => {
pattern = problemMatcher.pattern[0];
regexp = new RegExp(pattern.regexp);
});

expect(results.length).toEqual(3);
});
it("matches file path", () => {
const reportOutput = [
"scss/_test.scss",
" 11:16 ⚠ Unexpected unit length-zero-no-unit",
" 11:28 ⚠ Unexpected unit 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);

const results = matchResults(reportOutput, regexp);
expect(results.length).toEqual(1);
expect(results[0][pattern.file!]).toEqual("scss/_test.scss");
});
});

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("violation pattern", () => {
let pattern: ProblemPattern;
let regexp: RegExp;

beforeEach(() => {
pattern = problemMatcher.pattern[1];
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);
});

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");
});
});
});
});
18 changes: 10 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ export async function run(): Promise<void> {
case "remove":
const fileContents = await readFile(matcherFile, { encoding: "utf8" });
const problemMatcherDocument: ProblemMatcherDocument = JSON.parse(fileContents);
const problemMatcher = problemMatcherDocument.problemMatcher[0];

issueCommand(
"remove-matcher",
{
owner: problemMatcher.owner,
},
"",
);
for (const problemMatcher of problemMatcherDocument.problemMatcher) {
issueCommand(
"remove-matcher",
{
owner: problemMatcher.owner,
},
"",
);
}

break;

default:
Expand Down
21 changes: 20 additions & 1 deletion src/problem-matcher.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"problemMatcher": [
{
"owner": "stylelint",
"owner": "stylelint-error",
"severity": "error",
"pattern": [
{
"regexp": "^([^\\s].*)$",
Expand All @@ -16,6 +17,24 @@
"loop": true
}
]
},
{
"owner": "stylelint-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": 1
},
{
"regexp": "^\\s+((\\d+):(\\d+))?\\s+(⚠|‼)\\s+(.*)\\s{3,}(.*)$",
"line": 2,
"column": 3,
"message": 5,
"code": 6,
"loop": true
}
]
}
]
}

0 comments on commit 3f54025

Please sign in to comment.