Skip to content

Commit

Permalink
Merge pull request #1340 from Nowadays/main
Browse files Browse the repository at this point in the history
chore: migrate to eslint flat package to support eslint V9
  • Loading branch information
benscobie authored Nov 10, 2024
2 parents ef8a333 + 149dc78 commit 29d3e10
Show file tree
Hide file tree
Showing 28 changed files with 154 additions and 132 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data/
docs-output/
node_modules
.yarn
.yarn
.idea
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"start:ui": "cd ui && next start -p 80",
"start:server": "cd server && node dist/main",
"lint:ui": "cd ui && next lint",
"lint:server": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint:server": "cd server && eslint \"{src,test}/**/*.ts\" --fix",
"test": "jest",
"test:clear": "jest --clearCache",
"test:watch": "jest --watch",
Expand Down Expand Up @@ -74,6 +74,8 @@
"devDependencies": {
"@automock/jest": "^1.4.0",
"@babel/core": "^7.26.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.4",
Expand Down
31 changes: 0 additions & 31 deletions server/.eslintrc.js

This file was deleted.

55 changes: 55 additions & 0 deletions server/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import typescriptEslintEslintPlugin from "@typescript-eslint/eslint-plugin";
import globals from "globals";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["**/eslint.config.mjs"],
}, ...compat.extends("plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"), {
plugins: {
"@typescript-eslint": typescriptEslintEslintPlugin,
},

languageOptions: {
globals: {
...globals.node,
...globals.jest,
},

parser: tsParser,
ecmaVersion: 5,
sourceType: "module",

parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: ".",
},
},

rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
caughtErrors: "none"
}
],
"prettier/prettier": ["error", {
endOfLine: "auto",
}],
},
}];
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export class UpdateTautulliURL1728503476668 implements MigrationInterface {
);
}

public async down(queryRunner: QueryRunner): Promise<void> {}
public async down(): Promise<void> {}
}
2 changes: 1 addition & 1 deletion server/src/modules/api/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CacheManager {
}

