Skip to content

Commit

Permalink
enhance(lint): Stylisticを追加 (@taiyme/eslint-config ベース) (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme authored Feb 10, 2025
1 parent 1dce650 commit bbab10a
Show file tree
Hide file tree
Showing 517 changed files with 4,415 additions and 3,968 deletions.
8 changes: 4 additions & 4 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"lib": ["dom", "es5"],
"target": "es5",
"types": ["cypress", "node"]
"lib": ["DOM", "ES5"],
"target": "ES5",
"types": ["cypress", "node"],
},
"include": ["./**/*.ts"]
"include": ["./**/*.ts"],
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
},
"devDependencies": {
"@misskey-dev/eslint-plugin": "2.0.3",
"@stylistic/eslint-plugin-js": "2.13.0",
"@stylistic/eslint-plugin-ts": "2.13.0",
"@types/node": "22.9.0",
"@typescript-eslint/eslint-plugin": "7.17.0",
"@typescript-eslint/parser": "7.17.0",
Expand Down
50 changes: 47 additions & 3 deletions packages/backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import tsParser from '@typescript-eslint/parser';
import globals from 'globals';
import sharedConfig from '../shared/eslint.config.js';

// eslint-disable-next-line import/no-default-export
export default [
...sharedConfig,
{
ignores: ['**/node_modules', 'built', '@types/**/*', 'migration'],
ignores: [
'built/',
'built-test/',
'migration/',
],
},
{
files: ['**/*.ts', '**/*.tsx'],
files: ['**/*.ts'],
languageOptions: {
parserOptions: {
parser: tsParser,
project: ['./tsconfig.json', './test/tsconfig.json', './test-federation/tsconfig.json'],
project: [
'./tsconfig.eslint.json',
'./test/tsconfig.eslint.json',
'./test-federation/tsconfig.eslint.json',
'./test-server/tsconfig.eslint.json',
],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},
Expand Down Expand Up @@ -44,4 +54,38 @@ export default [
}],
},
},
{
files: ['test/**/*.ts'],
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
},
},
{
files: ['test-federation/**/*.ts'],
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ['scripts/*.{js,mjs}'],
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ['src/server/web/*.js'],
languageOptions: {
globals: {
...Object.fromEntries(Object.entries(globals.node).map(([key]) => [key, 'off'])),
...globals.browser,
},
},
},
];
7 changes: 4 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"build": "swc src -d built -D --strip-leading-paths",
"build:test": "swc test-server -d built-test -D --config-file test-server/.swcrc --strip-leading-paths",
"watch:swc": "swc src -d built -D -w --strip-leading-paths",
"build:tsc": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
"build:tsc": "tsc && tsc-alias",
"watch": "node ./scripts/watch.mjs",
"restart": "pnpm build && pnpm start",
"dev": "node ./scripts/dev.mjs",
"typecheck": "tsc --noEmit && tsc -p test --noEmit && tsc -p test-federation --noEmit",
"eslint": "eslint --quiet \"{src,test-federation}/**/*.ts\"",
"typecheck": "tsc --noEmit && tsc --noEmit -p ./test/ && tsc --noEmit -p ./test-federation/",
"eslint": "eslint --quiet .",
"eslint:fix": "eslint --fix .",
"lint": "pnpm typecheck && pnpm eslint",
"jest": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --config jest.config.unit.cjs",
"jest:e2e": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --config jest.config.e2e.cjs",
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function execBuildAssets() {
cwd: '../../',
stdout: process.stdout,
stderr: process.stderr,
})
});
}

function execStart() {
Expand All @@ -23,7 +23,7 @@ function execStart() {
stdout: process.stdout,
stderr: process.stderr,
env: {
'NODE_ENV': 'development',
NODE_ENV: 'development',
},
});
}
Expand Down Expand Up @@ -59,5 +59,5 @@ async function killProc() {
await execBuildAssets();
execStart();
}
})
});
})();
24 changes: 12 additions & 12 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Source = {
user?: string;
pass?: string;
disableCache?: boolean;
extra?: { [x: string]: string };
extra?: { [x: string]: string; };
};
dbReplications?: boolean;
dbSlaves?: {
Expand All @@ -62,7 +62,7 @@ type Source = {
scope?: 'local' | 'global' | string[];
};
sentryForBackend?: { options: Partial<Sentry.NodeOptions>; enableNodeProfiling: boolean; };
sentryForFrontend?: { options: Partial<Sentry.NodeOptions> };
sentryForFrontend?: { options: Partial<Sentry.NodeOptions>; };

publishTarballInsteadOfProvideRepositoryUrl?: boolean;

Expand Down Expand Up @@ -105,10 +105,10 @@ type Source = {

logging?: {
sql?: {
disableQueryTruncation? : boolean,
enableQueryParamLogging? : boolean,
}
}
disableQueryTruncation?: boolean;
enableQueryParamLogging?: boolean;
};
};
};

