Skip to content

Commit b257d50

Browse files
committed
align prettier with our standards
1 parent b786241 commit b257d50

File tree

10 files changed

+152
-154
lines changed

10 files changed

+152
-154
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
]
5757
},
5858
"prettier": {
59-
"semi": false,
60-
"useTabs": true,
6159
"trailingComma": "all"
6260
}
6361
}

src/cli.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import process from "process"
2-
import { promises as fs } from "fs"
3-
import path from "path"
1+
import process from "process";
2+
import { promises as fs } from "fs";
3+
import path from "path";
44

5-
import { parse } from "./lcov"
6-
import { diff } from "./comment"
5+
import { parse } from "./lcov";
6+
import { diff } from "./comment";
77

88
async function main() {
9-
const file = process.argv[2]
10-
const beforeFile = process.argv[3]
11-
const prefix = path.dirname(path.dirname(path.resolve(file))) + "/"
9+
const file = process.argv[2];
10+
const beforeFile = process.argv[3];
11+
const prefix = path.dirname(path.dirname(path.resolve(file))) + "/";
1212

13-
const content = await fs.readFile(file, "utf-8")
14-
const lcov = await parse(content)
13+
const content = await fs.readFile(file, "utf-8");
14+
const lcov = await parse(content);
1515

16-
let before
16+
let before;
1717
if (beforeFile) {
18-
const content = await fs.readFile(beforeFile, "utf-8")
19-
before = await parse(content)
18+
const content = await fs.readFile(beforeFile, "utf-8");
19+
before = await parse(content);
2020
}
2121

2222
const options = {
@@ -25,12 +25,12 @@ async function main() {
2525
prefix,
2626
head: "feat/test",
2727
base: "master",
28-
}
28+
};
2929

30-
console.log(diff(lcov, before, options))
30+
console.log(diff(lcov, before, options));
3131
}
3232

3333
main().catch(function(err) {
34-
console.log(err)
35-
process.exit(1)
36-
})
34+
console.log(err);
35+
process.exit(1);
36+
});

src/comment.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1-
import { details, summary, b, fragment, table, tbody, tr, th } from "./html"
1+
import { details, summary, b, fragment, table, tbody, tr, th } from "./html";
22

3-
import { percentage } from "./lcov"
4-
import { tabulate } from "./tabulate"
3+
import { percentage } from "./lcov";
4+
import { tabulate } from "./tabulate";
55

6-
export function comment (lcov, options) {
6+
export function comment(lcov, options) {
77
return fragment(
88
`Coverage after merging ${b(options.head)} into ${b(options.base)}`,
99
table(tbody(tr(th(percentage(lcov).toFixed(2), "%")))),
1010
"\n\n",
1111
details(summary("Coverage Report"), tabulate(lcov, options)),
12-
)
12+
);
1313
}
1414

1515
export function diff(lcov, before, options) {
1616
if (!before) {
17-
return comment(lcov, options)
17+
return comment(lcov, options);
1818
}
1919

20-
const pbefore = percentage(before)
21-
const pafter = percentage(lcov)
22-
const pdiff = pafter - pbefore
23-
const plus = pdiff > 0 ? "+" : ""
24-
const arrow =
25-
pdiff === 0
26-
? ""
27-
: pdiff < 0
28-
? "▾"
29-
: "▴"
20+
const pbefore = percentage(before);
21+
const pafter = percentage(lcov);
22+
const pdiff = pafter - pbefore;
23+
const plus = pdiff > 0 ? "+" : "";
24+
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
3025

3126
return fragment(
3227
`Coverage after merging ${b(options.head)} into ${b(options.base)}`,
33-
table(tbody(tr(
34-
th(pafter.toFixed(2), "%"),
35-
th(arrow, " ", plus, pdiff.toFixed(2), "%"),
36-
))),
28+
table(
29+
tbody(
30+
tr(
31+
th(pafter.toFixed(2), "%"),
32+
th(arrow, " ", plus, pdiff.toFixed(2), "%"),
33+
),
34+
),
35+
),
3736
"\n\n",
3837
details(summary("Coverage Report"), tabulate(lcov, options)),
39-
)
38+
);
4039
}

