From 33e5090b9857865977190dc25d57c6801d9d75bb Mon Sep 17 00:00:00 2001 From: Abhishek SAINI Date: Fri, 29 Nov 2024 11:55:52 +0100 Subject: [PATCH] tsconfig, eslintrc and prettier --- .eslintignore | 8 -- .eslintrc.json | 23 ++-- .prettierrc | 10 +- package-lock.json | 255 +++++++++++++++++++++++++++++++++++++-------- package.json | 16 +-- tsconfig.json | 42 ++++---- tsconfig.prod.json | 8 +- 7 files changed, 264 insertions(+), 98 deletions(-) delete mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 89c6313..0000000 --- a/.eslintignore +++ /dev/null @@ -1,8 +0,0 @@ -.vscode/ -node_modules/ -logs/ - -# Build products -build/ -dist/ -tools/ diff --git a/.eslintrc.json b/.eslintrc.json index 00d75d3..759acaf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,20 +1,25 @@ { - "rules": { - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/explicit-function-return-types": "off", - "@typescript-eslint/explicit-module-boundary-types": "off" + "env": { + "node": true, + "jest": true }, "extends": [ - "plugin:@typescript-eslint/recommended" // Uses the recommended rules from the @typescript-eslint/eslint-plugin + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + "plugin:prettier/recommended" ], + "ignorePatterns": [".eslintrc.json", "build", "node_modules"], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": "latest", // Allows for the parsing of modern ECMAScript features "sourceType": "module" // Allows for the use of imports }, - "env": { - "node": true + "rules": { + "no-console": "warn", + "no-undef": "error", + "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], + "@typescript-eslint/no-explicit-any": "warn", + "prefer-const": "error" } } diff --git a/.prettierrc b/.prettierrc index 4e815a7..2557053 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,12 +1,12 @@ { - "bracketSameLine": true, + "bracketSameLine": false, "useTabs": false, - "trailingComma": "all", - "endOfLine": "auto", + "trailingComma": "es5", + "endOfLine": "lf", "singleQuote": true, - "printWidth": 80, + "printWidth": 100, "tabWidth": 2, "arrowParens": "always", - "quoteProps": "as-needed", + "quoteProps": "consistent", "semi": true } diff --git a/package-lock.json b/package-lock.json index b80f7f3..919fb9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,9 +47,12 @@ "concurrently": "^8.2.1", "dotenv": "^16.3.1", "eslint": "^8.57.1", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^5.2.1", "jest": "^29.6.2", - "nodemon": "^2.0.20", - "prettier": "^2.8.1", + "nodemon": "^3.1.7", + "prettier": "^3.4.0", "supertest": "^6.3.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", @@ -1364,6 +1367,19 @@ "node": ">= 8" } }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@scarf/scarf": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.4.0.tgz", @@ -3344,6 +3360,101 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-es": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-3.0.1.tgz", + "integrity": "sha512-GUmAsJaN4Fc7Gbtl8uOBlayo2DqhwWvEzykMHSCZHU3XdJ+NSzzZcVhXh3VxX5icqQ+oQdIEawXX8xkR3mIFmQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-utils": "^2.0.0", + "regexpp": "^3.0.0" + }, + "engines": { + "node": ">=8.10.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=4.19.1" + } + }, + "node_modules/eslint-plugin-node": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz", + "integrity": "sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-plugin-es": "^3.0.0", + "eslint-utils": "^2.0.0", + "ignore": "^5.1.1", + "minimatch": "^3.0.4", + "resolve": "^1.10.1", + "semver": "^6.1.0" + }, + "engines": { + "node": ">=8.10.0" + }, + "peerDependencies": { + "eslint": ">=5.16.0" + } + }, + "node_modules/eslint-plugin-node/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", + "dev": true, + "license": "MIT", + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.9.1" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": "*", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -3357,6 +3468,32 @@ "node": ">=8.0.0" } }, + "node_modules/eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^1.1.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + } + }, + "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=4" + } + }, "node_modules/eslint-visitor-keys": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", @@ -3649,6 +3786,13 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -5752,18 +5896,19 @@ } }, "node_modules/nodemon": { - "version": "2.0.22", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", - "integrity": "sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==", + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.7.tgz", + "integrity": "sha512-hLj7fuMow6f0lbB0cD14Lz2xNjwsyruH251Pk4t/yIitCFJbmY1myuLlHm/q06aST4jg6EgAh74PIBBrRqpVAQ==", "dev": true, + "license": "MIT", "dependencies": { "chokidar": "^3.5.2", - "debug": "^3.2.7", + "debug": "^4", "ignore-by-default": "^1.0.1", "minimatch": "^3.1.2", "pstree.remy": "^1.1.8", - "semver": "^5.7.1", - "simple-update-notifier": "^1.0.7", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", "supports-color": "^5.5.0", "touch": "^3.1.0", "undefsafe": "^2.0.5" @@ -5772,22 +5917,13 @@ "nodemon": "bin/nodemon.js" }, "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/nodemon" } }, - "node_modules/nodemon/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "dev": true, - "dependencies": { - "ms": "^2.1.1" - } - }, "node_modules/nodemon/node_modules/has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -5797,15 +5933,6 @@ "node": ">=4" } }, - "node_modules/nodemon/node_modules/semver": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", - "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", - "dev": true, - "bin": { - "semver": "bin/semver" - } - }, "node_modules/nodemon/node_modules/supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -6185,20 +6312,34 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.1.tgz", + "integrity": "sha512-G+YdqtITVZmOJje6QkXQWzl3fSfMxFwm1tjTyo9exhkmWSqC4Yhd1+lug++IlR2mvRVAxEDDWYkQdeSztajqgg==", "dev": true, + "license": "MIT", "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -6409,6 +6550,19 @@ "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", "dev": true }, + "node_modules/regexpp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", + "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -6771,24 +6925,16 @@ "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" }, "node_modules/simple-update-notifier": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", - "integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", "dev": true, + "license": "MIT", "dependencies": { - "semver": "~7.0.0" + "semver": "^7.5.3" }, "engines": { - "node": ">=8.10.0" - } - }, - "node_modules/simple-update-notifier/node_modules/semver": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", - "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==", - "dev": true, - "bin": { - "semver": "bin/semver.js" + "node": ">=10" } }, "node_modules/sisteransi": { @@ -7144,6 +7290,23 @@ "express": ">=4.0.0 || >=5.0.0-beta" } }, + "node_modules/synckit": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", + "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/tar": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", diff --git a/package.json b/package.json index f127247..e4754f0 100644 --- a/package.json +++ b/package.json @@ -2,20 +2,19 @@ "name": "nodejs_auth-api", "version": "1.2.0", "description": "A backend authentication & authorization project to handle the scale and complexity of an application. It is design while keeping the different environments in the mind.", - "main": "index.js", + "main": "server.js", "scripts": { "start": "npm run build && npm run serve", - "serve": "node -r dotenv/config build/src/server.js", + "serve": "node -r dotenv/config build/server.js", "build": "npm run clean && npm run build-ts", "watch": "npx concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold,red.bold\" \"npm run watch-ts\" \"npm run watch-node\"", - "watch-node": "nodemon -r dotenv/config build/src/server.js", + "watch-node": "nodemon -r dotenv/config build/server.js", "clean": "npx rimraf ./build", "build-ts": "npx tsc --project tsconfig.prod.json", "watch-ts": "npx tsc -w", "lint": "npx eslint . --ext ts --report-unused-disable-directives --max-warnings 0", "lint:fix": "npm run lint --fix", - "prettier:write": "npx prettier . --write", - "prettier": "npx prettier . --check", + "format": "npx prettier \"**/*.+(json|ts|tsx|js)\" --write", "test": "npx jest --forceExit --detectOpenHandles --coverage --verbose", "install:packages": "npm i", "upgrade:packages": "npm update --save-dev && npm update --save", @@ -61,9 +60,12 @@ "concurrently": "^8.2.1", "dotenv": "^16.3.1", "eslint": "^8.57.1", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^5.2.1", "jest": "^29.6.2", - "nodemon": "^2.0.20", - "prettier": "^2.8.1", + "nodemon": "^3.1.7", + "prettier": "^3.4.0", "supertest": "^6.3.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/tsconfig.json b/tsconfig.json index 9d51b64..902aae2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,30 +1,34 @@ { "compilerOptions": { + "target": "ES2021", "module": "CommonJS", + "moduleResolution": "node", + "lib": ["ES2021", "DOM"], "esModuleInterop": true, - "target": "ES2021", // or higher if needed - "allowJs": false, - "strictNullChecks": true, - "noImplicitAny": true, + "forceConsistentCasingInFileNames": true, "strict": true, - "strictFunctionTypes": false, // Optional: Enforces stricter checks for function types - "noImplicitThis": true, // Optional: Enforces stricter checks on 'this' - "moduleResolution": "node", + "skipLibCheck": true, + "outDir": "./build", + "rootDir": "./src", + "baseUrl": "./", "resolveJsonModule": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "strictNullChecks": true, + "noImplicitAny": true, + "noImplicitThis": true, "sourceMap": true, - "outDir": "build", - "baseUrl": ".", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "declaration": true, + "types": ["node", "jest", "express"], "paths": { "*": ["node_modules/*", "src/types/*"] - }, - "types": ["node"], // Include Node.js types - "skipLibCheck": true, // Skips type checking of declaration files for faster builds - "forceConsistentCasingInFileNames": true, // Ensures file name casing consistency - "noFallthroughCasesInSwitch": true, // Prevents fall-through cases in switch statements - "noUncheckedIndexedAccess": true, // Ensures array access is checked for undefined - "declaration": true, // Generates .d.ts files alongside .js files - "incremental": true // Enables incremental builds for faster compilation + } }, - "include": ["src/**/*", "swaggerConfig.ts"], - "exclude": [".templates", "node_modules"] + "include": ["src/**/*", "src/types/**/*.d.ts", "src/swaggerConfig.ts"], + "exclude": ["node_modules", "build", "dist"] } diff --git a/tsconfig.prod.json b/tsconfig.prod.json index e145ccc..65808cb 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -1,9 +1,9 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "sourceMap": false, // Disable source maps for production - "removeComments": true, // Remove comments to reduce bundle size - "declaration": false, // Disable declaration files if not needed in production - "noImplicitReturns": true // Ensure all code paths return a value + "sourceMap": false, + "removeComments": true, + "declaration": false, + "noImplicitReturns": true } }