From 6f571e05ca7487ed24020a7e45668f0dadb69871 Mon Sep 17 00:00:00 2001 From: sbriat Date: Thu, 30 Mar 2023 10:28:20 +0200 Subject: [PATCH 1/2] lint pretty --check --- .eslintrc.js | 2 +- .gitlab-ci.yml | 6 +++--- .prettierignore | 6 ++++++ .prettierrc => .prettierrc.json | 0 README.md | 21 +++++++++++++-------- ci/Dockerfile | 6 ++++-- package.json | 3 +++ 7 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 .prettierignore rename .prettierrc => .prettierrc.json (100%) diff --git a/.eslintrc.js b/.eslintrc.js index 8f5aedb..259de13 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,7 @@ module.exports = { parser: '@typescript-eslint/parser', parserOptions: { project: 'tsconfig.json', - tsconfigRootDir : __dirname, + tsconfigRootDir: __dirname, sourceType: 'module', }, plugins: ['@typescript-eslint/eslint-plugin'], diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 406ae1f..0283fdf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ test: stage: test image: docker/compose:latest variables: - DOCKER_TLS_CERTDIR: "" + DOCKER_TLS_CERTDIR: '' services: - docker:dind script: @@ -22,7 +22,7 @@ test: - docker exec -t v3-auth-api sh -c "npm run test:integration:ci" coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/ rules: - - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH || $CI_COMMIT_MESSAGE =~ /--check/ || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH || $CI_COMMIT_MESSAGE =~ /--check/ || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' when: always ############### @@ -33,7 +33,7 @@ build: stage: build image: docker:20.10.22 variables: - DOCKER_TLS_CERTDIR: "" + DOCKER_TLS_CERTDIR: '' services: - docker:dind before_script: diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..192c132 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +node_modules +*.log* +.env +dist +coverage +.prettierrc.json diff --git a/.prettierrc b/.prettierrc.json similarity index 100% rename from .prettierrc rename to .prettierrc.json diff --git a/README.md b/README.md index a224b76..ad221ff 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A RabbitMQ instance is also required to send / receive messages when data has be ## Installation -- copy `.env.dist` to `.env` : +- copy `.env.dist` to `.env` : ```bash cp .env.dist .env @@ -22,13 +22,13 @@ A RabbitMQ instance is also required to send / receive messages when data has be Modify it if needed. -- install the dependencies : +- install the dependencies : ```bash npm install ``` - -- start the containers : + +- start the containers : ```bash docker compose up -d @@ -150,7 +150,7 @@ For AuthZ, the app exposes the following [gRPC](https://grpc.io/) services : } ``` - In return, the service gives an authorization response : + In return, the service gives an authorization response : ```json { @@ -158,15 +158,14 @@ For AuthZ, the app exposes the following [gRPC](https://grpc.io/) services : } ``` - ## Messages Various RabbitMQ messages are sent for logging purpose. -## Tests +## Tests / ESLint / Prettier Tests are run outside the container for ease of use (switching between different environments inside containers using prisma is complicated and error prone). -The integration tests use a dedicated database (see *db-test* section of *docker-compose.yml*). +The integration tests use a dedicated database (see _db-test_ section of _docker-compose.yml_). ```bash # run all tests (unit + integration) @@ -180,6 +179,12 @@ npm run test:integration # coverage npm run test:cov + +# ESLint +npm run lint + +# Prettier +npm run pretty ``` ## License diff --git a/ci/Dockerfile b/ci/Dockerfile index 4b2a20c..a14d07c 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -25,5 +25,7 @@ RUN npm run build # Run unit tests RUN npm run test:unit:ci -# Start the server -CMD [ "node", "dist/main.js" ] +# ESLint / Prettier +RUN npm run lint:check +RUN npm run pretty:check + diff --git a/package.json b/package.json index 7ae696c..ab29c54 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,9 @@ "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "lint:check": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix-dry-run --ignore-path .gitignore", + "pretty:check": "./node_modules/.bin/prettier --check .", + "pretty": "./node_modules/.bin/prettier --write .", "test": "npm run migrate:test && dotenv -e .env.test jest", "test:unit": "jest --testPathPattern 'tests/unit/' --verbose", "test:unit:ci": "jest --testPathPattern 'tests/unit/' --coverage", From a5a509659870929749cb5a80f108497a9e093ec4 Mon Sep 17 00:00:00 2001 From: sbriat Date: Thu, 30 Mar 2023 10:32:17 +0200 Subject: [PATCH 2/2] lint pretty --- ci/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/Dockerfile b/ci/Dockerfile index a14d07c..26b388a 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -29,3 +29,5 @@ RUN npm run test:unit:ci RUN npm run lint:check RUN npm run pretty:check +# Start the server +CMD [ "node", "dist/main.js" ]