src/html.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ function tag(name) {
55
? Object.keys(children[0])
66
.map(key => ` ${key}='${children[0][key]}'`)
77
.join("")
8-
: ""
8+
: "";
99

10-
const c = typeof children[0] === "string" ? children : children.slice(1)
10+
const c = typeof children[0] === "string" ? children : children.slice(1);
1111

12-
return `<${name}${props}>${c.join("")}</${name}>`
13-
}
12+
return `<${name}${props}>${c.join("")}</${name}>`;
13+
};
1414
}
1515

16-
export const details = tag("details")
17-
export const summary = tag("summary")
18-
export const tr = tag("tr")
19-
export const td = tag("td")
20-
export const th = tag("th")
21-
export const b = tag("b")
22-
export const table = tag("table")
23-
export const tbody = tag("tbody")
24-
export const a = tag("a")
25-
export const span = tag("span")
16+
export const details = tag("details");
17+
export const summary = tag("summary");
18+
export const tr = tag("tr");
19+
export const td = tag("td");
20+
export const th = tag("th");
21+
export const b = tag("b");
22+
export const table = tag("table");
23+
export const tbody = tag("tbody");
24+
export const a = tag("a");
25+
export const span = tag("span");
2626

2727
export const fragment = function(...children) {
28-
return children.join("")
29-
}
28+
return children.join("");
29+
};

src/html_test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ import {
1010
a,
1111
span,
1212
fragment,
13-
} from "./html"
13+
} from "./html";
1414

1515
test("html tags should return the correct html", function() {
16-
expect(details("foo", "bar")).toBe("<details>foobar</details>")
17-
expect(summary("foo", "bar")).toBe("<summary>foobar</summary>")
18-
expect(tr("foo", "bar")).toBe("<tr>foobar</tr>")
19-
expect(td("foo", "bar")).toBe("<td>foobar</td>")
20-
expect(th("foo", "bar")).toBe("<th>foobar</th>")
21-
expect(b("foo", "bar")).toBe("<b>foobar</b>")
22-
expect(table("foo", "bar")).toBe("<table>foobar</table>")
23-
expect(tbody("foo", "bar")).toBe("<tbody>foobar</tbody>")
24-
expect(a("foo", "bar")).toBe("<a>foobar</a>")
25-
expect(span("foo", "bar")).toBe("<span>foobar</span>")
26-
})
16+
expect(details("foo", "bar")).toBe("<details>foobar</details>");
17+
expect(summary("foo", "bar")).toBe("<summary>foobar</summary>");
18+
expect(tr("foo", "bar")).toBe("<tr>foobar</tr>");
19+
expect(td("foo", "bar")).toBe("<td>foobar</td>");
20+
expect(th("foo", "bar")).toBe("<th>foobar</th>");
21+
expect(b("foo", "bar")).toBe("<b>foobar</b>");
22+
expect(table("foo", "bar")).toBe("<table>foobar</table>");
23+
expect(tbody("foo", "bar")).toBe("<tbody>foobar</tbody>");
24+
expect(a("foo", "bar")).toBe("<a>foobar</a>");
25+
expect(span("foo", "bar")).toBe("<span>foobar</span>");
26+
});
2727

2828
test("html fragment should return the children", function() {
29-
expect(fragment()).toBe("")
30-
expect(fragment("foo")).toBe("foo")
31-
expect(fragment("foo", "bar")).toBe("foobar")
32-
})
29+
expect(fragment()).toBe("");
30+
expect(fragment("foo")).toBe("foo");
31+
expect(fragment("foo", "bar")).toBe("foobar");
32+
});
3333

3434
test("html tags should accept props", function() {
3535
expect(a({ href: "http://www.example.com" }, "example")).toBe(
3636
"<a href='http://www.example.com'>example</a>",
37-
)
37+
);
3838
expect(
3939
a({ href: "http://www.example.com", target: "_blank" }, "example"),
40-
).toBe("<a href='http://www.example.com' target='_blank'>example</a>")
41-
})
40+
).toBe("<a href='http://www.example.com' target='_blank'>example</a>");
41+
});

src/index.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import { promises as fs } from "fs"
2-
import core from "@actions/core"
3-
import { GitHub, context } from "@actions/github"
1+
import { promises as fs } from "fs";
2+
import core from "@actions/core";
3+
import { GitHub, context } from "@actions/github";
44

5-
import { parse } from "./lcov"
6-
import { diff } from "./comment"
5+
import { parse } from "./lcov";
6+
import { diff } from "./comment";
77

