Skip to content

Commit ae24521

Browse files
committed
feat(scripts): add format & format:check using prettier
1 parent e089f84 commit ae24521

File tree

8 files changed

+183
-20
lines changed

8 files changed

+183
-20
lines changed

.huskyrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hooks": {
3-
"pre-commit": "yarn lint",
3+
"pre-commit": "yarn format && yarn lint",
44
"pre-push": "yarn build"
55
}
66
}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"parser": "typescript",
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"purge": "rm -rf node_modules",
1414
"clean": "rm -rf dist",
1515
"dev": "rollup -cw",
16+
"format": "prettier --write **/*.ts",
17+
"format:check": "prettier --check **/*.ts",
1618
"lint": "tslint --project tsconfig.json --config tslint.json",
1719
"prebuild": "yarn clean",
1820
"build": "rollup -c",
@@ -27,6 +29,8 @@
2729
"@types/http-status-codes": "^1.2.0",
2830
"copyfiles": "^2.2.0",
2931
"husky": "^2.3.0",
32+
"prettier": "^2.0.2",
33+
"pretty-quick": "^2.0.1",
3034
"rollup": "^1.12.3",
3135
"rollup-plugin-async": "^1.2.0",
3236
"rollup-plugin-commonjs": "^10.0.0",

src/error.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ class MyError extends Error {
1010
constructor(err: any, isOperational = false) {
1111
super();
1212

13-
this.name = err instanceof Error || typeof err === 'object' ? err.name : 'Error';
14-
this.message = err instanceof Error || typeof err === 'object' ? err.message : err;
13+
this.name =
14+
err instanceof Error || typeof err === 'object' ? err.name : 'Error';
15+
this.message =
16+
err instanceof Error || typeof err === 'object' ? err.message : err;
1517
this.isOperational = isOperational;
1618

1719
// Restore prototype chain
@@ -43,9 +45,7 @@ class HttpError extends MyError {
4345
message: this.message,
4446
};
4547

46-
return !isDev()
47-
? content
48-
: { ...content, error: this.stack };
48+
return !isDev() ? content : { ...content, error: this.stack };
4949
}
5050
}
5151

src/express.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Request, Response, NextFunction, Router } from 'express';
2-
import { NOT_FOUND, OK, INTERNAL_SERVER_ERROR, getStatusText } from 'http-status-codes';
2+
import {
3+
NOT_FOUND,
4+
OK,
5+
INTERNAL_SERVER_ERROR,
6+
getStatusText,
7+
} from 'http-status-codes';
38

49
import { MyError, HttpError } from './error';
510
import errorHandler from './errorHandler';
@@ -25,7 +30,12 @@ const handleNotFound = (_: Request, __: Response, next: NextFunction) => {
2530
* @param res Express Response object
2631
* @param __ Express Next function
2732
*/
28-
const handleErrors = (err: MyError | HttpError, _: Request, res: Response, __: NextFunction) => {
33+
const handleErrors = (
34+
err: MyError | HttpError,
35+
_: Request,
36+
res: Response,
37+
__: NextFunction,
38+
) => {
2939
errorHandler.handle(err);
3040

3141
try {
@@ -58,10 +68,4 @@ const health = () => {
5868
return router;
5969
};
6070

61-
export {
62-
handleNotFound,
63-
handleErrors,
64-
handleHealthCheck,
65-
66-
health,
67-
};
71+
export { handleNotFound, handleErrors, handleHealthCheck, health };

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*/
55

66
const isDev = (): boolean => {
7-
return !['test', 'staging', 'production'].includes(process.env.NODE_ENV as string);
7+
return !['test', 'staging', 'production'].includes(
8+
process.env.NODE_ENV as string,
9+
);
810
};
911

1012
const isTest = (): boolean => {

0 commit comments

Comments
 (0)