Skip to content

Commit

Permalink
chore(codestyle): Setup eslint deps, rules and fix violations
Browse files Browse the repository at this point in the history
hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \
                    --runs 100 "nx run-many -t lint"
  Time (mean ± σ):    2.686s ±  0.044s  [User: 3.278s, System: 0.222s]
  Range (min … max):  2.594s …  2.818s  100 runs

hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \
                    --runs 100 "nx run-many -t build"
  Time (mean ± σ):    2.254s ±  0.019s  [User: 2.561s, System: 0.213s]
  Range (min … max):  2.229s …  2.372s  100 runs

hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \
                    --runs 100 "nx run-many -t test"
  Time (mean ± σ):    1.636s ±  0.007s  [User: 0.784s, System: 0.134s]
  Range (min … max):  1.611s …  1.659s  100 runs

More:
- https://nx.dev/recipes/tips-n-tricks/eslint
  • Loading branch information
roalcantara committed Jun 4, 2024
1 parent a135fec commit de4d116
Show file tree
Hide file tree
Showing 11 changed files with 804 additions and 73 deletions.
50 changes: 49 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
root: true
env:
es2021: true
node: true
browser: true
ignorePatterns:
- '**/*'
plugins:
- '@nx'
- eslint-comments
extends:
- eslint:recommended
- plugin:eslint-comments/recommended
- plugin:promise/recommended
- plugin:import/recommended
- plugin:prettier/recommended
rules:
import/first: error
import/no-duplicates: error
import/no-self-import: error
import/no-absolute-path: error
import/no-named-default: error
import/order:
- error
- groups:
- builtin
- external
- internal
newlines-between: never
alphabetize:
order: asc
caseInsensitive: false

overrides:
- files:
- '*.ts'
Expand All @@ -21,9 +49,24 @@ overrides:
- files:
- '*.ts'
- '*.tsx'
parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: latest
sourceType: module
project: tsconfig.*?.json
extends:
- plugin:@nx/typescript
rules: {}
- plugin:@typescript-eslint/recommended
- plugin:import/typescript
- xo
- xo-typescript/space
rules:
new-cap: off
semi: off
'@typescript-eslint/semi': off
'@typescript-eslint/comma-dangle': off
'@typescript-eslint/object-curly-spacing': off
'@typescript-eslint/require-await': error
- files:
- '*.js'
- '*.jsx'
Expand All @@ -35,6 +78,11 @@ overrides:
- '*.spec.tsx'
- '*.spec.js'
- '*.spec.jsx'
extends:
- plugin:jest/style
- plugin:jest/recommended
- plugin:jest-formatting/recommended
env:
jest: true
jest/globals: true
rules: {}
25 changes: 12 additions & 13 deletions apps/app/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Test, type TestingModule } from '@nestjs/testing'
import { AppController } from './app.controller'
import { AppService } from './app.service'

describe('AppController', () => {
let app: TestingModule;
let app: TestingModule

beforeAll(async () => {
app = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
});
providers: [AppService]
}).compile()
})

describe('getData', () => {
it('should return "Hello API"', () => {
const appController = app.get<AppController>(AppController);
expect(appController.getData()).toEqual({ message: 'Hello API' });
});
});
});
const appController = app.get(AppController)
expect(appController.getData()).toEqual({ message: 'Hello API' })
})
})
})
7 changes: 3 additions & 4 deletions apps/app/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Controller, Get } from '@nestjs/common';

import { AppService } from './app.service';
import { Controller, Get } from '@nestjs/common'
import { AppService } from './app.service'

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getData() {
return this.appService.getData();
return this.appService.getData()
}
}
9 changes: 4 additions & 5 deletions apps/app/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
providers: [AppService]
})
export class AppModule {}
23 changes: 11 additions & 12 deletions apps/app/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';
import { Test } from '@nestjs/testing'
import { AppService } from './app.service'

describe('AppService', () => {
let service: AppService;
let service: AppService

beforeAll(async () => {
const app = await Test.createTestingModule({
providers: [AppService],
}).compile();
providers: [AppService]
}).compile()

service = app.get<AppService>(AppService);
});
service = app.get<AppService>(AppService)
})

describe('getData', () => {
it('should return "Hello API"', () => {
expect(service.getData()).toEqual({ message: 'Hello API' });
});
});
});
expect(service.getData()).toEqual({ message: 'Hello API' })
})
})
})
4 changes: 2 additions & 2 deletions apps/app/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common'

@Injectable()
export class AppService {
getData(): { message: string } {
return { message: 'Hello API' };
return { message: 'Hello API' }
}
}
26 changes: 10 additions & 16 deletions apps/app/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';
import { Logger } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app/app.module'

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
await app.listen(port);
const app = await NestFactory.create(AppModule)
const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
const port = process.env.PORT ?? 3000
await app.listen(port)
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
)
}

bootstrap();
bootstrap().then(console.log).catch(console.error)
14 changes: 7 additions & 7 deletions apps/app/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
const { join } = require('path');
const { join } = require('path')
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin')

module.exports = {
output: {
path: join(__dirname, '../../dist/apps/app'),
path: join(__dirname, '../../dist/apps/app')
},
plugins: [
new NxAppWebpackPlugin({
Expand All @@ -13,7 +13,7 @@ module.exports = {
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
}),
],
};
outputHashing: 'none'
})
]
}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
"@typescript-eslint/parser": "^7.12.0",
"eslint": "~9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.45.0",
"eslint-config-xo-typescript": "^4.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-jest-formatting": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.2.0",
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
"nx": "19.1.2",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lib": ["es2020", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"strictNullChecks": true,
"baseUrl": ".",
"paths": {}
},
Expand Down
Loading

0 comments on commit de4d116

Please sign in to comment.