Skip to content

Commit

Permalink
chore: Fix eslint (#304)
Browse files Browse the repository at this point in the history
* chore: dedupe lang folder

* chore: remove unused directory

* chore: fix i18n ci

* ci: extract i18n messages

* fix: ignore enquening empty array

This fix removes unnecessary work and reduces spam log

* chore: sync with main

* ci: extract i18n messages

* chore: move lang files to root

* chore: run lint

* chore: fix lint problems

* chore: remove unused dependency

* ci: extract i18n messages

* fix: invalid date error

* ci: extract i18n messages

* chore(deps): update prettier to v3

* chore: run prettier -w apps libs

* chore(deps): upgrade eslint-plugin-prettier

* chore: do not delete messages

---------

Co-authored-by: leaftail1880 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent ac4d7aa commit a2c1454
Show file tree
Hide file tree
Showing 189 changed files with 845 additions and 772 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @ts-check
const { defineConfig } = require('eslint-define-config');

// Disable this annoying red lines under unformatted code
// if there is prettier extensions installed
let prettierExtension = process.env.VSCODE_CWD;

module.exports = defineConfig({
module.exports = {
root: true,
ignorePatterns: ['**/*'],
extends: [
Expand Down Expand Up @@ -103,4 +102,4 @@ module.exports = defineConfig({
},
],
},
});
};
2 changes: 1 addition & 1 deletion apps/client-server/src/app/account/account.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('AccountsService', () => {

service = module.get<AccountService>(AccountService);
registryService = module.get<WebsiteRegistryService>(
WebsiteRegistryService
WebsiteRegistryService,
);
orm = module.get(MikroORM);
try {
Expand Down
14 changes: 7 additions & 7 deletions apps/client-server/src/app/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class AccountService
@InjectRepository(Account)
repository: PostyBirbRepository<Account>,
private readonly websiteRegistry: WebsiteRegistryService,
@Optional() webSocket?: WSGateway
@Optional() webSocket?: WSGateway,
) {
super(repository, webSocket);
repository.addUpdateListener(dbSubscriber, [Account], () => this.emit());
Expand All @@ -66,7 +66,7 @@ export class AccountService
this.emit();

Object.keys(this.loginRefreshTimers).forEach((interval) =>
this.executeOnLoginForInterval(interval)
this.executeOnLoginForInterval(interval),
);
}

Expand All @@ -76,7 +76,7 @@ export class AccountService
private async populateNullAccount(): Promise<void> {
if (!(await this.repository.findById(NULL_ACCOUNT_ID))) {
await this.repository.persistAndFlush(
this.repository.create(new NullAccount())
this.repository.create(new NullAccount()),
);
}
}
Expand All @@ -89,7 +89,7 @@ export class AccountService
id: { $ne: NULL_ACCOUNT_ID },
});
await Promise.all(
accounts.map((account) => this.websiteRegistry.create(account))
accounts.map((account) => this.websiteRegistry.create(account)),
).catch((err) => {
this.logger.error(err, 'onModuleInit');
});
Expand Down Expand Up @@ -119,7 +119,7 @@ export class AccountService

protected async emit() {
const dtos = await this.findAll().then((results) =>
results.map((account) => account.toJSON())
results.map((account) => account.toJSON()),
);
super.emit({
event: ACCOUNT_UPDATES,
Expand Down Expand Up @@ -212,7 +212,7 @@ export class AccountService
.info(`Creating Account '${createDto.name}:${createDto.website}`);
if (!this.websiteRegistry.canCreate(createDto.website)) {
throw new BadRequestException(
`Website ${createDto.website} is not supported.`
`Website ${createDto.website} is not supported.`,
);
}
const account = this.repository.create(createDto);
Expand Down Expand Up @@ -298,7 +298,7 @@ export class AccountService
async setAccountData(setWebsiteDataRequestDto: SetWebsiteDataRequestDto) {
const account = await this.repository.findById(
setWebsiteDataRequestDto.id,
{ failOnMissing: true }
{ failOnMissing: true },
);
const instance = this.websiteRegistry.findInstance(account);
await instance.setWebsiteData(setWebsiteDataRequestDto.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class PostyBirbController<T extends PostyBirbEntity> {
})
async remove(@Query('ids') ids: string | string[]) {
return Promise.all(
(Array.isArray(ids) ? ids : [ids]).map((id) => this.service.remove(id))
(Array.isArray(ids) ? ids : [ids]).map((id) => this.service.remove(id)),
).then(() => ({
success: true,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface OnDatabaseQuery<T extends PostyBirbEntity> {

export function isOnDatabaseQuery(
// eslint-disable-next-line @typescript-eslint/ban-types
thisService: Object
thisService: Object,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): thisService is OnDatabaseQuery<any> {
return 'getDefaultQueryOptions' in thisService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface OnDatabaseUpdate {

export function isOnDatabaseUpdate(
// eslint-disable-next-line @typescript-eslint/ban-types
thisService: Object
thisService: Object,
): thisService is OnDatabaseUpdate {
return 'getRegisteredEntities' in thisService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { WebSocketEvents } from '../../web-socket/web-socket.events';
*/
@Injectable()
export abstract class PostyBirbService<
T extends PostyBirbEntity = PostyBirbEntity
T extends PostyBirbEntity = PostyBirbEntity,
> {
protected readonly logger = Logger();

constructor(
protected readonly repository: PostyBirbRepository<T>,
private readonly webSocket?: WSGateway
private readonly webSocket?: WSGateway,
) {}

/**
Expand All @@ -47,7 +47,7 @@ export abstract class PostyBirbService<
const exists = await this.repository.findOne(where);
if (exists) {
const err = new BadRequestException(
`An entity with query '${JSON.stringify(where)}' already exists`
`An entity with query '${JSON.stringify(where)}' already exists`,
);
this.logger.withError(err).error();
throw err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Account extends PostyBirbEntity implements IAccount {
hidden: true,
})
userSpecifiedWebsiteOptions = new Collection<UserSpecifiedWebsiteOptions>(
this
this,
);

@OneToMany(() => WebsitePostRecord, (wpr) => wpr.account, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class PostRecord extends PostyBirbEntity implements IPostRecord {
postRecord: Pick<
IPostRecord,
'parent' | 'completedAt' | 'state' | 'resumeMode'
>
>,
) {
super();
this.parent = postRecord.parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Submission<T extends ISubmissionMetadata = ISubmissionMetadata>
eager: true,
})
options = new Collection<WebsiteOptions<IWebsiteFormFields>, ISubmission<T>>(
this
this,
);

@OneToMany(() => SubmissionFile, (sf) => sf.submission, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export type FindOptions = {
};

export class PostyBirbRepository<
T extends IEntity
T extends IEntity,
> extends EntityRepository<T> {
private emitter = new EventEmitter();

public addUpdateListener(
subscriber: DatabaseUpdateSubscriber,
types: Constructor<PostyBirbEntity>[],
fn: (change: EntityUpdateRecord<SubscribableEntities>[]) => void
fn: (change: EntityUpdateRecord<SubscribableEntities>[]) => void,
) {
subscriber.subscribe(types, (updates) => {
this.emitter.emit('change', updates);
Expand All @@ -46,7 +46,7 @@ export class PostyBirbRepository<

on<K extends EventKey<EventMap>>(
eventName: K,
fn: EventReceiver<EventMap[K]>
fn: EventReceiver<EventMap[K]>,
) {
this.emitter.on(eventName, fn);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type SubscribableEntities = PostyBirbEntity;

export type EntityUpdateRecord<T = SubscribableEntities> = [ChangeSetType, T];
export type OnDatabaseUpdateCallback<T = SubscribableEntities> = (
updates: EntityUpdateRecord<T>[]
updates: EntityUpdateRecord<T>[],
) => void;

const registeredListeners: Map<
Expand All @@ -38,7 +38,7 @@ export class DatabaseUpdateSubscriber

async afterFlush(event: FlushEventArgs): Promise<void> {
this.publish(
event.uow.getChangeSets() as unknown as ChangeSet<SubscribableEntities>[]
event.uow.getChangeSets() as unknown as ChangeSet<SubscribableEntities>[],
);
}

Expand All @@ -50,7 +50,7 @@ export class DatabaseUpdateSubscriber
*/
public subscribe(
entities: Constructor<SubscribableEntities>[],
func: OnDatabaseUpdateCallback
func: OnDatabaseUpdateCallback,
): void {
entities.forEach((entity) => {
if (!registeredListeners.has(entity)) {
Expand Down Expand Up @@ -85,11 +85,11 @@ export class DatabaseUpdateSubscriber

if (
!seen.includes(
`${proto.constructor}:${change.type}:${change.entity.id}`
`${proto.constructor}:${change.type}:${change.entity.id}`,
)
)
seen.push(
`${proto.constructor}:${change.type}:${change.entity.id}`
`${proto.constructor}:${change.type}:${change.entity.id}`,
);
callbacks.set(cb, [
...callbacks.get(cb),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DirectoryWatchersController extends PostyBirbController<DirectoryWa
@ApiNotFoundResponse({ description: 'Entity not found.' })
update(
@Body() updateDto: UpdateDirectoryWatcherDto,
@Param('id') id: string
@Param('id') id: string,
) {
return this.service.update(id, updateDto).then((entity) => entity.toJSON());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DirectoryWatchersService extends PostyBirbService<DirectoryWatcher>
@InjectRepository(DirectoryWatcher)
repository: PostyBirbRepository<DirectoryWatcher>,
private readonly submissionService: SubmissionService,
@Optional() webSocket?: WSGateway
@Optional() webSocket?: WSGateway,
) {
super(repository, webSocket);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class DirectoryWatchersService extends PostyBirbService<DirectoryWatcher>
this.logger
.withError(err)
.error(`Failed to update metadata for '${metaFileName}'`);
}
},
);
} catch (e) {
this.logger.error(e, `Failed to read directory ${watcher.path}`);
Expand All @@ -90,11 +90,11 @@ export class DirectoryWatchersService extends PostyBirbService<DirectoryWatcher>
* @returns {Promise<WatcherMetadata>}
*/
private async getMetadata(
watcher: DirectoryWatcher
watcher: DirectoryWatcher,
): Promise<WatcherMetadata> {
try {
const metadata = JSON.parse(
(await readFile(join(watcher.path, 'pb-meta.json'))).toString()
(await readFile(join(watcher.path, 'pb-meta.json'))).toString(),
) as WatcherMetadata;
if (!metadata.read) {
metadata.read = []; // protect user modification
Expand Down Expand Up @@ -134,13 +134,13 @@ export class DirectoryWatchersService extends PostyBirbService<DirectoryWatcher>
name: fileName,
type: SubmissionType.FILE,
},
multerInfo
multerInfo,
);
submissionId = submission.id;
if (watcher.template) {
await this.submissionService.applyOverridingTemplate(
submission.id,
watcher.template?.id
watcher.template?.id,
);
}
break;
Expand All @@ -159,7 +159,7 @@ export class DirectoryWatchersService extends PostyBirbService<DirectoryWatcher>
}

async create(
createDto: CreateDirectoryWatcherDto
createDto: CreateDirectoryWatcherDto,
): Promise<DirectoryWatcher> {
const entity = this.repository.create(createDto);
await this.repository.persistAndFlush(entity);
Expand Down
10 changes: 5 additions & 5 deletions apps/client-server/src/app/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FileService {
private readonly createFileService: CreateFileService,
private readonly updateFileService: UpdateFileService,
@InjectRepository(SubmissionFile)
private readonly fileRepository: PostyBirbRepository<SubmissionFile>
private readonly fileRepository: PostyBirbRepository<SubmissionFile>,
) {}

/**
Expand All @@ -45,7 +45,7 @@ export class FileService {
public async remove(id: string) {
this.logger.info(id, `Removing entity '${id}'`);
return this.fileRepository.removeAndFlush(
await this.fileRepository.findById(id)
await this.fileRepository.findById(id),
);
}

Expand All @@ -58,7 +58,7 @@ export class FileService {
*/
public async create(
file: MulterFileInfo,
submission: FileSubmission
submission: FileSubmission,
): Promise<SubmissionFile> {
return this.queue.push({ type: TaskType.CREATE, file, submission });
}
Expand All @@ -73,7 +73,7 @@ export class FileService {
public async update(
file: MulterFileInfo,
submissionFileId: string,
forThumbnail: boolean
forThumbnail: boolean,
): Promise<SubmissionFile> {
return this.queue.push({
type: TaskType.UPDATE,
Expand All @@ -99,7 +99,7 @@ export class FileService {
ut.file,
ut.submissionFileId,
buf,
ut.target
ut.target,
);
default:
throw new BadRequestException(`Unknown TaskType '${task.type}'`);
Expand Down
Loading

0 comments on commit a2c1454

Please sign in to comment.