public flushAll(): void {
for (const [key, value] of Object.entries(this.getAllCaches())) {
for (const [, value] of Object.entries(this.getAllCaches())) {
value.flush();
}
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/modules/api/lib/plexApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ class PlexApi extends NodePlexAPI {
}
}

deleteQuery<T>(arg) {
deleteQuery(arg) {
return super.deleteQuery(arg);
}
postQuery<T>(arg) {
postQuery(arg) {
return super.postQuery(arg);
}
putQuery<T>(arg) {
putQuery(arg) {
return super.putQuery(arg);
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/modules/api/overseerr-api/overseerr-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ export class OverseerrApiService {
let hasNext = true;
let skip = 0;

let users: OverseerrUserResponseResult[] = [];
const users: OverseerrUserResponseResult[] = [];

while (hasNext) {
let resp: OverseerrUserResponse = await this.api.get(
const resp: OverseerrUserResponse = await this.api.get(
`/user?take=${size}&skip=${skip}`,
);

Expand Down
67 changes: 35 additions & 32 deletions server/src/modules/api/plex-api/plex-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
import { PlexSettings } from '../../../modules/settings/interfaces/plex-settings.interface';
import { SettingsService } from '../../..//modules/settings/settings.service';
import { PlexSettings } from '../../settings/interfaces/plex-settings.interface';
import { SettingsService } from '../../settings/settings.service';
import { BasicResponseDto } from './dto/basic-response.dto';
import { CollectionHubSettingsDto } from './dto/collection-hub-settings.dto';
import {
Expand Down Expand Up @@ -35,7 +35,6 @@ import PlexTvApi, { PlexUser } from '../lib/plextvApi';
import cacheManager from '../../api/lib/cache';
import { Settings } from '../../settings/entities/settings.entities';
import PlexCommunityApi, {
GraphQLQuery,
PlexCommunityWatchHistory,
PlexCommunityWatchList,
} from '../../api/lib/plexCommunityApi';
Expand All @@ -47,6 +46,7 @@ export class PlexApiService {
private plexCommunityClient: PlexCommunityApi;
private machineId: string;
private readonly logger = new Logger(PlexApiService.name);

constructor(
@Inject(forwardRef(() => SettingsService))
private readonly settings: SettingsService,
Expand All @@ -73,6 +73,7 @@ export class PlexApiService {
webAppUrl: this.settings.plex_hostname,
};
}

public async initialize({
plexToken,
timeout,
Expand Down Expand Up @@ -153,15 +154,17 @@ export class PlexApiService {
}),
)
: [];
const fileteredResults: PlexMetadata[] = [];
const filteredResults: PlexMetadata[] = [];
(await results).forEach((el: PlexMetadata) => {
fileteredResults.find(
(e: PlexMetadata) => e.ratingKey === el.ratingKey,
) === undefined
? fileteredResults.push(el)
: undefined;
if (
filteredResults.find(
(e: PlexMetadata) => e.ratingKey === el.ratingKey,
) === undefined
) {
filteredResults.push(el);
}
});
return fileteredResults;
return filteredResults;
} catch (err) {
this.logger.warn(
'Plex api communication failure.. Is the application running?',
Expand Down Expand Up @@ -444,7 +447,7 @@ export class PlexApiService {
`[Plex] Removed media with ID ${plexId} from Plex library.`,
);
try {
await this.plexClient.deleteQuery<void>({
await this.plexClient.deleteQuery({
uri: `/library/metadata/${plexId}`,
});
} catch (e) {
Expand Down Expand Up @@ -480,7 +483,7 @@ export class PlexApiService {

public async createCollection(params: CreateUpdateCollection) {
try {
const response = await this.plexClient.postQuery<PlexLibraryResponse>({
const response = await this.plexClient.postQuery({
uri: `/library/collections?type=${
params.type
}&title=${encodeURIComponent(params.title)}&sectionId=${
Expand All @@ -505,7 +508,7 @@ export class PlexApiService {

public async updateCollection(body: CreateUpdateCollection) {
try {
await this.plexClient.putQuery<PlexLibraryResponse>({
await this.plexClient.putQuery({
uri: `/library/sections/${body.libraryId}/all?type=18&id=${
body.collectionId
}&title.value=${encodeURIComponent(
Expand All @@ -527,7 +530,7 @@ export class PlexApiService {
collectionId: string,
): Promise<BasicResponseDto> {
try {
await this.plexClient.deleteQuery<PlexLibraryResponse>({
await this.plexClient.deleteQuery({
uri: `/library/collections/${collectionId}`,
});
} catch (err) {
Expand Down Expand Up @@ -955,15 +958,15 @@ export class PlexApiService {
const data = await this.getChildrenMetadata(context.id.toString());

// transform & add eps
data
? handleMedia.push(
...data.map((el) => {
return {
plexId: +el.ratingKey,
};
}),
)
: undefined;
if (data) {
handleMedia.push(
...data.map((el) => {
return {
plexId: +el.ratingKey,
};
}),
);
}
break;
case EPlexDataType.EPISODES:
// transform & push episode
Expand Down Expand Up @@ -993,15 +996,15 @@ export class PlexApiService {
season.ratingKey.toString(),
);
// transform & add eps
eps
? handleMedia.push(
...eps.map((el) => {
return {
plexId: +el.ratingKey,
};
}),
)
: undefined;
if (eps) {
handleMedia.push(
...eps.map((el) => {
return {
plexId: +el.ratingKey,
};
}),
);
}
}
break;
case EPlexDataType.MOVIES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface Response<T> {
| {
message: string | null;
result: 'error';
data: {};
data: object;
};
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/modules/api/tmdb-api/tmdb-id.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class TmdbIdService {
libItem.grandparentRatingKey.toString(),
)
: libItem.parentRatingKey
? await this.plexApi.getMetadata(libItem.parentRatingKey.toString())
: libItem;
? await this.plexApi.getMetadata(libItem.parentRatingKey.toString())
: libItem;

return this.getTmdbIdFromPlexData(libItem);
} else {
Expand Down
2 changes: 0 additions & 2 deletions server/src/modules/api/tmdb-api/tmdb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import {
TmdbUpcomingMoviesResponse,
} from './interfaces/tmdb.interface';

const ANIME_KEYWORD_ID = 210024;

export class TmdbApiService extends ExternalApiService {
private region?: string;
private originalLanguage?: string;
Expand Down
16 changes: 8 additions & 8 deletions server/src/modules/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ interface addCollectionDbResponse {
deleteAfterDays: number;
manualCollection: boolean;
}

@Injectable()
export class CollectionsService {
private readonly logger = new Logger(CollectionsService.name);

constructor(
@InjectRepository(Collection)
private readonly collectionRepo: Repository<Collection>,
Expand Down Expand Up @@ -562,11 +564,11 @@ export class CollectionsService {
sharedHome: collection.visibleOnHome,
});
} else {
collection.manualCollection
? this.logger.warn(
`Manual Collection '${collection.manualCollectionName}' doesn't exist in Plex..`,
)
: undefined;
if (collection.manualCollection) {
this.logger.warn(
`Manual Collection '${collection.manualCollectionName}' doesn't exist in Plex..`,
);
}
}
}
// add children to collection
Expand Down Expand Up @@ -696,9 +698,7 @@ export class CollectionsService {
});

if (!collection.manualCollection) {
const status = await this.plexApi.deleteCollection(
collection.plexId.toString(),
);
await this.plexApi.deleteCollection(collection.plexId.toString());
}

await this.CollectionMediaRepo.delete({ collectionId: collection.id });
Expand Down
10 changes: 4 additions & 6 deletions server/src/modules/collections/entities/collection.entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ export class Collection {
sonarrSettings: SonarrSettings;

@OneToMany(
(type) => CollectionMedia,
() => CollectionMedia,
(collectionMedia) => collectionMedia.collectionId,
{ onDelete: 'CASCADE' },
)
collectionMedia: CollectionMedia[];

@OneToMany(
(type) => CollectionLog,
(collectionLog) => collectionLog.collection,
{ onDelete: 'CASCADE' },
)
@OneToMany(() => CollectionLog, (collectionLog) => collectionLog.collection, {
onDelete: 'CASCADE',
})
collectionLog: CollectionLog[];
}
Loading

0 comments on commit 29d3e10

Please sign in to comment.