Skip to content

Commit 5a9e961

Browse files
author
Robert Jackson
authored
Merge pull request #42 from volta-cli/add-matchers
Add tsc and eslint matchers.
2 parents e80f8de + 5430714 commit 5a9e961

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed

matchers/eslint-compact.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "eslint-compact",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5,
13+
"code": 6
14+
}
15+
]
16+
}
17+
]
18+
}

matchers/eslint-stylish.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "eslint-stylish",
5+
"pattern": [
6+
{
7+
"regexp": "^([^\\s].*)$",
8+
"file": 1
9+
},
10+
{
11+
"regexp": "^\\s+(\\d+):(\\d+)\\s+(error|warning|info)\\s+(.*)\\s\\s+(.*)$",
12+
"line": 1,
13+
"column": 2,
14+
"severity": 3,
15+
"message": 4,
16+
"code": 5,
17+
"loop": true
18+
}
19+
]
20+
}
21+
]
22+
}

matchers/tsc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "tsc",
5+
"pattern": [
6+
{
7+
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
8+
"file": 1,
9+
"location": 2,
10+
"severity": 3,
11+
"code": 4,
12+
"message": 5
13+
}
14+
]
15+
}
16+
]
17+
}

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"devDependencies": {
3030
"@actions/core": "^1.2.6",
3131
"@actions/exec": "^1.0.4",
32+
"@actions/glob": "^0.1.0",
3233
"@actions/io": "^1.0.2",
3334
"@actions/tool-cache": "^1.6.0",
3435
"@types/jest": "^26.0.14",

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core';
22
import findUp from 'find-up';
33
import * as installer from './installer';
4+
import addMatchers from './matchers';
45

56
async function run(): Promise<void> {
67
try {
@@ -29,6 +30,8 @@ async function run(): Promise<void> {
2930
await installer.pinYarn(yarnVersion);
3031
}
3132
}
33+
34+
await addMatchers();
3235
} catch (error) {
3336
core.setFailed(error.message);
3437
}

src/matchers.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as path from 'path';
2+
import addMatchers from './matchers';
3+
import { createTempDir } from 'broccoli-test-helper';
4+
import type { TempDir } from 'broccoli-test-helper';
5+
6+
const ORIGNAL_CONSOLE = Object.assign({}, console);
7+
8+
describe('addMatchers', () => {
9+
let output: string[][];
10+
let tmpdir: TempDir;
11+
12+
beforeEach(async () => {
13+
output = [];
14+
15+
console.log = (...args: string[]) => {
16+
output.push(args);
17+
};
18+
19+
tmpdir = await createTempDir();
20+
});
21+
22+
afterEach(() => {
23+
Object.assign(console, ORIGNAL_CONSOLE);
24+
});
25+
26+
test('adds each of the matchers in the `matchers` directory', async () => {
27+
await addMatchers();
28+
29+
expect(output).toEqual([
30+
[`##[add-matcher]${path.join(__dirname, '..', 'matchers', 'eslint-compact.json')}`],
31+
[`##[add-matcher]${path.join(__dirname, '..', 'matchers', 'eslint-stylish.json')}`],
32+
[`##[add-matcher]${path.join(__dirname, '..', 'matchers', 'tsc.json')}`],
33+
]);
34+
});
35+
36+
test('adds matchers found', async () => {
37+
tmpdir.write({
38+
'foo.json': '{}',
39+
'bar.json': '{}',
40+
});
41+
await addMatchers(tmpdir.path());
42+
43+
expect(output).toEqual([
44+
[`##[add-matcher]${path.normalize(tmpdir.path('bar.json'))}`],
45+
[`##[add-matcher]${path.normalize(tmpdir.path('foo.json'))}`],
46+
]);
47+
});
48+
});

src/matchers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as path from 'path';
2+
import * as glob from '@actions/glob';
3+
4+
export default async function addMatchers(
5+
matchersPath = path.join(__dirname, '..', 'matchers')
6+
): Promise<void> {
7+
const globber = await glob.create(path.join(matchersPath, '*.json'));
8+
9+
for await (const file of globber.globGenerator()) {
10+
console.log(`##[add-matcher]${file}`);
11+
}
12+
}

0 commit comments

Comments
 (0)