Skip to content

Commit

Permalink
chore: upgrade eslint, update husky config
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 17, 2025
1 parent 4134457 commit 2c011fa
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 2,513 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['tests/**'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
},
},
);
18 changes: 9 additions & 9 deletions lib/common/typeorm.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export function getDataSourceToken(
| string = DEFAULT_DATA_SOURCE_NAME,
): string | Function | Type<DataSource> {
return DEFAULT_DATA_SOURCE_NAME === dataSource
? DataSource ?? Connection
? (DataSource ?? Connection)
: 'string' === typeof dataSource
? `${dataSource}DataSource`
: DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name
? DataSource ?? Connection
: `${dataSource.name}DataSource`;
? `${dataSource}DataSource`
: DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name
? (DataSource ?? Connection)
: `${dataSource.name}DataSource`;
}

/** @deprecated */
Expand Down Expand Up @@ -128,10 +128,10 @@ export function getEntityManagerToken(
return DEFAULT_DATA_SOURCE_NAME === dataSource
? EntityManager
: 'string' === typeof dataSource
? `${dataSource}EntityManager`
: DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name
? EntityManager
: `${dataSource.name}EntityManager`;
? `${dataSource}EntityManager`
: DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name
? EntityManager
: `${dataSource.name}EntityManager`;
}

export function handleRetry(
Expand Down
4 changes: 2 additions & 2 deletions lib/entities-metadata.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class EntitiesMetadataStorage {
this.storage.set(dataSourceToken, collection);
}
entities.forEach((entity) => {
if (collection!.includes(entity)) {
if (collection.includes(entity)) {
return;
}
collection!.push(entity);
collection.push(entity);
});
}

Expand Down
4 changes: 3 additions & 1 deletion lib/typeorm-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ export class TypeOrmCoreModule implements OnApplicationShutdown {
} as DataSourceOptions);
}
// TODO: remove "dataSource.initialize" condition (left for backward compatibility)
return (dataSource as any).initialize && !dataSource.isInitialized && !options.manualInitialization
return (dataSource as any).initialize &&
!dataSource.isInitialized &&
!options.manualInitialization
? dataSource.initialize()
: dataSource;
}).pipe(
Expand Down
8 changes: 5 additions & 3 deletions lib/typeorm.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export function createTypeOrmProviders(
return (entities || []).map((entity) => ({
provide: getRepositoryToken(entity, dataSource),
useFactory: (dataSource: DataSource) => {
const entityMetadata = dataSource.entityMetadatas.find((meta) => meta.target === entity)
const isTreeEntity = typeof entityMetadata?.treeType !== 'undefined'
return isTreeEntity
const entityMetadata = dataSource.entityMetadatas.find(
(meta) => meta.target === entity,
);
const isTreeEntity = typeof entityMetadata?.treeType !== 'undefined';
return isTreeEntity
? dataSource.getTreeRepository(entity)
: dataSource.options.type === 'mongodb'
? dataSource.getMongoRepository(entity)
Expand Down
Loading

0 comments on commit 2c011fa

Please sign in to comment.