Skip to content

Commit ac8c021

Browse files
committed
Use Prettier everywhere
1 parent 9f2ac40 commit ac8c021

9 files changed

+166
-161
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*lock.yaml

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,30 +134,30 @@ The responses are structured like this:
134134

135135
```typescript
136136
interface Contribution {
137-
date: string;
138-
count: number;
139-
level: 0 | 1 | 2 | 3 | 4;
137+
date: string
138+
count: number
139+
level: 0 | 1 | 2 | 3 | 4
140140
}
141141

142142
interface Response {
143143
total: {
144-
[year: number]: number;
145-
[year: string]: number; // 'lastYear'
146-
};
147-
contributions: Array<Contribution>;
144+
[year: number]: number
145+
[year: string]: number // 'lastYear'
146+
}
147+
contributions: Array<Contribution>
148148
}
149149

150150
interface NestedResponse {
151151
total: {
152-
[year: number]: number;
153-
[year: string]: number; // 'lastYear;
154-
};
152+
[year: number]: number
153+
[year: string]: number // 'lastYear;
154+
}
155155
contributions: {
156156
[year: number]: {
157157
[month: number]: {
158-
[day: number]: Contribution;
159-
};
160-
};
161-
};
158+
[day: number]: Contribution
159+
}
160+
}
161+
}
162162
}
163163
```

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ module.exports = {
1010
],
1111
'@babel/preset-typescript',
1212
],
13-
};
13+
}

jest.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Config } from 'jest';
1+
import type { Config } from 'jest'
22

33
const config: Config = {
44
silent: true,
5-
};
5+
}
66

7-
export default config;
7+
export default config

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"build": "rm -rf build/* && tsc",
1414
"dev": "nodemon src/server.ts --exec ts-node src/server.ts",
15-
"format": "prettier --write src tests",
15+
"format": "prettier --write .",
1616
"prepare": "husky",
1717
"postinstall": "npm run build",
1818
"prestart": "npm run build",
@@ -59,5 +59,9 @@
5959
"supertest": "^7.0.0",
6060
"ts-node": "^10.9.2",
6161
"typescript": "^5.5.4"
62+
},
63+
"prettier": {
64+
"semi": false,
65+
"singleQuote": true
6266
}
6367
}

src/index.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
1-
import express, { ErrorRequestHandler } from 'express';
2-
import cache from 'memory-cache';
3-
import cors from 'cors';
4-
import compression from 'compression';
1+
import express, { ErrorRequestHandler } from 'express'
2+
import cache from 'memory-cache'
3+
import cors from 'cors'
4+
import compression from 'compression'
55

66
import {
77
NestedResponse as ApiNestedResponse,
88
Response as ApiResponse,
99
scrapeGitHubContributions,
1010
UserNotFoundError,
11-
} from './scrape';
11+
} from './scrape'
1212

1313
export interface ParsedQuery {
14-
years: Array<number>;
15-
fetchAll: boolean;
16-
lastYear: boolean;
17-
format: QueryParams['format'];
14+
years: Array<number>
15+
fetchAll: boolean
16+
lastYear: boolean
17+
format: QueryParams['format']
1818
}
1919

2020
interface Params {
21-
username: string;
21+
username: string
2222
}
2323

2424
interface QueryParams {
25-
y?: string | Array<string>;
26-
format?: 'nested';
25+
y?: string | Array<string>
26+
format?: 'nested'
2727
}
2828

2929
type Request = express.Request<
3030
Params,
3131
ApiResponse | ApiNestedResponse | { error: string },
3232
{},
3333
QueryParams
34-
>;
34+
>
3535

36-
const app = express();
36+
const app = express()
3737

38-
app.use(cors());
39-
app.use(compression());
38+
app.use(cors())
39+
app.use(compression())
4040

4141
app.get('/v4/:username', async (req: Request, res, next) => {
42-
const { username } = req.params;
42+
const { username } = req.params
4343

4444
if (req.query.format && req.query.format !== 'nested') {
4545
return res.status(400).send({
4646
error: "Query parameter 'format' must be 'nested' or undefined",
47-
});
47+
})
4848
}
4949

5050
const years =
5151
req.query.y != null
5252
? typeof req.query.y === 'string'
5353
? [req.query.y]
5454
: req.query.y
55-
: [];
55+
: []
5656

5757
if (years.some((y) => !/^\d+$/.test(y) && y !== 'all' && y !== 'last')) {
5858
return res.status(400).send({
5959
error: "Query parameter 'y' must be an integer, 'all' or 'last'",
60-
});
60+
})
6161
}
6262

6363
const query: ParsedQuery = {
6464
years: years.map((y) => parseInt(y)).filter(isFinite),
6565
fetchAll: years.includes('all') || years.length === 0,
6666
lastYear: years.includes('last'),
6767
format: req.query.format,
68-
};
68+
}
6969

70-
const key = `${username}-${JSON.stringify(query)}`;
71-
const cached = cache.get(key);
70+
const key = `${username}-${JSON.stringify(query)}`
71+
const cached = cache.get(key)
7272

7373
if (cached !== null) {
74-
return res.json(cached);
74+
return res.json(cached)
7575
}
7676

7777
try {
78-
const response = await scrapeGitHubContributions(username, query);
79-
cache.put(key, response, 1000 * 3600); // Store for an hour
78+
const response = await scrapeGitHubContributions(username, query)
79+
cache.put(key, response, 1000 * 3600) // Store for an hour
8080

81-
return res.json(response);
81+
return res.json(response)
8282
} catch (error) {
8383
if (error instanceof UserNotFoundError) {
8484
return res.status(404).send({
8585
error: error.message,
86-
});
86+
})
8787
}
8888

8989
next(
@@ -92,20 +92,20 @@ app.get('/v4/:username', async (req: Request, res, next) => {
9292
error instanceof Error ? error.message : 'Unknown error.'
9393
}`,
9494
),
95-
);
95+
)
9696
}
97-
});
97+
})
9898

9999
const errorHandler: ErrorRequestHandler = (error, _req, res, next) => {
100-
console.error(error);
100+
console.error(error)
101101
res.status(500).json({
102102
error: error.message,
103-
});
104-
next();
105-
};
103+
})
104+
next()
105+
}
106106

107107
// This needs to be last to override the default Express.js error handler!
108108
// The order of middleware does matter.
109-
app.use(errorHandler);
109+
app.use(errorHandler)
110110

111-
export default app;
111+
export default app

0 commit comments

Comments
 (0)