From c83319c300d4756b011113d829a9a531b162a7a2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 25 Aug 2022 19:59:53 +0200 Subject: [PATCH] Added linting so everything gets absolutly imported --- .eslintrc.js | 6 +++++- package.json | 1 + src/controller/auth.ts | 6 +++--- src/controller/filesystem.ts | 6 +++--- src/controller/user.ts | 2 +- src/modules/auth.ts | 14 +++++--------- src/modules/filesystem.ts | 6 +++--- src/services/auth/base.ts | 4 ++-- src/services/auth/gitlab.ts | 2 +- src/services/auth/tfa.ts | 2 +- src/services/filesystem.ts | 2 +- tsconfig.json | 2 +- yarn.lock | 5 +++++ 13 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2237313..9989762 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { tsconfigRootDir: __dirname, sourceType: 'module', }, - plugins: ['@typescript-eslint/eslint-plugin'], + plugins: ['@typescript-eslint/eslint-plugin', 'no-relative-import-paths'], extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', @@ -21,5 +21,9 @@ module.exports = { '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-explicit-any': 'off', + 'no-relative-import-paths/no-relative-import-paths': [ + 'error', + { 'allowSameFolder': true, 'rootDir': 'src' } + ] }, }; diff --git a/package.json b/package.json index a240b92..8250c86 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "copy-webpack-plugin": "^11.0.0", "eslint": "^8.21.0", "eslint-config-prettier": "^8.5.0", + "eslint-plugin-no-relative-import-paths": "^1.4.0", "eslint-plugin-prettier": "^4.2.1", "jest": "^28.1.3", "prettier": "^2.7.1", diff --git a/src/controller/auth.ts b/src/controller/auth.ts index 19b74cf..a99a0ac 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -12,11 +12,11 @@ import { UseGuards, ValidationPipe } from '@nestjs/common'; -import { AuthService } from '../services/auth'; +import { AuthService } from 'services/auth'; import { AuthGuard } from '@nestjs/passport'; -import { Public } from '../authguards'; +import { Public } from 'authguards'; import { Requests, Responses } from 'dto'; -import { tfaTypes } from '../entities'; +import { tfaTypes } from 'entities'; import { toDataURL } from 'qrcode'; import * as base32 from 'thirty-two'; diff --git a/src/controller/filesystem.ts b/src/controller/filesystem.ts index 2a34145..3bd3841 100644 --- a/src/controller/filesystem.ts +++ b/src/controller/filesystem.ts @@ -10,9 +10,9 @@ import { ValidationPipe } from '@nestjs/common'; import { Responses, Requests, validateAsyncInline } from 'dto'; -import FileSystemService from '../services/filesystem'; -import { UserRole } from '../entities'; -import { Role } from '../authguards'; +import FileSystemService from 'services/filesystem'; +import { UserRole } from 'entities'; +import { Role } from 'authguards'; @Controller('api/fs') export default class FileSystemController { diff --git a/src/controller/user.ts b/src/controller/user.ts index 9f674a2..bd1846b 100644 --- a/src/controller/user.ts +++ b/src/controller/user.ts @@ -1,5 +1,5 @@ import { Controller, Get, Post, Request } from '@nestjs/common'; -import { AuthService } from '../services/auth'; +import { AuthService } from 'services/auth'; import { Responses } from 'dto'; @Controller('api/user') diff --git a/src/modules/auth.ts b/src/modules/auth.ts index d35540d..9a2263f 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -1,14 +1,10 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { INode, JWTToken, User } from '../entities'; -import { - AuthService, - AuthLocalService, - AuthJwtService -} from '../services/auth'; -import FileSystemService from '../services/filesystem'; -import AuthController from '../controller/auth'; -import UserController from '../controller/user'; +import { INode, JWTToken, User } from 'entities'; +import { AuthService, AuthLocalService, AuthJwtService } from 'services/auth'; +import FileSystemService from 'services/filesystem'; +import AuthController from 'controller/auth'; +import UserController from 'controller/user'; @Module({ imports: [TypeOrmModule.forFeature([User, INode, JWTToken])], diff --git a/src/modules/filesystem.ts b/src/modules/filesystem.ts index 86f6bbc..3830db7 100644 --- a/src/modules/filesystem.ts +++ b/src/modules/filesystem.ts @@ -1,8 +1,8 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { INode } from '../entities'; -import FileSystemService from '../services/filesystem'; -import FileSystemController from '../controller/filesystem'; +import { INode } from 'entities'; +import FileSystemService from 'services/filesystem'; +import FileSystemController from 'controller/filesystem'; @Module({ imports: [TypeOrmModule.forFeature([INode])], diff --git a/src/services/auth/base.ts b/src/services/auth/base.ts index 17e9055..a89cbb6 100644 --- a/src/services/auth/base.ts +++ b/src/services/auth/base.ts @@ -4,10 +4,10 @@ import { UnauthorizedException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { JWTToken, User, UserRole } from '../../entities'; +import { JWTToken, User, UserRole } from 'entities'; import { LessThanOrEqual, Repository } from 'typeorm'; import * as argon2 from 'argon2'; -import FileSystemService from '../filesystem'; +import FileSystemService from 'services/filesystem'; import * as jwt from 'jsonwebtoken'; export const jwtSecret = 'CUM'; diff --git a/src/services/auth/gitlab.ts b/src/services/auth/gitlab.ts index e7d8ee6..2cf3622 100644 --- a/src/services/auth/gitlab.ts +++ b/src/services/auth/gitlab.ts @@ -1,4 +1,4 @@ -import { User, UserRole } from '../../entities'; +import { User, UserRole } from 'entities'; import { FastifyRequest } from 'fastify'; import axios from 'axios'; import * as argon2 from 'argon2'; diff --git a/src/services/auth/tfa.ts b/src/services/auth/tfa.ts index 93b3462..9e899d3 100644 --- a/src/services/auth/tfa.ts +++ b/src/services/auth/tfa.ts @@ -1,4 +1,4 @@ -import { tfaTypes, User } from '../../entities'; +import { tfaTypes, User } from 'entities'; import { BadRequestException } from '@nestjs/common'; import BaseAuthService from './base'; import { randomBytes } from 'crypto'; diff --git a/src/services/filesystem.ts b/src/services/filesystem.ts index 16c3a28..eb86e19 100644 --- a/src/services/filesystem.ts +++ b/src/services/filesystem.ts @@ -6,7 +6,7 @@ import { UnauthorizedException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { INode, User } from '../entities'; +import { INode, User } from 'entities'; import { Repository } from 'typeorm'; import { Multipart } from '@fastify/multipart'; import { pipeline } from 'stream/promises'; diff --git a/tsconfig.json b/tsconfig.json index 631555b..08f305b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "target": "es2017", "sourceMap": true, "outDir": "./dist", - "baseUrl": "./", + "baseUrl": "./src", "incremental": true, "skipLibCheck": true, "resolveJsonModule": true, diff --git a/yarn.lock b/yarn.lock index 032b637..ba70dc5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2465,6 +2465,11 @@ eslint-config-prettier@^8.5.0: resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1" integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q== +eslint-plugin-no-relative-import-paths@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-no-relative-import-paths/-/eslint-plugin-no-relative-import-paths-1.4.0.tgz#59489ebc19688d1398bfe53d3ad320b3ed42ca17" + integrity sha512-J/ok26KqJM+20VsxNEcHc9kyW0dcFHBlihOO5FFv/GQqwcW+G1UngbHLpnPAdOQ1dJg5Ljk/40csqfZ3mnneUw== + eslint-plugin-prettier@^4.2.1: version "4.2.1" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz#651cbb88b1dab98bfd42f017a12fa6b2d993f94b"