export type Config = {
Expand All @@ -124,7 +124,7 @@ export type Config = {
user: string;
pass: string;
disableCache?: boolean;
extra?: { [x: string]: string };
extra?: { [x: string]: string; };
};
dbReplications: boolean | undefined;
dbSlaves: {
Expand Down Expand Up @@ -166,10 +166,10 @@ export type Config = {
signToActivityPubGet: boolean | undefined;
logging?: {
sql?: {
disableQueryTruncation? : boolean,
enableQueryParamLogging? : boolean,
}
}
disableQueryTruncation?: boolean;
enableQueryParamLogging?: boolean;
};
};

version: string;
publishTarballInsteadOfProvideRepositoryUrl: boolean;
Expand All @@ -196,7 +196,7 @@ export type Config = {
redisForTimelines: RedisOptions & RedisOptionsSource;
redisForReactions: RedisOptions & RedisOptionsSource;
sentryForBackend: { options: Partial<Sentry.NodeOptions>; enableNodeProfiling: boolean; } | undefined;
sentryForFrontend: { options: Partial<Sentry.NodeOptions> } | undefined;
sentryForFrontend: { options: Partial<Sentry.NodeOptions>; } | undefined;
perChannelMaxNoteCacheCount: number;
perUserNotificationsMaxCount: number;
deactivateAntennaThreshold: number;
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/src/core/AbuseReportNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
@bindThis
public async fetchRecipients(
params?: {
ids?: MiAbuseReportNotificationRecipient['id'][],
method?: RecipientMethod[],
ids?: MiAbuseReportNotificationRecipient['id'][];
method?: RecipientMethod[];
},
opts?: {
removeUnauthorized?: boolean,
joinUser?: boolean,
joinSystemWebhook?: boolean,
removeUnauthorized?: boolean;
joinUser?: boolean;
joinSystemWebhook?: boolean;
},
): Promise<MiAbuseReportNotificationRecipient[]> {
const query = this.abuseReportNotificationRecipientRepository.createQueryBuilder('recipient');
Expand Down Expand Up @@ -248,7 +248,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
*/
@bindThis
public async fetchEMailRecipients(opts?: {
removeUnauthorized?: boolean
removeUnauthorized?: boolean;
}): Promise<MiAbuseReportNotificationRecipient[]> {
return this.fetchRecipients({ method: ['email'] }, { joinUser: true, ...opts });
}
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/core/AbuseReportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export class AbuseReportService {
*/
@bindThis
public async report(params: {
targetUserId: MiAbuseUserReport['targetUserId'],
targetUserHost: MiAbuseUserReport['targetUserHost'],
reporterId: MiAbuseUserReport['reporterId'],
reporterHost: MiAbuseUserReport['reporterHost'],
comment: string,
targetUserId: MiAbuseUserReport['targetUserId'];
targetUserHost: MiAbuseUserReport['targetUserHost'];
reporterId: MiAbuseUserReport['reporterId'];
reporterHost: MiAbuseUserReport['reporterHost'];
comment: string;
}[]) {
const entities = params.map(param => {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/AnnouncementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export class AnnouncementService {
qb.orWhere('announcement.forExistingUsers = false');
qb.orWhere('announcement.id > :userId', { userId: user.id });
}))
.andWhere(`announcement.id NOT IN (${ readsQuery.getQuery() })`);
.andWhere(`announcement.id NOT IN (${readsQuery.getQuery()})`);

q.setParameters(readsQuery.getParameters());

return q.getMany();
}

@bindThis
public async create(values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
public async create(values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'>; }> {
const announcement = await this.announcementsRepository.insertOne({
id: this.idService.gen(),
updatedAt: null,
Expand Down
16 changes: 8 additions & 8 deletions packages/backend/src/core/CaptchaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ export type CaptchaSetting = {
hcaptcha: {
siteKey: string | null;
secretKey: string | null;
}
};
mcaptcha: {
siteKey: string | null;
secretKey: string | null;
instanceUrl: string | null;
}
};
recaptcha: {
siteKey: string | null;
secretKey: string | null;
}
};
turnstile: {
siteKey: string | null;
secretKey: string | null;
}
}
};
};

export class CaptchaError extends Error {
public readonly code: CaptchaErrorCode;
Expand All @@ -59,11 +59,11 @@ export class CaptchaError extends Error {

export type CaptchaSaveSuccess = {
success: true;
}
};
export type CaptchaSaveFailure = {
success: false;
error: CaptchaError;
}
};
export type CaptchaSaveResult = CaptchaSaveSuccess | CaptchaSaveFailure;

type CaptchaResponse = {
Expand Down Expand Up @@ -161,7 +161,7 @@ export class CaptchaService {
throw new CaptchaError(captchaErrorCodes.requestFailed, 'mcaptcha-failed: mcaptcha didn\'t return 200 OK');
}

const resp = (await result.json()) as { valid: boolean };
const resp = (await result.json()) as { valid: boolean; };

if (!resp.valid) {
throw new CaptchaError(captchaErrorCodes.verificationFailed, 'mcaptcha-request-failed');
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class CustomEmojiService implements OnApplicationShutdown {

@bindThis
public async update(data: (
{ id: MiEmoji['id'], name?: string; } | { name: string; id?: MiEmoji['id'], }
{ id: MiEmoji['id']; name?: string; } | { name: string; id?: MiEmoji['id']; }
) & {
originalUrl?: string;
publicUrl?: string;
Expand Down Expand Up @@ -469,14 +469,14 @@ export class CustomEmojiService implements OnApplicationShutdown {
localOnly?: boolean;
hostType?: FetchEmojisHostTypes;
roleIds?: string[];
},
};
sinceId?: string;
untilId?: string;
},
opts?: {
limit?: number;
page?: number;
sortKeys?: FetchEmojisSortKeys[]
sortKeys?: FetchEmojisSortKeys[];
},
) {
function multipleWordsToQuery(words: string) {
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { UtilityService } from '@/core/UtilityService.js';

type AddFileArgs = {
/** User who wish to add file */
user: { id: MiUser['id']; host: MiUser['host'] } | null;
user: { id: MiUser['id']; host: MiUser['host']; } | null;
/** File path */
path: string;
/** Name */
Expand Down Expand Up @@ -74,7 +74,7 @@ type AddFileArgs = {

type UploadFromUrlArgs = {
url: string;
user: { id: MiUser['id']; host: MiUser['host'] } | null;
user: { id: MiUser['id']; host: MiUser['host']; } | null;
folderId?: MiDriveFolder['id'] | null;
uri?: string | null;
sensitive?: boolean;
Expand Down Expand Up @@ -170,11 +170,11 @@ export class DriveService {
}

const baseUrl = this.meta.objectStorageBaseUrl
?? `${ this.meta.objectStorageUseSSL ? 'https' : 'http' }://${ this.meta.objectStorageEndpoint }${ this.meta.objectStoragePort ? `:${this.meta.objectStoragePort}` : '' }/${ this.meta.objectStorageBucket }`;
?? `${this.meta.objectStorageUseSSL ? 'https' : 'http'}://${this.meta.objectStorageEndpoint}${this.meta.objectStoragePort ? `:${this.meta.objectStoragePort}` : ''}/${this.meta.objectStorageBucket}`;

// for original
const key = `${this.meta.objectStoragePrefix}/${randomUUID()}${ext}`;
const url = `${ baseUrl }/${ key }`;
const url = `${baseUrl}/${key}`;

// for alts
let webpublicKey: string | null = null;
Expand All @@ -191,15 +191,15 @@ export class DriveService {

if (alts.webpublic) {
webpublicKey = `${this.meta.objectStoragePrefix}/webpublic-${randomUUID()}.${alts.webpublic.ext}`;
webpublicUrl = `${ baseUrl }/${ webpublicKey }`;
webpublicUrl = `${baseUrl}/${webpublicKey}`;

this.registerLogger.info(`uploading webpublic: ${webpublicKey}`);
uploads.push(this.upload(webpublicKey, alts.webpublic.data, alts.webpublic.type, alts.webpublic.ext, name));
}

if (alts.thumbnail) {
thumbnailKey = `${this.meta.objectStoragePrefix}/thumbnail-${randomUUID()}.${alts.thumbnail.ext}`;
thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`;
thumbnailUrl = `${baseUrl}/${thumbnailKey}`;

this.registerLogger.info(`uploading thumbnail: ${thumbnailKey}`);
uploads.push(this.upload(thumbnailKey, alts.thumbnail.data, alts.thumbnail.type, alts.thumbnail.ext, `${name}.thumbnail`));
Expand Down
Loading

0 comments on commit bbab10a

Please sign in to comment.