Skip to content

Commit

Permalink
chore: add typecheck and linting for backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dec0dOS committed Oct 4, 2023
1 parent 70c5804 commit bdf406f
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 11 deletions.
63 changes: 63 additions & 0 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"plugins": [
"@typescript-eslint",
"unicorn",
"jsdoc",
"import",
"promise",
"sonarjs"
],
"extends": [
"eslint:recommended",
"plugin:n/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:unicorn/recommended",
"plugin:jsdoc/recommended",
"plugin:import/recommended",
"plugin:promise/recommended",
"plugin:sonarjs/recommended",
"plugin:security/recommended"
],
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
],
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-comment": "off",
"jsdoc/require-jsdoc": ["warn", { "publicOnly": true }],
"jsdoc/require-description": "off",
"import/no-unresolved": "off",
"unicorn/no-empty-file": "off",
"unicorn/consistent-function-scoping": [
"error",
{
"checkArrowFunctions": false
}
],
"unicorn/prefer-module": "off",
"unicorn/prevent-abbreviations": "off",
"unicorn/catch-error-name": "off",
"unicorn/prefer-ternary": "off",
"unicorn/prefer-event-target": "off",
"security/detect-object-injection": "off",
"security/detect-non-literal-fs-filename": "off"
}
}
1 change: 1 addition & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (
process.env.NODE_ENV === "production" &&
process.env.ZU_SECURE_HEADERS !== "false"
) {
// @ts-ignore
app.use(helmet());
}

Expand Down
1 change: 1 addition & 0 deletions backend/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "axios";
6 changes: 0 additions & 6 deletions backend/jsconfig.json

This file was deleted.

26 changes: 21 additions & 5 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,36 @@
"name": "backend",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "node ./bin/www",
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
"typecheck": "tsc --pretty --noEmit -p tsconfig.json"
},
"dependencies": {
"axios": "^0.27.2",
"compression": "^1.7.4",
"debug": "~4.3.4",
"dotenv": "^16.0.1",
"express": "~4.18.1",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-bearer-token": "^2.4.0",
"helmet": "^5.1.1",
"lodash": "^4.17.21",
"lowdb": "^1.0.0",
"morgan": "~1.10.0",
"morgan": "^1.10.0",
"node-cron": "^3.0.2",
"pbkdf2-wrapper": "^1.3.4"
},
"devDependencies": {
"@types/express": "^4.17.18",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint": "^8.50.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-sonarjs": "^0.21.0",
"eslint-plugin-unicorn": "^48.0.1",
"typescript": "^5.2.2"
}
}
4 changes: 4 additions & 0 deletions backend/routes/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const api = require("../utils/controller-api");

// get all members
router.get("/", auth.isAuthorized, async function (req, res) {
// @ts-ignore
const nwid = req.params.nwid;
api
.get("controller/network/" + nwid + "/member")
Expand All @@ -23,6 +24,7 @@ router.get("/", auth.isAuthorized, async function (req, res) {

// get member
router.get("/:mid", auth.isAuthorized, async function (req, res) {
// @ts-ignore
const nwid = req.params.nwid;
const mid = req.params.mid;
const data = await member.getMembersData(nwid, [mid]);
Expand All @@ -35,6 +37,7 @@ router.get("/:mid", auth.isAuthorized, async function (req, res) {

// update member
router.post("/:mid", auth.isAuthorized, async function (req, res) {
// @ts-ignore
const nwid = req.params.nwid;
const mid = req.params.mid;
member.updateMemberAdditionalData(nwid, mid, req.body);
Expand All @@ -56,6 +59,7 @@ router.post("/:mid", auth.isAuthorized, async function (req, res) {

// delete member
router.delete("/:mid", auth.isAuthorized, async function (req, res) {
// @ts-ignore
const nwid = req.params.nwid;
const mid = req.params.mid;
member.deleteMemberAdditionalData(nwid, mid);
Expand Down
1 change: 1 addition & 0 deletions backend/services/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async function getMemberAdditionalData(data) {
networkId: data.nwid,
nodeId: data.id,
controllerId: ZT_ADDRESS,
// @ts-ignore
lastOnline: lastOnline,
...additionalData,
...peerData,
Expand Down
18 changes: 18 additions & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"allowJs": true,
"checkJs": true,
"noEmit": true,
"skipLibCheck": true,
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ESNext",
"lib": ["ESNext", "dom"],
"strict": true,
"noImplicitAny": false,
"allowSyntheticDefaultImports": true
},
"include": ["."]
}
1 change: 1 addition & 0 deletions backend/utils/zt-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = async function () {
return res.data.address;
} catch (err) {
console.error(
// @ts-ignore
"Couldn't connect to the controller on " + err.config.baseURL
);
}
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"skipLibCheck": true,
"target": "ESNext",
"lib": ["ESNext", "dom"],
"strict": true,
"noImplicitAny": false,
"allowSyntheticDefaultImports": true
},
"include": ["backend", "frontend"]
}

0 comments on commit bdf406f

Please sign in to comment.