Skip to content

Commit

Permalink
chore: 更新eslint 9并修复大量代码风格错误 (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal authored Jul 7, 2024
1 parent cd8efd3 commit bf32e8d
Show file tree
Hide file tree
Showing 217 changed files with 2,100 additions and 1,737 deletions.
15 changes: 0 additions & 15 deletions .eslintignore

This file was deleted.

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

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/test-build-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
- name: Install dependencies
run: pnpm i --frozen-lockfile

- name: Prepare dev libs and code
run: pnpm prepareDev

- name: Lint code
run: pnpm lint

Expand All @@ -60,10 +63,6 @@ jobs:
if: vars.RUN_TESTS == 'true'
run: docker ps

- name: Prepare dev libs and code
if: vars.RUN_TESTS == 'true' || vars.RUN_RELEASE == 'true'
run: pnpm prepareDev

- name: Wait for ports
if: vars.RUN_TESTS == 'true'
uses: ifaxity/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"cSpell.words": [
"trpc"
],
"jest.runMode": "on-demand",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
Expand Down
15 changes: 0 additions & 15 deletions apps/ai/.eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions apps/ai/.eslintrc.json

This file was deleted.

7 changes: 7 additions & 0 deletions apps/ai/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const base = require("../../eslint.config");
const react = require("@ddadaal/eslint-config/react");

module.export = {
...base,
...react,
};
3 changes: 2 additions & 1 deletion apps/ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build:ts": "rimraf build && tsc -p tsconfig.server.json && tsc-alias -p tsconfig.server.json",
"orm": "dotenv -e env/.env.dev -- npx mikro-orm",
"ormCreate": "dotenv -e env/.env.dev -- npx mikro-orm migration:create",
"ormUp": "dotenv -e env/.env.dev -- npx mikro-orm migration:up"
"ormUp": "dotenv -e env/.env.dev -- npx mikro-orm migration:up",
"lint": "eslint ."
},
"mikro-orm": {
"useTsNode": true,
Expand Down
3 changes: 2 additions & 1 deletion apps/audit-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "rimraf build && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"serve": "node build/index.js",
"test": "jest",
"orm": "dotenv -e env/.env.dev -- npx mikro-orm"
"orm": "dotenv -e env/.env.dev -- npx mikro-orm",
"lint": "eslint -c ../../eslint.config.js ."
},
"files": [
"scripts",
Expand Down
30 changes: 15 additions & 15 deletions apps/audit-server/src/entities/OperationLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@ export enum OperationResult {
export class OperationLog {

@PrimaryKey()
id!: number;
id!: number;

@Property()
operatorUserId!: string;
operatorUserId!: string;

@Property()
operatorIp!: string;
operatorIp!: string;

@Property({ columnType: DATETIME_TYPE, defaultRaw: CURRENT_TIMESTAMP })
operationTime?: Date;
operationTime?: Date;

@Enum({ items: () => OperationResult, comment: Object.values(OperationResult).join(", ") })
operationResult: OperationResult;
operationResult: OperationResult;

@Property({ type: "json", nullable: true })
metaData?: OperationEvent & { targetAccountName?: string };
metaData?: OperationEvent & { targetAccountName?: string };

// 用户自定义操作类型
@Index({ name: "custom_event" })
@Property({ nullable: true })
customEventType?: string;
customEventType?: string;

constructor(init: {
operationLogId?: number;
operatorUserId: string;
operatorIp: string;
operationTime?: Date;
operationResult: OperationResult;
metaData: OperationEvent & { targetAccountName?: string };
customEventType?: string;
}) {
operationLogId?: number;
operatorUserId: string;
operatorIp: string;
operationTime?: Date;
operationResult: OperationResult;
metaData: OperationEvent & { targetAccountName?: string };
customEventType?: string;
}) {
if (init.operationLogId) {
this.id = init.operationLogId;
}
Expand Down
14 changes: 7 additions & 7 deletions apps/audit-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ async function main() {

switch (command) {

case "migrationUp":
await migrationUp(server.ext.orm);
break;
default:
logger.error("Unexpected task name %s", command);
process.exit(1);
case "migrationUp":
await migrationUp(server.ext.orm);
break;
default:
logger.error("Unexpected task name %s", command);
process.exit(1);
}

process.exit(0);
Expand All @@ -41,4 +41,4 @@ async function main() {
await server.start();
}

main();
void main();
20 changes: 17 additions & 3 deletions apps/audit-server/src/migrations/Migration20230817054947.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { Migration } from '@mikro-orm/migrations';
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

/* eslint-disable @stylistic/max-len */

import { Migration } from "@mikro-orm/migrations";

export class Migration20230817054947 extends Migration {

async up(): Promise<void> {
this.addSql('create table `operation_log` (`id` int unsigned not null auto_increment primary key, `operator_user_id` varchar(255) not null, `operator_ip` varchar(255) not null, `operation_time` DATETIME(6) not null default current_timestamp(6), `operation_result` enum(\'UNKNOWN\', \'SUCCESS\', \'FAIL\') not null comment \'UNKNOWN, SUCCESS, FAIL\', `meta_data` json null) default character set utf8mb4 engine = InnoDB;');
this.addSql("create table `operation_log` (`id` int unsigned not null auto_increment primary key, `operator_user_id` varchar(255) not null, `operator_ip` varchar(255) not null, `operation_time` DATETIME(6) not null default current_timestamp(6), `operation_result` enum('UNKNOWN', 'SUCCESS', 'FAIL') not null comment 'UNKNOWN, SUCCESS, FAIL', `meta_data` json null) default character set utf8mb4 engine = InnoDB;");
}

async down(): Promise<void> {
this.addSql('drop table if exists `operation_log`;');
this.addSql("drop table if exists `operation_log`;");
}

}
14 changes: 14 additions & 0 deletions apps/audit-server/src/migrations/Migration20240218000000.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

/* eslint-disable @stylistic/max-len */

import { Migration } from "@mikro-orm/migrations";

export class Migration20240129000000 extends Migration {
Expand Down
28 changes: 21 additions & 7 deletions apps/audit-server/src/migrations/Migration20240313015230.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import { Migration } from '@mikro-orm/migrations';
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

/* eslint-disable @stylistic/max-len */

import { Migration } from "@mikro-orm/migrations";

export class Migration20240313015230 extends Migration {

async up(): Promise<void> {
this.addSql('alter table `operation_log` add `custom_event_type` varchar(255) null;');
this.addSql('alter table `operation_log` modify `operation_time` DATETIME(6) not null default current_timestamp(6), modify `operation_result` enum(\'UNKNOWN\', \'SUCCESS\', \'FAIL\') not null comment \'UNKNOWN, SUCCESS, FAIL\';');
this.addSql('alter table `operation_log` add index `custom_event`(`custom_event_type`);');
this.addSql("alter table `operation_log` add `custom_event_type` varchar(255) null;");
this.addSql("alter table `operation_log` modify `operation_time` DATETIME(6) not null default current_timestamp(6), modify `operation_result` enum('UNKNOWN', 'SUCCESS', 'FAIL') not null comment 'UNKNOWN, SUCCESS, FAIL';");
this.addSql("alter table `operation_log` add index `custom_event`(`custom_event_type`);");
}

async down(): Promise<void> {
this.addSql('alter table `operation_log` drop index `custom_event`;');
this.addSql('alter table `operation_log` drop column `custom_event_type`;');
this.addSql("alter table `operation_log` drop index `custom_event`;");
this.addSql("alter table `operation_log` drop column `custom_event_type`;");

this.addSql('alter table `operation_log` modify `operation_time` DATETIME(6) not null default current_timestamp(0), modify `operation_result` enum(\'UNKNOWN\', \'SUCCESS\', \'FAIL\') not null comment \'UNKNOWN, SUCCESS, FAIL\';');
this.addSql("alter table `operation_log` modify `operation_time` DATETIME(6) not null default current_timestamp(0), modify `operation_result` enum('UNKNOWN', 'SUCCESS', 'FAIL') not null comment 'UNKNOWN, SUCCESS, FAIL';");
}

}
17 changes: 9 additions & 8 deletions apps/audit-server/src/services/operationLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,18 @@ export const operationLogServiceServer = plugin((server) => {
data.push(row);
writeTotal += 1;
if (data.length === 200 || writeTotal === addAccountNamesRecords.length) {
await new Promise(async (resolve) => {
await writeAsync({ operationLogs: data });
// 清空暂存
data = [];
resolve("done");
await new Promise((resolve) => {
void writeAsync({ operationLogs: data }).then(() => {
// 清空暂存
data = [];
resolve("done");
});
}).catch((e) => {
throw <ServiceError>{
throw {
code: status.INTERNAL,
message: "Error when exporting file",
details: e?.message,
};
} as ServiceError;
});
}
}
Expand All @@ -144,7 +145,7 @@ export const operationLogServiceServer = plugin((server) => {
getCustomEventTypes: async ({ em }) => {

const qb = em.createQueryBuilder(OperationLog, "o");
qb
void qb
.select([
raw("DISTINCT o.custom_event_type as customType"),
raw("JSON_UNQUOTE(JSON_EXTRACT(meta_data, '$.customEvent.name')) AS name"),
Expand Down
12 changes: 6 additions & 6 deletions apps/audit-server/src/services/statistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const statisticServiceServer = plugin((server) => {
checkTimeZone(timeZone);

const qb = em.createQueryBuilder(OperationLog, "o");
qb
void qb
.select([
raw("DATE(CONVERT_TZ(o.operation_time, 'UTC', ?)) as date", [timeZone]),
raw("COUNT(DISTINCT o.operator_user_id) as userCount"),
Expand All @@ -39,7 +39,7 @@ export const statisticServiceServer = plugin((server) => {
.groupBy(raw("date"))
.orderBy({ [raw("date")]: QueryOrder.DESC });

const records: {date: string, userCount: number}[] = await qb.execute();
const records: { date: string, userCount: number }[] = await qb.execute();

return [{
results: records.map((record) => ({
Expand Down Expand Up @@ -72,15 +72,15 @@ export const statisticServiceServer = plugin((server) => {
];

const qb = em.createQueryBuilder(OperationLog, "o");
qb
void qb
.select([raw("JSON_EXTRACT(meta_data, '$.$case') as operationType"), raw("COUNT(*) as count")])
.where({ operationTime: { $gte: startTime } })
.andWhere({ operationTime: { $lte: endTime } })
.andWhere({ [raw("JSON_EXTRACT(meta_data, '$.$case')")]: { $in: portalOperationType } })
.groupBy(raw("operationType"))
.orderBy({ [raw("count")]: QueryOrder.DESC });

const results: {operationType: string, count: number}[] = await qb.execute();
const results: { operationType: string, count: number }[] = await qb.execute();

return [{
results,
Expand Down Expand Up @@ -133,15 +133,15 @@ export const statisticServiceServer = plugin((server) => {
];

const qb = em.createQueryBuilder(OperationLog, "o");
qb
void qb
.select([raw("JSON_EXTRACT(meta_data, '$.$case') as operationType"), raw("COUNT(*) as count")])
.where({ operationTime: { $gte: startTime } })
.andWhere({ operationTime: { $lte: endTime } })
.andWhere({ [raw("JSON_EXTRACT(meta_data, '$.$case')")]: { $in: misOperationType } })
.groupBy(raw("operationType"))
.orderBy({ [raw("count")]: QueryOrder.DESC });

const results: {operationType: string, count: number}[] = await qb.execute();
const results: { operationType: string, count: number }[] = await qb.execute();

return [{
results,
Expand Down
Loading

0 comments on commit bf32e8d

Please sign in to comment.