Skip to content

Commit

Permalink
fix lint and typecheck commands across monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
sitek94 committed Nov 26, 2023
1 parent ce89084 commit ac3c6e6
Show file tree
Hide file tree
Showing 28 changed files with 107 additions and 53 deletions.
4 changes: 3 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"build": "storybook build -o build",
"start": "serve build",
"clean": "rm -rf .turbo && rm -rf node_modules",
"lint": "eslint ."
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@repo/ui": "workspace:*",
Expand Down
3 changes: 0 additions & 3 deletions apps/nestjs/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
testEnvironment: 'node',
rootDir: './src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: './coverage',
}
10 changes: 7 additions & 3 deletions apps/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"build": "nest build",
"develop": "nest start --watch",
"develop:debug": "nest start --debug --watch",
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"start": "node build/main",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.config.js"
"test:e2e": "jest --config ./test/jest-e2e.config.js",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand All @@ -23,11 +26,12 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/types": "workspace:*",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@repo/eslint-config": "workspace:*",
"@repo/tsconfig": "workspace:^",
"@repo/types": "workspace:*",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
Expand Down
3 changes: 2 additions & 1 deletion apps/nestjs/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'

import { AppController } from './app.controller'
import { AppService } from './app.service'
Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get } from '@nestjs/common'

import { AppService } from './app.service'
import type { AppService } from './app.service'

@Controller()
export class AppController {
Expand Down
6 changes: 4 additions & 2 deletions apps/nestjs/src/cats/cats.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'

import { CatsController } from './cats.controller'
import { CatsService } from './cats.service'
import { CreateCatDto } from './dto/create-cat.dto'
import type { CreateCatDto } from './dto/create-cat.dto'

describe('Cats Controller', () => {
let controller: CatsController
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('Cats Controller', () => {
age: 2,
},
])

expect(service.findAll).toHaveBeenCalled()
})
})
Expand Down
4 changes: 1 addition & 3 deletions apps/nestjs/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'

import { CatsService } from './cats.service'
import { CreateCatDto } from './dto/create-cat.dto'
import { Cat } from './schemas/cat.schema'
import type { Cat } from './schemas/cat.schema'

@Controller('cats')
export class CatsController {
Expand All @@ -25,8 +25,6 @@ export class CatsController {

@Delete(':id')
async delete(@Param('id') id: string) {
console.log('id', id)

return this.catsService.delete(id)
}
}
7 changes: 4 additions & 3 deletions apps/nestjs/src/cats/cats.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getModelToken } from '@nestjs/mongoose'
import { Test, TestingModule } from '@nestjs/testing'
import { Model } from 'mongoose'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'
import type { Model } from 'mongoose'

import { CatsService } from './cats.service'
import { Cat } from './schemas/cat.schema'
import type { Cat } from './schemas/cat.schema'

const mockCat = {
name: 'Cat #1',
Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/cats/cats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'

import { CreateCatDto } from './dto/create-cat.dto'
import type { CreateCatDto } from './dto/create-cat.dto'
import { Cat } from './schemas/cat.schema'

@Injectable()
Expand Down
4 changes: 2 additions & 2 deletions apps/nestjs/src/cats/schemas/cat.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Cat as CatInterface } from '@repo/types'
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { HydratedDocument } from 'mongoose'
import type { Cat as CatInterface } from '@repo/types'
import type { HydratedDocument } from 'mongoose'

export type CatDocument = HydratedDocument<Cat>

Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/config/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerAs } from '@nestjs/config'

export type AppConfig = {
export interface AppConfig {
env: 'development' | 'production' | 'test'
port: number
}
Expand Down
3 changes: 2 additions & 1 deletion apps/nestjs/src/dogs/dogs.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'

import { DogsController } from './dogs.controller'
import { DogsService } from './dogs.service'
Expand Down
4 changes: 2 additions & 2 deletions apps/nestjs/src/dogs/dogs.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dog } from '@repo/types'
import { Controller, Get } from '@nestjs/common'
import type { Dog } from '@repo/types'

import { DogsService } from './dogs.service'
import type { DogsService } from './dogs.service'

