Skip to content

Commit

Permalink
Update linting rules, ignore some warnings for now
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Jan 31, 2023
1 parent b14f611 commit 60ffa3c
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 22 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module.exports = {
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
extraFileExtensions: ['.json'],
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended',
],
root: true,
Expand All @@ -15,6 +17,18 @@ module.exports = {
jest: true,
},
rules: {
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/unbound-method': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/no-misused-promises': ['error', {
checksVoidReturn: false,
}],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"deploy:demo": "pm2 deploy demo-ecosystem.config.js production update",
"lint": "eslint \"{src,scripts,test,@types}/**/*.ts\" --fix",
"lint:ci": "eslint \"{src,scripts,test,@types}/**/*.ts\"",
"lint": "eslint \"{src,scripts,test,@types}/**/*.ts\" --fix --quiet",
"lint:ci": "eslint \"{src,scripts,test,@types}/**/*.ts\" --fix-dry-run --quiet",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
Expand Down Expand Up @@ -138,8 +138,8 @@
"testEnvironment": "node"
},
"lint-staged": {
"*": [
"prettier --write --ignore-unknown"
"(src|scripts|test|@types)/**/*.(ts|js)": [
"eslint --fix --quiet"
]
},
"main": "dist/main.js",
Expand Down
8 changes: 7 additions & 1 deletion scripts/import-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ const escValue = (value: string | number): string => {
return value;
}

return "'" + ('' + value).replace(/'/g, "''") + "'";
if (typeof value === 'number') {
value = value.toString();
}

value = value.replace(/'/g, "''");

return `'${value}'`;
};

const insertTemplate = `INSERT INTO :table (:columns) values (:values);`;
Expand Down
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { CommandModule } from 'nestjs-command';
ConfigModule.forRoot({ validationSchema: configSchema }),
I18nModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
useFactory: (configService: ConfigService) => ({
fallbackLanguage: configService.get('NEST_LANG', 'bg'),
loaderOptions: {
path: path.join(__dirname, '/i18n/'),
Expand Down
6 changes: 5 additions & 1 deletion src/auth/auth-basic.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export class BasicStrategy extends PassportStrategy(Strategy) {
});
}

public validate = async (req, username, password): Promise<boolean> => {
public validate = async (
_: any,
username: string,
password: string,
): Promise<boolean> => {
if (
this.configService.get<string>('STREAMS_WEBHOOK_USERNAME') === username &&
this.configService.get<string>('STREAMS_WEBHOOK_PASSWORD') === password
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/translate-status.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TranslateStatusInterceptor implements NestInterceptor {
.replace('Dto', '')
.toUpperCase();
try {
object.statusLocalized = await this.i18n.translate(
object.statusLocalized = this.i18n.translate(
`status.${objectType}_${object.status.toUpperCase()}`,
{ lang },
);
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/entities/work-items.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class WorkItemsRepository {
.limit(200)
.orderBy('workItem.id', 'ASC');

return (await qb.getOneOrFail()) as WorkItem;
return await qb.getOneOrFail();
}

async findCompletedItems(): Promise<WorkItem[]> {
Expand Down
4 changes: 1 addition & 3 deletions src/results/api/results.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,7 @@ export class ResultsController {
section.results = (await this.sectionsRepo.getResultsFor(
section.id,
)) as number[];
section.protocols = (await this.protocolsRepo.findBySection(
section.id,
)) as Protocol[];
section.protocols = await this.protocolsRepo.findBySection(section.id);

return {
...sectionMapper(section),
Expand Down
13 changes: 8 additions & 5 deletions src/sections/entities/sections.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ export class SectionsRepository {
let violationsCountTown = 0;
stats.forEach((x) =>
Object.keys(x).includes('violationsCountTown')
? (violationsCountTown = parseInt(x.violationsCountTown))
? (violationsCountTown = parseInt(x.violationsCountTown, 10))
: (violationsCountTown = 0),
);
stats.forEach((x) =>
Object.keys(x).includes('violationsCount')
? (x.violationsCount =
parseInt(x.violationsCount) + violationsCountTown)
parseInt(x.violationsCount, 10) + violationsCountTown)
: x.violatinsCount,
);

Expand All @@ -227,9 +227,12 @@ export class SectionsRepository {
'violationsCountTown',
)
? (output[singleStat.segment].violationsCount =
parseInt(output[singleStat.segment].violationsCount) +
output[singleStat.segment].violationsCountTown)
: output[singleStat.segment].violationsCount;
parseInt(output[singleStat.segment].violationsCount, 10) +
parseInt(
output[singleStat.segment].violationsCountTown,
10,
))
: parseInt(output[singleStat.segment].violationsCount, 10);
});
delete singleStat.segment;
});
Expand Down
10 changes: 7 additions & 3 deletions src/users/api/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ export class UserDto {
groups: [UserDto.CREATE, UserDto.UPDATE],
message: 'USER_EMAIL_LENGTH',
})
@Transform(({ value: email }) => (email ? email.toLowerCase() : email), {
groups: [UserDto.CREATE, UserDto.UPDATE],
})
@Transform(
({ value: email }: { value: string }) =>
email ? email.toLowerCase() : email,
{
groups: [UserDto.CREATE, UserDto.UPDATE],
},
)
email: string;

@ApiProperty({ required: true })
Expand Down
7 changes: 5 additions & 2 deletions src/utils/csvToSql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ const createRecordsToInsertsTransformer = (
.replace(
':values',
Object.entries(record)
.map(([key, value]) => {
const str = ('' + value).trim();
.map(([key, value]: [string, string | number]) => {
if (typeof value === 'number') {
value = value.toString();
}
const str = value.trim();

return escValue(str.length > 0 ? str : emptyColumnCallback(key));
})
Expand Down

0 comments on commit 60ffa3c

Please sign in to comment.