88
async function main() {
9-
const token = core.getInput("github-token")
10-
const lcovFile = core.getInput("lcov-file") || "./coverage/lcov.info"
11-
const baseFile = core.getInput("lcov-base")
9+
const token = core.getInput("github-token");
10+
const lcovFile = core.getInput("lcov-file") || "./coverage/lcov.info";
11+
const baseFile = core.getInput("lcov-base");
1212

13-
const raw = await fs.readFile(lcovFile, "utf-8").catch(err => null)
13+
const raw = await fs.readFile(lcovFile, "utf-8").catch(err => null);
1414
if (!raw) {
15-
console.log(`No coverage report found at '${lcovFile}', exiting...`)
16-
return
15+
console.log(`No coverage report found at '${lcovFile}', exiting...`);
16+
return;
1717
}
1818

19-
const baseRaw = baseFile && await fs.readFile(baseFile, "utf-8").catch(err => null)
19+
const baseRaw =
20+
baseFile && (await fs.readFile(baseFile, "utf-8").catch(err => null));
2021
if (baseFile && !baseRaw) {
21-
console.log(`No coverage report found at '${baseFile}', ignoring...`)
22+
console.log(`No coverage report found at '${baseFile}', ignoring...`);
2223
}
2324

2425
const options = {
@@ -27,21 +28,21 @@ async function main() {
2728
prefix: `${process.env.GITHUB_WORKSPACE}/`,
2829
head: context.payload.pull_request.head.ref,
2930
base: context.payload.pull_request.base.ref,
30-
}
31+
};
3132

32-
const lcov = await parse(raw)
33-
const baselcov = baseRaw && await parse(baseRaw)
34-
const body = diff(lcov, baselcov, options)
33+
const lcov = await parse(raw);
34+
const baselcov = baseRaw && (await parse(baseRaw));
35+
const body = diff(lcov, baselcov, options);
3536

3637
await new GitHub(token).issues.createComment({
3738
repo: context.repo.repo,
3839
owner: context.repo.owner,
3940
issue_number: context.payload.pull_request.number,
4041
body: diff(lcov, baselcov, options),
41-
})
42+
});
4243
}
4344

4445
main().catch(function(err) {
45-
console.log(err)
46-
core.setFailed(err.message)
47-
})
46+
console.log(err);
47+
core.setFailed(err.message);
48+
});

src/lcov.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import lcov from "lcov-parse"
1+
import lcov from "lcov-parse";
22

33
// Parse lcov string into lcov data
44
export function parse(data) {
55
return new Promise(function(resolve, reject) {
66
lcov(data, function(err, res) {
77
if (err) {
8-
reject(err)
9-
return
8+
reject(err);
9+
return;
1010
}
11-
resolve(res)
12-
})
13-
})
11+
resolve(res);
12+
});
13+
});
1414
}
1515

1616
// Get the total coverage percentage from the lcov data.
1717
export function percentage(lcov) {
18-
let hit = 0
19-
let found = 0
18+
let hit = 0;
19+
let found = 0;
2020
for (const entry of lcov) {
21-
hit += entry.lines.hit
22-
found += entry.lines.found
21+
hit += entry.lines.hit;
22+
found += entry.lines.found;
2323
}
2424

25-
return (hit / found) * 100
25+
return (hit / found) * 100;
2626
}

src/lcov_test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parse, percentage } from "./lcov"
1+
import { parse, percentage } from "./lcov";
22

33
test("parse should parse lcov strings correctly", async function() {
44
const data = `
@@ -22,9 +22,9 @@ BRDA:37,2,0,0
2222
BRF:5
2323
BRH:4
2424
end_of_record
25-
`
25+
`;
2626

27-
const lcov = await parse(data)
27+
const lcov = await parse(data);
2828
expect(lcov).toEqual([
2929
{
3030
title: "",
@@ -102,18 +102,18 @@ end_of_record
102102
],
103103
},
104104
},
105-
])
106-
})
105+
]);
106+
});
107107

108108
test("parse should fail on invalid lcov", async function() {
109-
await expect(parse("invalid")).rejects.toBe("Failed to parse string")
110-
})
109+
await expect(parse("invalid")).rejects.toBe("Failed to parse string");
110+
});
111111

112112
test("percentage should calculate the correct percentage", function() {
113113
expect(
114114
percentage([
115115
{ lines: { hit: 20, found: 25 } },
116116
{ lines: { hit: 10, found: 15 } },
117117
]),
118-
).toBe(75)
119-
})
118+
).toBe(75);
119+
});

0 commit comments

Comments
 (0)