Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bc-7808 - Adjust eslint config in tldraw-server #17

Merged
merged 10 commits into from
Sep 18, 2024
84 changes: 61 additions & 23 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.cjs'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin', 'jest'],
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts
extends: ['plugin:@typescript-eslint/stylistic-type-checked', 'plugin:prettier/recommended'],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.cjs'],
rules: {
'newline-before-return': 'error',
'require-await': 'error',
'no-return-assign': 'error',
'max-classes-per-file': 'error',
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z]',
match: false,
},
},
],
'@typescript-eslint/no-empty-interface': [
'error',
{
allowSingleExtends: true,
},
],
},
overrides: [
{
files: ['**/*spec.ts'],
plugins: ['jest'],
env: {
jest: true,
},
rules: {
// you should turn the original rule off *only* for test files
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'jest/unbound-method': 'error',
'jest/prefer-spy-on': 'error',
},
},
],
};
84 changes: 84 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read

env:
NODE_VERSION: '20'
jobs:
tests_cov:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wo wird eigentlich angegeben, dass Jobs required sind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bei Github

runs-on: ubuntu-latest
strategy:
matrix:
shard: [1]
services:
rabbitmq:
image: rabbitmq:3
ports:
- 5672:5672
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm ci
run: npm ci --prefer-offline --no-audit
- name: test:cov - test all with coverage
timeout-minutes: 15
run: export RUN_WITHOUT_JEST_COVERAGE='true' && export NODE_OPTIONS='--max_old_space_size=4096' && ./node_modules/.bin/jest --shard=${{ matrix.shard }}/${{ strategy.job-total }} --coverage --force-exit
- name: save-coverage
run: mv coverage/lcov.info coverage/${{matrix.shard}}.info
- name: "upload-artifacts"
uses: actions/upload-artifact@v4
with:
name: coverage-artifacts-${{ matrix.shard }}
path: coverage/
sonarcloud:
name: SonarCloud coverage
runs-on: ubuntu-latest
needs: [tests_cov]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
pattern: coverage-artifacts-*
path: coverage
merge-multiple: true
- name: Merge Code Coverage
run: |
sudo apt-get install -y lcov
find coverage -name *.info -exec echo -a {} \; | xargs lcov -o merged-lcov.info
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: SonarCloud upload coverage
uses: SonarSource/sonarcloud-github-action@v2.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
lint:
runs-on: ubuntu-latest
timeout-minutes: 6
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm ci
run: npm ci --prefer-offline --no-audit
- name: lint
run: npm run lint
4 changes: 2 additions & 2 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"server": {
"type": "application",
"root": ".",
"entryFile": "apps/tldraw-server.js",
"entryFile": "apps/tldraw-server.app.js",
"sourceRoot": "src",
"compilerOptions": {
"tsConfigPath": "tsconfig.json"
Expand All @@ -18,7 +18,7 @@
"worker": {
"type": "application",
"root": ".",
"entryFile": "apps/tldraw-worker.js",
"entryFile": "apps/tldraw-worker.app.js",
"sourceRoot": "src",
"compilerOptions": {
"tsConfigPath": "tsconfig.json"
Expand Down
123 changes: 123 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"start": "nest start server",
"start:server:dev": "nest start server --watch",
"start:server:debug": "nest start server --debug --watch",
"start:server:prod": "node dist/apps/tldraw-server.js",
"start:server:prod": "node dist/apps/tldraw-server.app.js",
"start:worker:dev": "nest start worker --watch",
"start:worker:debug": "nest start worker --debug --watch",
"start:worker:prod": "node dist/apps/tldraw-worker.js",
"start:worker:prod": "node dist/apps/tldraw-worker.app.js",
"lint": "eslint \"src/**/*.ts\" ",
"lint:fix": "eslint \"src/**/*.ts\" --fix",
"test": "jest",
Expand Down Expand Up @@ -53,6 +53,7 @@
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
Expand Down
10 changes: 10 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sonar.organization=schulcloud-verbund
sonar.projectKey=hpi-schul-cloud_tldraw-server
sonar.sources=.
sonar.tests=.
sonar.test.inclusions=**/*.spec.ts
sonar.exclusions=**/*.app.ts,
sonar.coverage.exclusions=**/*.factory.ts
sonar.cpd.exclusions=**/controller/dto/*.ts
sonar.javascript.lcov.reportPaths=merged-lcov.info
sonar.typescript.tsconfigPaths=tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Logger } from '../infra/logging/logger.js';
import { MetricsModule } from '../infra/metrics/metrics.module.js';
import { ServerModule } from '../modules/server/server.module.js';

async function bootstrap() {
async function bootstrap(): Promise<void> {
const httpPort = 3347;
const nestApp = await NestFactory.create(ServerModule);
nestApp.enableCors();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { WorkerModule } from '../modules/worker/worker.module.js';

async function bootstrap() {
async function bootstrap(): Promise<void> {
const nestApp = await NestFactory.createApplicationContext(WorkerModule);

await nestApp.init();
Expand Down
Loading
Loading