Skip to content

Commit

Permalink
Merge branch 'master' into releases/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
xt0rted committed Feb 4, 2020
2 parents 5f677b5 + 92df1d3 commit d699a80
Show file tree
Hide file tree
Showing 10 changed files with 4,728 additions and 15 deletions.
12 changes: 6 additions & 6 deletions .github/stylelint-problem-matcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": "1"
"file": 1
},
{
"regexp": "^\\s+(\\d+):(\\d+)\\s+(✖|×)\\s+(.*)\\s{3,}(.*)$",
"line": 1,
"column": 2,
"message": 4,
"code": 5,
"regexp": "^\\s+((\\d+):(\\d+))?\\s+(✖|×)\\s+(.*)\\s{3,}(.*)$",
"line": 2,
"column": 3,
"message": 5,
"code": 6,
"loop": true
}
]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:

- run: npm ci

- run: npm run lint

- run: npm test

- run: npm run build
18 changes: 18 additions & 0 deletions __data__/stylelintMatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { problemMatcher } from "../.github/stylelint-problem-matcher.json";

export interface ProblemMatcher {
owner: string;
pattern: ProblemMatcherPattern[];
};

export interface ProblemMatcherPattern {
regexp: string;
file?: number;
line?: number;
column?: number;
message?: number;
code?: number;
loop?: boolean;
}

export const stylelintMatcher: ProblemMatcher = problemMatcher[0];
4 changes: 4 additions & 0 deletions __helpers__/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function matchResults(report: string[], regexp: RegExp): RegExpExecArray[] {
return report.map(line => regexp.exec(line))
.filter(match => match);
}
81 changes: 81 additions & 0 deletions __tests__/problemMatcher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { matchResults } from "../__helpers__/utils";
import { stylelintMatcher, ProblemMatcherPattern } from "../__data__/stylelintMatcher";

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

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

beforeEach(() => {
pattern = stylelintMatcher.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: ProblemMatcherPattern;
let regexp: RegExp;

beforeEach(() => {
pattern = stylelintMatcher.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");
});
});
});
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "stylelint problem matcher"
name: "Stylelint Problem Matcher"

description: "Sets up a problem matcher for stylelint that's used to create annotations for violations"

Expand Down
32 changes: 32 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: [
"**/*.ts",
"!dist/**",
"!lib/**",
"!**/node_modules/**",
],
coverageDirectory: "./coverage/",
globals: {
"ts-jest": {
diagnostics: false,
}
},
moduleFileExtensions: ["js", "ts"],
testEnvironment: "node",
testMatch: ["**/*.test.ts"],
testRunner: "jest-circus/runner",
transform: {
"^.+\\.ts$": "ts-jest",
},
verbose: true,
};

const processStdoutWrite = process.stdout.write.bind(process.stdout);

process.stdout.write = (str, encoding, cb) => {
if (!str.match(/^::/)) {
return processStdoutWrite(str, encoding, cb);
}
};
Loading

0 comments on commit d699a80

Please sign in to comment.