Skip to content

Commit c8dd269

Browse files
committed
Add lint
1 parent a503f74 commit c8dd269

File tree

12 files changed

+52
-43
lines changed

12 files changed

+52
-43
lines changed

.github/workflows/preview-theme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
- run: npm run preview-theme
2222
env:
2323
CI: true
24-
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
24+
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ jobs:
2525
npm install
2626
npm run test
2727
28+
- name: Run Prettier
29+
run: |
30+
npm run prettier:check:ci
31+
2832
- name: Code Coverage
2933
uses: codecov/codecov-action@v1

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"scripts": {
77
"test": "jest --coverage",
88
"test:watch": "jest --watch",
9-
"preview-theme": "node scripts/preview-theme"
9+
"preview-theme": "node scripts/preview-theme",
10+
"prettier:check:ci": "./node_modules/.bin/prettier --check .",
11+
"prettier:format": "./node_modules/.bin/prettier --write ."
1012
},
1113
"author": "Steven",
1214
"license": "MIT",

scripts/preview-theme.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ async function run() {
108108
const comment = await findComment(octokit, pullRequestId);
109109

110110
const diff = parse(res.data);
111-
const content1 = diff
112-
.find((file) => file.to === "themes/index.js")
111+
const content1 = diff.find((file) => file.to === "themes/index.js")
113112
.chunks[0].changes;
114-
115-
const content = content1.filter((c) => c.type === "add").map((c) => c.content.replace("+", ""))
113+
114+
const content = content1
115+
.filter((c) => c.type === "add")
116+
.map((c) => c.content.replace("+", ""))
116117
.join("");
117118

118119
console.log("content1 diff");
@@ -193,4 +194,4 @@ async function run() {
193194
}
194195
}
195196

196-
run();
197+
run();

src/cards/stats-card.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ const {
1010
getCardColors,
1111
} = require("../common/utils");
1212

13-
const createTextNode = ({
14-
icon,
15-
label,
16-
value,
17-
id,
18-
index,
19-
showIcons,
20-
}) => {
13+
const createTextNode = ({ icon, label, value, id, index, showIcons }) => {
2114
const kValue = isNaN(value) ? value : kFormatter(value);
2215
const staggerDelay = (index + 3) * 150;
2316

@@ -169,7 +162,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
169162
</g>`;
170163

171164
// progress over 100
172-
const progress = (recentAvgWpm/150)*100;
165+
const progress = (recentAvgWpm / 150) * 100;
173166
const cssStyles = getStyles({
174167
titleColor,
175168
textColor,
@@ -179,7 +172,9 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
179172
});
180173

181174
const calculateTextWidth = () => {
182-
return measureText(custom_title ? custom_title : `${username}'s Typeracer Stats`);
175+
return measureText(
176+
custom_title ? custom_title : `${username}'s Typeracer Stats`,
177+
);
183178
};
184179

185180
const width = hide_rank

src/fetchers/stats-fetcher.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// @ts-check
22
const axios = require("axios").default;
33

4-
const {
5-
logger,
6-
CustomError,
7-
MissingParamError,
8-
} = require("../common/utils");
4+
const { logger, CustomError, MissingParamError } = require("../common/utils");
95

106
require("dotenv").config();
117

@@ -14,15 +10,15 @@ require("dotenv").config();
1410
*/
1511
const fetcher = (username) => {
1612
return axios({
17-
method: 'get',
18-
url: `https://data.typeracer.com/users?id=tr:${username}`
13+
method: "get",
14+
url: `https://data.typeracer.com/users?id=tr:${username}`,
1915
}).catch((error) => {
2016
logger.error(`Fail to fetch TypeRacer statistics: ${error}`);
2117
throw new CustomError(
2218
error.message || "Could not fetch typeracer statistic",
2319
CustomError.USER_NOT_FOUND,
2420
);
25-
})
21+
});
2622
};
2723

2824
/**
@@ -43,11 +39,11 @@ async function fetchStats(username) {
4339
};
4440

4541
let raceResponse = await fetcher(username);
46-
42+
4743
// @ts-ignore
4844
const { data } = raceResponse;
4945

50-
if(!data || !data.tstats || data.errors){
46+
if (!data || !data.tstats || data.errors) {
5147
logger.error(data.errors);
5248
throw new CustomError(
5349
data.errors[0].message || "Could not fetch user",

src/fetchers/types.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export type StatsData = {
2-
username: string,
3-
cg: number,
4-
gamesWon: number,
5-
bestGameWpm: number,
6-
wpm: number,
7-
recentAvgWpm: number,
8-
recentScores: number[],
2+
username: string;
3+
cg: number;
4+
gamesWon: number;
5+
bestGameWpm: number;
6+
wpm: number;
7+
recentAvgWpm: number;
8+
recentScores: number[];
99
};

tests/api.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ const faker = (query, data) => {
5555
setHeader: jest.fn(),
5656
send: jest.fn(),
5757
};
58-
mock.onGet(`https://data.typeracer.com/users?id=tr:${req.query.username}`).reply(200, data);
58+
mock
59+
.onGet(`https://data.typeracer.com/users?id=tr:${req.query.username}`)
60+
.reply(200, data);
5961

6062
return { req, res };
6163
};

tests/fetchStats.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ afterEach(() => {
3838

3939
describe("Test fetchStats", () => {
4040
it("should fetch correct stats", async () => {
41-
mock.onGet(`https://data.typeracer.com/users?id=tr:juninight`).reply(200, data);
42-
41+
mock
42+
.onGet(`https://data.typeracer.com/users?id=tr:juninight`)
43+
.reply(200, data);
4344

4445
let stats = await fetchStats("juninight");
4546

tests/renderStatsCard.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ describe("Test renderStatsCard", () => {
3232
).toBe("255");
3333
expect(getByTestId(document.body, "cg").textContent).toBe("9.1k");
3434
expect(getByTestId(document.body, "gamesWon").textContent).toBe("1.9k");
35-
expect(getByTestId(document.body, "bestGameWpm").textContent).toBe("110 WPM");
35+
expect(getByTestId(document.body, "bestGameWpm").textContent).toBe(
36+
"110 WPM",
37+
);
3638
expect(getByTestId(document.body, "wpm").textContent).toBe("70 WPM");
37-
expect(getByTestId(document.body, "recentAvgWpm").textContent).toBe("85 WPM");
38-
expect(getByTestId(document.body, "recentScores").textContent).toBe(`[${stats.recentScores.toString()}]`);
39+
expect(getByTestId(document.body, "recentAvgWpm").textContent).toBe(
40+
"85 WPM",
41+
);
42+
expect(getByTestId(document.body, "recentScores").textContent).toBe(
43+
`[${stats.recentScores.toString()}]`,
44+
);
3945
expect(queryByTestId(document.body, "card-bg")).toBeInTheDocument();
4046
expect(queryByTestId(document.body, "rank-circle")).toBeInTheDocument();
4147
});

0 commit comments

Comments
 (0)