Skip to content

Commit

Permalink
BC-8200 - adjust ESLint rules (#5368)
Browse files Browse the repository at this point in the history
* add new ESLint-rules according to ticket
* adapt rules for @ infra, @ apps, @ core etc.
  • Loading branch information
hoeppner-dataport authored Dec 3, 2024
1 parent 7d6866a commit 67cbf0c
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 13 deletions.
111 changes: 108 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ module.exports = {
'arrow-parens': ['error', 'always'],
'arrow-body-style': ['error', 'as-needed', { requireReturnForObjectLiteral: true }],
'no-only-tests/no-only-tests': 'error',
'max-classes-per-file': ['warn', 1],
},
plugins: ['import', 'prettier', 'promise', 'no-only-tests'],
plugins: ['import', 'prettier', 'promise', 'no-only-tests', 'filename-rules'],
env: {
node: true,
mocha: true,
Expand Down Expand Up @@ -88,11 +89,27 @@ module.exports = {
'import/no-extraneous-dependencies': 'off', // better handles by ts resolver
'import/prefer-default-export': 'off',
'no-void': ['error', { allowAsStatement: true }],
'max-classes-per-file': 'off',
'class-methods-use-this': 'off',
'no-param-reassign': 'off',
'no-underscore-dangle': 'off',
'filename-rules/match': [1, 'kebabcase'],
'require-await': 'warn',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/explicit-member-accessibility': [
'warn',
{
accessibility: 'explicit',
overrides: {
accessors: 'no-public',
constructors: 'no-public',
methods: 'explicit',
properties: 'explicit',
parameterProperties: 'explicit',
},
},
],
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-empty-interface': [
'error',
Expand All @@ -105,7 +122,11 @@ module.exports = {
{
patterns: [
{
group: ['@infra/*/*', '@modules/*/*', '!*.module'],
group: ['@src/apps/**', '@src/core/**', '@src/modules/*/*', '@src/shared/**'],
message: 'Remove src/ from import path',
},
{
group: ['@infra/*/*', '@modules/*/*', '!@modules/*/testing', '!*.module'],
message: 'Do not deep import from a module',
},
],
Expand All @@ -122,7 +143,91 @@ module.exports = {
rules: {
// you should turn the original rule off *only* for test files
'@typescript-eslint/unbound-method': 'off',
'jest/prefer-spy-on': 'warn',
'jest/unbound-method': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'max-classes-per-file': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
},
},
{
files: ['apps/server/src/apps/**/*.ts'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@apps/**', '@infra/**', '@shared/**'],
message: 'apps-modules may NOT import from @apps, @infra or @shared',
},
],
},
],
},
},
{
files: ['apps/server/src/core/**/*.ts'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@apps/**', '@core/**', '@infra/**', '@modules/**'],
message: 'core-modules may NOT import from @apps, @core, @infra or @modules',
},
],
},
],
},
},
{
files: ['apps/server/src/infra/**/*.ts'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@apps/**', '@core/**', '@modules/**'],
message: 'infra-modules may NOT import from @apps, @core or @modules',
},
],
},
],
},
},
{
files: ['apps/server/src/modules/**/*.ts'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@apps/**'],
message: 'modules-modules may NOT import from @apps',
},
],
},
],
},
},
{
files: ['apps/server/src/shared/**/*.ts'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@apps/**', '@core/**', '@infra/**', '@modules/**', '@shared/**'],
message: 'shared modules may NOT import from @apps, @core, @infra, @modules or @shared',
},
],
},
],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ErrorLogger, ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogM
import util from 'util';
import { ErrorLoggable } from '../loggable/error.loggable';
import { ErrorUtils } from '../utils';
import { DomainErrorHandler } from './domainErrorHandler';
import { DomainErrorHandler } from './domain-error-handler';

class SampleLoggableException extends BadRequestException implements Loggable {
constructor(private testData: string) {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/core/error/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DomainErrorHandler } from './domainErrorHandler';
export { DomainErrorHandler } from './domain-error-handler';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CurrentUser, JWT, JwtAuthentication } from './jwt-auth.decorator';
export class TestDecoratorCurrentUserController {
@Get('test')
async test(@CurrentUser() currentUser: ICurrentUser): Promise<void> {
return Promise.resolve();
await Promise.resolve(currentUser);
}
}

Expand All @@ -21,7 +21,7 @@ export class TestDecoratorCurrentUserController {
export class TestDecoratorJWTController {
@Get('test')
async test(@JWT() jwt: string): Promise<void> {
return Promise.resolve();
await Promise.resolve(jwt);
}
}

Expand Down
19 changes: 16 additions & 3 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
]
},
"scripts": {
"lint-fix": "eslint . --fix --ignore-path .gitignore",
"lint": "eslint . --ignore-path .gitignore",
"test": "npm run nest:test && npm run feathers:test",
"feathers:test": "cross-env NODE_ENV=test npm run setup:db:seed && npm run nest:build && npm run coverage",
Expand Down Expand Up @@ -115,7 +114,6 @@
"nest:test:cov": "jest \"^((?!\\.load\\.spec\\.ts).)*\\.spec\\.ts$\" --coverage --force-exit --maxWorkers='50%'",
"nest:test:debug": "jest --runInBand",
"nest:lint": "eslint apps --ignore-path .gitignore",
"nest:lint:fix": "eslint apps --fix --ignore-path .gitignore",
"syncIndexes": "node ./scripts/syncIndexes.js",
"ensureIndexes": "npm run nest:start:console -- database sync-indexes",
"schoolExport": "node ./scripts/schoolExport.js",
Expand Down Expand Up @@ -311,6 +309,7 @@
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^8.10.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-filename-rules": "^1.3.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
Expand Down Expand Up @@ -340,4 +339,4 @@
"tsconfig-paths": "^4.1.1",
"typescript": "^5.5.4"
}
}
}

0 comments on commit 67cbf0c

Please sign in to comment.