Switch to eslint and prettier for code formatting (#607) · hackmcgill/hackerAPI@15e980d · GitHub
Skip to content

Commit 15e980d

Browse files
authored
Switch to eslint and prettier for code formatting (#607)
* delete jshint and jslint * add eslint * add eslint ignore * add prettier * update eslint * add prettier config * add vscode settings * add format and lint scripts * remove eslint rules * update prettier ignore * update eslint ignore * update eslint config * run eslint * run prettier * update settings * run prettier
1 parent 3d5d679 commit 15e980d

201 files changed

Lines changed: 34226 additions & 9069 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintignore‎

Lines changed: 1 addition & 0 deletions

‎.eslintrc‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es6": true,
5+
"node": true,
6+
"mocha": true
7+
},
8+
"parserOptions": {
9+
"ecmaVersion": 2017,
10+
"sourceType": "module"
11+
},
12+
"plugins": [
13+
"prettier"
14+
],
15+
"extends": [
16+
"eslint:recommended",
17+
"prettier"
18+
]
19+
}

‎.jshintrc‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎.prettierignore‎

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

‎.prettierrc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"tabWidth": 4,
3+
"useTabs": false,
4+
"singleQuote": false,
5+
"semi": true,
6+
"arrowParens": "always",
7+
"jsxBracketSameLine": false
8+
}

‎.vscode/settings.json‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
2-
"jslint.version": "es6",
3-
"jslint.options": {
4-
"node":true,
5-
"this":false,
6-
"bad_property":false
7-
},
82
"search.usePCRE2": true,
9-
"editor.formatOnSave": true
10-
}
3+
"editor.formatOnSave": true,
4+
"files.insertFinalNewline": true,
5+
"files.trimFinalNewlines": true,
6+
"editor.tabSize": 4
7+
}

‎app.js‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ if (!Services.env.isProduction()) {
4444
} else {
4545
// TODO: change this when necessary
4646
corsOptions = {
47-
origin: [`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`, `https://docs.mchacks.ca`],
47+
origin: [
48+
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
49+
`https://docs.mchacks.ca`
50+
],
4851
credentials: true
4952
};
5053
}
@@ -53,17 +56,21 @@ app.use(cors(corsOptions));
5356
app.use(Services.log.requestLogger);
5457
app.use(Services.log.errorLogger);
5558
app.use(express.json());
56-
app.use(express.urlencoded({
57-
extended: false
58-
}));
59+
app.use(
60+
express.urlencoded({
61+
extended: false
62+
})
63+
);
5964
app.use(cookieParser());
6065
//Cookie-based session tracking
61-
app.use(cookieSession({
62-
name: "session",
63-
keys: [process.env.COOKIE_SECRET],
64-
// Cookie Options
65-
maxAge: 48 * 60 * 60 * 1000 //Logged in for 48 hours
66-
}));
66+
app.use(
67+
cookieSession({
68+
name: "session",
69+
keys: [process.env.COOKIE_SECRET],
70+
// Cookie Options
71+
maxAge: 48 * 60 * 60 * 1000 //Logged in for 48 hours
72+
})
73+
);
6774
app.use(passport.initialize());
6875
app.use(passport.session()); //persistent login session
6976

@@ -98,8 +105,8 @@ app.use("/api", apiRouter);
98105
//Custom error handler
99106
app.use((err, req, res, next) => {
100107
// log the error...
101-
const status = (err.status) ? err.status : 500;
102-
const message = (err.message) ? err.message : "Internal Server Error";
108+
const status = err.status ? err.status : 500;
109+
const message = err.message ? err.message : "Internal Server Error";
103110
//Only show bad error when we're not in deployment
104111
let errorContents;
105112
if (status === 500 && Services.env.isProduction) {
@@ -118,5 +125,5 @@ app.use((err, req, res, next) => {
118125
});
119126

120127
module.exports = {
121-
app: app,
122-
};
128+
app: app
129+
};

‎bin/www.js‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,20 @@ function onError(error) {
4949
throw error;
5050
}
5151

52-
const bind = typeof port === "string" ?
53-
"Pipe " + port:
54-
"Port " + port;
52+
const bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
5553

5654
// handle specific listen errors with friendly messages
5755
switch (error.code) {
58-
case "EACCES":
59-
console.error(bind + " requires elevated privileges");
60-
process.exit(1);
61-
break;
62-
case "EADDRINUSE":
63-
console.error(bind + " is already in use");
64-
process.exit(1);
65-
break;
66-
default:
67-
throw error;
56+
case "EACCES":
57+
console.error(bind + " requires elevated privileges");
58+
process.exit(1);
59+
break;
60+
case "EADDRINUSE":
61+
console.error(bind + " is already in use");
62+
process.exit(1);
63+
break;
64+
default:
65+
throw error;
6866
}
6967
}
7068

@@ -74,23 +72,21 @@ function onError(error) {
7472

7573
function onListening() {
7674
const addr = server.address();
77-
const bind = typeof addr === "string" ?
78-
"pipe " + addr :
79-
"port " + addr.port;
75+
const bind =
76+
typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
8077
debug("Listening on " + bind);
81-
fs.readFile("VERSION", function (err, data) {
78+
fs.readFile("VERSION", function(err, data) {
8279
if (err) {
8380
throw err;
8481
}
8582
debug(`VERSION ${data}`);
8683
});
8784
}
8885

89-
9086
/**
9187
* Listen on provided port, on all network interfaces.
9288
*/
9389

9490
server.listen(port);
9591
server.on("error", onError);
96-
server.on("listening", onListening);
92+
server.on("listening", onListening);

‎constants/error.constant.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const ACCOUNT_TYPE_409_MESSAGE = "Wrong account type";
1212
const SPONSOR_ID_409_MESSAGE = "Conflict with sponsor accountId link";
1313
const VOLUNTEER_ID_409_MESSAGE = "Conflict with volunteer accountId link";
1414
const HACKER_ID_409_MESSAGE = "Conflict with hacker accountId link";
15-
const TEAM_MEMBER_409_MESSAGE = "Conflict with team member being in another team";
15+
const TEAM_MEMBER_409_MESSAGE =
16+
"Conflict with team member being in another team";
1617
const TEAM_NAME_409_MESSAGE = "Conflict with team name already in use";
1718
const HACKER_STATUS_409_MESSAGE = "Conflict with hacker status";
1819
const TEAM_SIZE_409_MESSAGE = "Team full";
@@ -81,4 +82,4 @@ module.exports = {
8182
VOLUNTEER_404_MESSAGE: VOLUNTEER_404_MESSAGE,
8283
SPONSOR_UPDATE_500_MESSAGE: SPONSOR_UPDATE_500_MESSAGE,
8384
SETTINGS_404_MESSAGE: SETTINGS_404_MESSAGE
84-
};
85+
};

‎constants/general.constant.js‎

Lines changed: 41 additions & 12 deletions

0 commit comments

Comments
 (0)