@Controller('dogs')
export class DogsController {
Expand Down
3 changes: 2 additions & 1 deletion apps/nestjs/src/dogs/dogs.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'

import { DogsService } from './dogs.service'

Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/dogs/dogs.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dog } from '@repo/types'
import { Injectable } from '@nestjs/common'
import type { Dog } from '@repo/types'

@Injectable()
export class DogsService {
Expand Down
9 changes: 6 additions & 3 deletions apps/nestjs/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ async function bootstrap() {
const logger = new Logger('NestApplication')
const app = await NestFactory.create(AppModule)
const configService = app.get(ConfigService)
const port = configService.get('app.port')
const host = configService.get('app.host')
const port = configService.get<string>('app.port')
const host = configService.get<string>('app.host')

await app.listen(port, host)

logger.log(`Nest application running on port ${port}`)
}

bootstrap()
bootstrap().catch(error => {
console.error(error)
process.exit(1)
})
5 changes: 3 additions & 2 deletions apps/nestjs/test/dogs.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { INestApplication } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import type { INestApplication } from '@nestjs/common'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'
import request from 'supertest'

import { DogsModule } from '~/dogs/dogs.module'
Expand Down
17 changes: 2 additions & 15 deletions apps/nestjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
{
"extends": "../../tsconfig.json",
"extends": "@repo/tsconfig/nest.json",
"include": ["**/*.ts", "jest.config.js"],
"exclude": ["node_modules", "build"],
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./build",
"incremental": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
"baseUrl": "./",
"paths": {
"~/*": ["./src/*"]
Expand Down
10 changes: 10 additions & 0 deletions libs/eslint-config/_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ module.exports = {
// Following rules are disabled during setup, but should probably be enabled later:

// Errors as unknown, etc.
'no-console': 'off',
'@typescript-eslint/no-explicit-any': 'off',

// Some weird type issues when calling `catsApi` in Remix index route
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',

'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
},
}
2 changes: 1 addition & 1 deletion libs/eslint-config/nest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
},
},
overrides: [
// Jest
// Jest configs
{
files: ['jest.config.js', 'jest-e2e.config.js'],
rules: {
Expand Down
22 changes: 22 additions & 0 deletions libs/tsconfig/nest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "./base.json",
"$schema": "https://json.schemastore.org/tsconfig",
"display": "NestJS",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./build",
"incremental": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
"baseUrl": "."
}
}
4 changes: 2 additions & 2 deletions libs/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export type Cat = {
export interface Cat {
_id: string
name: string
age: number
breed: string
}

export type Dog = {
export interface Dog {
_id: string
name: string
}
6 changes: 6 additions & 0 deletions libs/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"name": "@repo/types",
"private": true,
"main": "index.ts",
"scripts": {
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/tsconfig": "workspace:^",
"typescript": "^5.3.2"
}
}
10 changes: 10 additions & 0 deletions libs/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@repo/tsconfig/base.json",
"include": ["."],
"exclude": ["dist", "node_modules"],
"compilerOptions": {
"lib": ["ES2015"],
"module": "CommonJS",
"outDir": "./dist"
}
}
1 change: 1 addition & 0 deletions libs/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"scripts": {
"build": "tsup",
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"develop": "tsup --watch",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test": "pnpm -r test",
"test:e2e": "pnpm -r test:e2e",
"test:nestjs": "pnpm -F nestjs test",
"typecheck": "tsc -b ."
"typecheck": "turbo run typecheck"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.4.11",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

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

7 changes: 4 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependsOn": ["^build"],
// note: output globs are relative to each package's `package.json`
// (and not the monorepo root)
"outputs": [".next/**", "!.next/cache/**"]
"outputs": [".next/**", "!.next/cache/**", ".cache"]
},
"deploy": {
// A package's `deploy` script depends on the `build`,
Expand All @@ -21,11 +21,12 @@
// either a `.tsx` or `.ts` file has changed in `src` or `test` folders.
"inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts", "test/**/*.tsx"]
},
// A package's `lint` script has no dependencies and
// can be run whenever. It also has no filesystem outputs.
"lint": {
"dependsOn": ["^build"]
},
"typecheck": {
"dependsOn": ["^build"]
},
"develop": {
"dependsOn": ["build"],
"cache": false,
Expand Down

0 comments on commit ac3c6e6

Please sign in to comment.