Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHirsch committed Sep 9, 2021
1 parent 77f81cd commit 7c3d384
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 44 deletions.
1 change: 1 addition & 0 deletions scripts/generic-json.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/** This file is auto-generated, any changes made will likely be overridden */

export const json = {{{json}}}
8 changes: 7 additions & 1 deletion src/parser/__test__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export async function loadFixture(name = "example"): Promise<string> {
}

export function getPhaseSupport(feed: FeedObject, phase: number): string[] {
return feed.__phase?.[phase.toString()] ?? [];
const defaultReturn: string[] = [];
// eslint-disable-next-line no-underscore-dangle
const phaseObj = feed.__phase;
if (phaseObj) {
return phaseObj[phase] ?? defaultReturn;
}
return defaultReturn;
}

export function loadSimple(): Promise<string> {
Expand Down
1 change: 1 addition & 0 deletions src/parser/phase/__test__/phase-1.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-duplicate-string */
import * as helpers from "../../__test__/helpers";
import { parseFeed } from "../../index";

Expand Down
1 change: 1 addition & 0 deletions src/parser/phase/__test__/phase-2.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-duplicate-string */
import * as helpers from "../../__test__/helpers";
import { parseFeed } from "../../index";

Expand Down
38 changes: 14 additions & 24 deletions src/parser/phase/__test__/phase-3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ describe("phase 3", () => {
});

describe("trailer", () => {
it("extracts generic single trailer", () => {
const url = "https://example.org/trailers/teaser";
const pubdate = "Thu, 01 Apr 2021 08:00:00 EST";
const mimeType = "audio/mp3";
const length = 12345678;
const title = "Coming April 1st, 2021";
const url = "https://example.org/trailers/teaser";
const pubdate = "Thu, 01 Apr 2021 08:00:00 EST";
const mimeType = "audio/mp3";
const length = 12345678;
const title = "Coming April 1st, 2021";

it("extracts generic single trailer", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:trailer pubdate="${pubdate}" url="${url}" length="${length}" type="${mimeType}">${title}</podcast:trailer>
Expand All @@ -38,11 +38,6 @@ describe("phase 3", () => {
});

it("extracts single season trailer", () => {
const url = "https://example.org/trailers/teaser";
const pubdate = "Thu, 01 Apr 2021 08:00:00 EST";
const mimeType = "audio/mp3";
const length = 12345678;
const title = "Coming April 1st, 2021";
const season = 1;

const xml = helpers.spliceFeed(
Expand All @@ -69,11 +64,6 @@ describe("phase 3", () => {
});

it("extracts multiple season trailers", () => {
const url = "https://example.org/trailers/teaser";
const pubdate = "Thu, 01 Apr 2021 08:00:00 EST";
const mimeType = "audio/mp3";
const length = 12345678;
const title = "Coming April 1st, 2021";
const season = 1;

const xml = helpers.spliceFeed(
Expand Down Expand Up @@ -110,10 +100,6 @@ describe("phase 3", () => {
});

it("skips missing url trailers", () => {
const pubdate = "Thu, 01 Apr 2021 08:00:00 EST";
const mimeType = "audio/mp3";
const length = 12345678;
const title = "Coming April 1st, 2021";
const season = 1;

const xml = helpers.spliceFeed(
Expand All @@ -130,9 +116,10 @@ describe("phase 3", () => {
});

describe("feed license", () => {
const customLicense = "my-podcast-license-v1";
it("extracts custom license", () => {
const url = "https://example.org/mypodcastlicense/full.pdf";
const name = "my-podcast-license-v1";
const name = customLicense;
const xml = helpers.spliceFeed(
feed,
`<podcast:license url="${url}">${name}</podcast:license>`
Expand Down Expand Up @@ -162,7 +149,7 @@ describe("phase 3", () => {
});

it("skips bad custom license", () => {
const name = "my-podcast-license-v1";
const name = customLicense;
const xml = helpers.spliceFeed(feed, `<podcast:license>${name}</podcast:license>`);

const result = parseFeed(xml);
Expand All @@ -174,9 +161,11 @@ describe("phase 3", () => {
});

describe("item license", () => {
const customLicense = "my-podcast-license-v1";

it("extracts custom license", () => {
const url = "https://example.org/mypodcastlicense/full.pdf";
const name = "my-podcast-license-v1";
const name = customLicense;
const xml = helpers.spliceFirstItem(
feed,
`<podcast:license url="${url}">${name}</podcast:license>`
Expand Down Expand Up @@ -216,7 +205,7 @@ describe("phase 3", () => {
});

it("skips bad custom license", () => {
const name = "my-podcast-license-v1";
const name = customLicense;
const xml = helpers.spliceFirstItem(feed, `<podcast:license>${name}</podcast:license>`);

const result = parseFeed(xml);
Expand Down Expand Up @@ -255,6 +244,7 @@ describe("phase 3", () => {
expect(altEnclosure).toHaveProperty("bitrate", 128000);
expect(altEnclosure).toHaveProperty("title", "Standard");

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(altEnclosure.source).toHaveLength(2);
const [s1, s2] = first.alternativeEnclosures[0].source;
expect(s1).toHaveProperty("uri", "https://example.com/file-720.torrent");
Expand Down
4 changes: 2 additions & 2 deletions src/parser/phase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type FeedUpdate = {
/** What is the name of the tag, expected to "transcript" for <podcast:transcript> */
tag: string;
/** Processing function to return an object to be merged with the current feed */
fn: (node: any, feed: RSSFeed) => Partial<FeedObject>;
fn: (node: TODO, feed: RSSFeed) => Partial<FeedObject>;
/** An optional function to transform the node before calling both the support and processing functions */
nodeTransform?: NodeTransform;
/** An optional function to determine if the tag meets the requirements for processing (eg. has required attributes or value) */
Expand All @@ -44,7 +44,7 @@ export type ItemUpdate = {
/** What is the name of the tag, expected to "transcript" for <podcast:transcript> */
tag: string;
/** Processing function to return an object to be merged with the current item */
fn: (node: any, feed: RSSFeed) => Partial<Episode>;
fn: (node: TODO, feed: RSSFeed) => Partial<Episode>;
/** An optional function to transform the node before calling both the support and processing functions */
nodeTransform?: NodeTransform;
/** An optional function to determine if the tag meets the requirements for processing (eg. has required attributes or value) */
Expand Down
1 change: 1 addition & 0 deletions src/parser/phase/licenses.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/** This file is auto-generated, any changes made will likely be overridden */

export const json = {
Expand Down
16 changes: 8 additions & 8 deletions src/parser/phase/phase-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const locked: FeedUpdate = {
const lockedText = getText(node).toLowerCase();
const owner = getAttribute(node, "owner");

log.debug(`- Owner: ${owner}`);
log.debug(`- Owner: ${owner ?? ""}`);
log.debug(`- Locked: ${lockedText}`);

if (["yes", "true"].includes(lockedText)) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export const transcript: ItemUpdate = {
tag: "transcript",
nodeTransform: ensureArray,
supportCheck: (node) =>
node.some(
(node as TODO[]).some(
(transcriptNode: any) =>
Boolean(getAttribute(transcriptNode, "url")) &&
Boolean(getAttribute(transcriptNode, "type"))
Expand All @@ -80,7 +80,7 @@ export const transcript: ItemUpdate = {

const itemUpdate = { podcastTranscripts: [] as Phase1Transcript[] };

node.forEach((transcriptNode: any) => {
(node as TODO[]).forEach((transcriptNode: any) => {
const feedLanguage: string = feed ? feed.rss.channel.language : null;
const url = getAttribute(transcriptNode, "url");
const type = getAttribute(transcriptNode, "type") as TranscriptType;
Expand All @@ -89,10 +89,10 @@ export const transcript: ItemUpdate = {
const rel = getAttribute(transcriptNode, "rel");

log.debug(`- Feed Language: ${feedLanguage}`);
log.debug(`- URL: ${url}`);
log.debug(`- URL: ${url ?? "<null>"}`);
log.debug(`- Type: ${type}`);
log.debug(`- Language: ${language}`);
log.debug(`- Rel: ${rel}`);
log.debug(`- Rel: ${rel ?? "<null>"}`);

if (url && type) {
const transcriptValue: Phase1Transcript = {
Expand Down Expand Up @@ -196,13 +196,13 @@ export const soundbite: ItemUpdate = {
tag: "soundbite",
nodeTransform: ensureArray,
supportCheck: (node) =>
node.some((n: any) => getAttribute(n, "duration") && getAttribute(n, "startTime")),
(node as TODO[]).some((n: TODO) => getAttribute(n, "duration") && getAttribute(n, "startTime")),
fn(node, feed) {
log.info("soundbite");

const itemUpdate = { podcastSoundbites: [] as Phase1SoundBite[] };

node.forEach((soundbiteNode: any) => {
(node as TODO[]).forEach((soundbiteNode: TODO) => {
const duration = parseFloat(getKnownAttribute(soundbiteNode, "duration"));
const startTime = parseFloat(getKnownAttribute(soundbiteNode, "startTime"));
const title = getText(soundbiteNode);
Expand All @@ -211,7 +211,7 @@ export const soundbite: ItemUpdate = {
const bite: Phase1SoundBite = {
duration,
startTime,
title: title ? title : (feed.rss.channel.title ?? "").trim(),
title: title || ((feed.rss.channel.title as string) ?? "").trim(),
};

itemUpdate.podcastSoundbites.push(bite);
Expand Down
4 changes: 2 additions & 2 deletions src/parser/phase/phase-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export const person: FeedUpdate | ItemUpdate = {
tag: "person",
nodeTransform: ensureArray,
// As long as one of the person tags has text, we'll consider it valid
supportCheck: (node) => node.some((n: any) => Boolean(getText(n))),
supportCheck: (node) => (node as TODO[]).some((n: TODO) => Boolean(getText(n))),
fn(node: TODO): Partial<FeedObject> | Partial<Episode> {
log.info("person");
const podcastPeople: Phase2Person[] = [];

const groups = Object.values(PersonGroup);
const roles = Object.values(PersonRole);

node.forEach((personNode: any) => {
(node as TODO[]).forEach((personNode: TODO) => {
const name = getText(personNode);
const role =
roles.find((r) => r.toLowerCase() === getAttribute(personNode, "role")?.toLowerCase()) ??
Expand Down
13 changes: 6 additions & 7 deletions src/parser/phase/phase-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {

import { json as licenseDefinitions } from "./licenses";

import type { Episode, FeedObject } from "../shared";
import type { FeedUpdate, ItemUpdate } from "./index";
import { log } from "../../logger";

Expand Down Expand Up @@ -104,19 +103,19 @@ export const license: FeedUpdate | ItemUpdate = {
)?.reference;

if (!url) {
log.warn(`Missing License URL for ${identifier}, originating in ${feed.rss.channel.title}`);
log.warn(
`Missing License URL for ${identifier}, originating in ${feed.rss.channel.title as string}`
);
return {};
}

log.info(` [${identifier}](${url})`);
const update: Partial<FeedObject> | Partial<Episode> = {
return {
license: {
identifier,
url,
},
};

return update;
},
};

Expand Down Expand Up @@ -171,7 +170,7 @@ export const alternativeEnclosure: ItemUpdate = {
tag: "alternateEnclosure",
nodeTransform: ensureArray,
supportCheck: (node) => {
return node.some((i: any) => {
return (node as TODO[]).some((i: TODO) => {
const type = getAttribute(i, "type");
const length = getAttribute(i, "length");
const sourceNodes = ensureArray(i?.["podcast:source"] ?? []);
Expand All @@ -189,7 +188,7 @@ export const alternativeEnclosure: ItemUpdate = {

const update: Phase3AltEnclosure[] = [];

node.forEach((altEncNode: any) => {
(node as TODO[]).forEach((altEncNode: TODO) => {
const type = getKnownAttribute(altEncNode, "type");
const length = getKnownAttribute(altEncNode, "length");
const sourceUris = ensureArray(altEncNode["podcast:source"] ?? [])
Expand Down

0 comments on commit 7c3d384

Please sign in to comment.