Skip to content

Commit

Permalink
v11: strict typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Jan 24, 2021
1 parent 65ca756 commit 192597a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 27 deletions.
15 changes: 9 additions & 6 deletions app/templates/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: "module" // Allows for the use of imports
sourceType: 'module', // Allows for the use of imports
},
extends: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
// 'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],

// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
};
};
4 changes: 2 additions & 2 deletions app/templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM node:12-alpine
FROM node:14-alpine
LABEL Author Carmine DiMascio <cdimascio@gmail.com>

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . /usr/src/app
RUN npm install
RUN npm install && npm run compile

EXPOSE 3000

Expand Down
17 changes: 10 additions & 7 deletions app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "<%= name %>",
"version": "<%= version %>",
"description": "<%= description %>",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"start": "node dist/index.js",
"compile": "ts-node build.ts && tsc",
Expand All @@ -18,23 +18,26 @@
"cookie-parser": "^1.4.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"pino": "^6.8.0",
"pino": "^6.11.0",
<% if (specification === 'openapi_3') { %>
"express-openapi-validator": "^4.10.6"
"express-openapi-validator": "^4.10.9"
<% } else { %>
"swagger-express-middleware": "^4.0.2"
<% } %>
},
"devDependencies": {
"@types/chai": "^4.2.14",
"@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.11",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.22",
"@types/pino": "^6.3.5",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"@types/shelljs": "^0.8.8",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"chai": "^4.2.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.3.1",
"mocha": "^8.2.1",
"nodemon": "^2.0.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ExamplesService from '../../services/examples.service';
import { Request, Response } from 'express';

export class Controller {
all(req: Request, res: Response): void {
all(_: Request, res: Response): void {
ExamplesService.all().then(r => res.json(r));
}

Expand Down
8 changes: 3 additions & 5 deletions app/templates/server/api/middlewares/error.handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Request, Response, NextFunction } from 'express';

<% if (specification === 'openapi_3') { %>
// eslint-disable-next-line no-unused-vars, no-shadow
export default function errorHandler(
err,
req: Request,
err: any,
_req: Request,
res: Response,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
next: NextFunction
_next: NextFunction
): void {
const errors = err.errors || [{ message: err.message }];
res.status(err.status || 500).json({ errors });
Expand Down
2 changes: 1 addition & 1 deletion app/templates/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './common/env';
import Server from './common/server';
import routes from './routes';

const port = parseInt(process.env.PORT);
const port = parseInt(process.env.PORT ?? '3000');
export default new Server()
.router(routes)
.listen(port);
22 changes: 17 additions & 5 deletions app/templates/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
{
"compileOnSave": false,
"compilerOptions": {
"target": "es6",
"target":"ES2018",
"module": "commonjs",
"lib": ["es2020"],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"sourceMap": true,
"moduleResolution": "node",
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"sourceMap": true,
"strictPropertyInitialization":false,
"resolveJsonModule": true,
"outDir": "dist",
"typeRoots": ["node_modules/@types"],
"resolveJsonModule": true
"typeRoots": ["./node_modules/@types"]
},
"include": ["typings.d.ts", "server/**/*.ts"],
"include": ["server/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 192597a

Please sign in to comment.