Fix errors found by linter

This commit is contained in:
freearhey 2023-09-22 06:22:47 +03:00
parent efcae8e3b5
commit 21efb82055
24 changed files with 632 additions and 629 deletions

View file

@ -19,19 +19,19 @@ export class HTMLTable {
let output = '<table>\n' let output = '<table>\n'
output += ' <thead>\n <tr>' output += ' <thead>\n <tr>'
for (let column of this.columns) { for (const column of this.columns) {
output += `<th align="left">${column.name}</th>` output += `<th align="left">${column.name}</th>`
} }
output += '</tr>\n </thead>\n' output += '</tr>\n </thead>\n'
output += ' <tbody>\n' output += ' <tbody>\n'
for (let item of this.data) { for (const item of this.data) {
output += ' <tr>' output += ' <tr>'
let i = 0 let i = 0
for (let prop in item) { for (const prop in item) {
const column = this.columns[i] const column = this.columns[i]
let nowrap = column.nowrap ? ` nowrap` : '' const nowrap = column.nowrap ? ' nowrap' : ''
let align = column.align ? ` align="${column.align}"` : '' const align = column.align ? ` align="${column.align}"` : ''
output += `<td${align}${nowrap}>${item[prop]}</td>` output += `<td${align}${nowrap}>${item[prop]}</td>`
i++ i++
} }

View file

@ -11,7 +11,7 @@ const octokit = new CustomOctokit()
export class IssueLoader { export class IssueLoader {
async load({ labels }: { labels: string[] | string }) { async load({ labels }: { labels: string[] | string }) {
labels = Array.isArray(labels) ? labels.join(',') : labels labels = Array.isArray(labels) ? labels.join(',') : labels
let issues: any[] = [] let issues: object[] = []
if (TESTING) { if (TESTING) {
switch (labels) { switch (labels) {
case 'streams:add': case 'streams:add':

View file

@ -1,6 +1,5 @@
import { Dictionary } from '@freearhey/core' import { Dictionary } from '@freearhey/core'
import { Issue } from '../models' import { Issue } from '../models'
import _ from 'lodash'
const FIELDS = new Dictionary({ const FIELDS = new Dictionary({
'Channel ID': 'channel_id', 'Channel ID': 'channel_id',
@ -21,7 +20,7 @@ const FIELDS = new Dictionary({
}) })
export class IssueParser { export class IssueParser {
parse(issue: any): Issue { parse(issue: { number: number; body: string; labels: { name: string }[] }): Issue {
const fields = issue.body.split('###') const fields = issue.body.split('###')
const data = new Dictionary() const data = new Dictionary()

View file

@ -4,7 +4,7 @@ export type LogItem = {
} }
export class LogParser { export class LogParser {
parse(content: string): any[] { parse(content: string): LogItem[] {
if (!content) return [] if (!content) return []
const lines = content.split('\n') const lines = content.split('\n')

View file

@ -14,7 +14,7 @@ export class PlaylistParser {
async parse(files: string[]): Promise<Collection> { async parse(files: string[]): Promise<Collection> {
let streams = new Collection() let streams = new Collection()
for (let filepath of files) { for (const filepath of files) {
const relativeFilepath = filepath.replace(path.normalize(STREAMS_DIR), '') const relativeFilepath = filepath.replace(path.normalize(STREAMS_DIR), '')
const _streams: Collection = await this.parseFile(relativeFilepath) const _streams: Collection = await this.parseFile(relativeFilepath)
streams = streams.concat(_streams) streams = streams.concat(_streams)

View file

@ -26,15 +26,13 @@ export class CategoriesGenerator implements Generator {
const streams = this.streams.orderBy([(stream: Stream) => stream.getTitle()]) const streams = this.streams.orderBy([(stream: Stream) => stream.getTitle()])
this.categories.forEach(async (category: Category) => { this.categories.forEach(async (category: Category) => {
let categoryStreams = streams const categoryStreams = streams
.filter((stream: Stream) => stream.hasCategory(category)) .filter((stream: Stream) => stream.hasCategory(category))
.map((stream: Stream) => { .map((stream: Stream) => {
const groupTitle = stream.categories const streamCategories = stream.categories
? stream.categories .map((category: Category) => category.name)
.map((category: Category) => category.name) .sort()
.sort() const groupTitle = stream.categories ? streamCategories.join(';') : ''
.join(';')
: ''
stream.groupTitle = groupTitle stream.groupTitle = groupTitle
return stream return stream
@ -48,7 +46,7 @@ export class CategoriesGenerator implements Generator {
const undefinedStreams = streams.filter((stream: Stream) => stream.noCategories()) const undefinedStreams = streams.filter((stream: Stream) => stream.noCategories())
const playlist = new Playlist(undefinedStreams, { public: true }) const playlist = new Playlist(undefinedStreams, { public: true })
const filepath = `categories/undefined.m3u` const filepath = 'categories/undefined.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ filepath, count: playlist.streams.count() })) this.logger.info(JSON.stringify({ filepath, count: playlist.streams.count() }))
} }

View file

@ -29,10 +29,10 @@ export class CountriesGenerator implements Generator {
} }
async generate(): Promise<void> { async generate(): Promise<void> {
let streams = this.streams const streams = this.streams
.orderBy([stream => stream.getTitle()]) .orderBy([stream => stream.getTitle()])
.filter((stream: Stream) => stream.isSFW()) .filter((stream: Stream) => stream.isSFW())
let regions = this.regions.filter((region: Region) => region.code !== 'INT') const regions = this.regions.filter((region: Region) => region.code !== 'INT')
this.countries.forEach(async (country: Country) => { this.countries.forEach(async (country: Country) => {
const countrySubdivisions = this.subdivisions.filter( const countrySubdivisions = this.subdivisions.filter(
@ -77,7 +77,7 @@ export class CountriesGenerator implements Generator {
const internationalStreams = streams.filter(stream => stream.isInternational()) const internationalStreams = streams.filter(stream => stream.isInternational())
if (internationalStreams.notEmpty()) { if (internationalStreams.notEmpty()) {
const playlist = new Playlist(internationalStreams, { public: true }) const playlist = new Playlist(internationalStreams, { public: true })
const filepath = `countries/int.m3u` const filepath = 'countries/int.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ filepath, count: playlist.streams.count() })) this.logger.info(JSON.stringify({ filepath, count: playlist.streams.count() }))
} }

View file

@ -17,7 +17,9 @@ export class LanguagesGenerator implements Generator {
} }
async generate(): Promise<void> { async generate(): Promise<void> {
let streams = this.streams.orderBy(stream => stream.getTitle()).filter(stream => stream.isSFW()) const streams = this.streams
.orderBy(stream => stream.getTitle())
.filter(stream => stream.isSFW())
let languages = new Collection() let languages = new Collection()
streams.forEach((stream: Stream) => { streams.forEach((stream: Stream) => {

View file

@ -26,7 +26,9 @@ export class RegionsGenerator implements Generator {
} }
async generate(): Promise<void> { async generate(): Promise<void> {
let streams = this.streams.orderBy(stream => stream.getTitle()).filter(stream => stream.isSFW()) const streams = this.streams
.orderBy(stream => stream.getTitle())
.filter(stream => stream.isSFW())
this.regions.forEach(async (region: Region) => { this.regions.forEach(async (region: Region) => {
if (region.code === 'INT') return if (region.code === 'INT') return

View file

@ -17,10 +17,10 @@ export class Playlist {
} }
toString() { toString() {
let output = `#EXTM3U\n` let output = '#EXTM3U\n'
this.streams.forEach((stream: Stream) => { this.streams.forEach((stream: Stream) => {
output += stream.toString(this.options) + `\n` output += stream.toString(this.options) + '\n'
}) })
return output return output

View file

@ -48,7 +48,7 @@ export class CountryTable implements Table {
} else if (countryCode === 'INT') { } else if (countryCode === 'INT') {
data.add([ data.add([
'ZZ', 'ZZ',
`🌍 International`, '🌍 International',
logItem.count, logItem.count,
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>` `<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
]) ])

View file

@ -4,14 +4,14 @@ import fs from 'fs-extra'
beforeEach(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
const stdout = execSync( execSync(
'STREAMS_DIR=tests/__data__/input/streams_generate API_DIR=tests/__data__/output/.api npm run api:generate', 'STREAMS_DIR=tests/__data__/input/streams_generate API_DIR=tests/__data__/output/.api npm run api:generate',
{ encoding: 'utf8' } { encoding: 'utf8' }
) )
}) })
it('can create streams.json', () => { it('can create streams.json', () => {
expect(content(`output/.api/streams.json`)).toMatchObject(content(`expected/.api/streams.json`)) expect(content('output/.api/streams.json')).toMatchObject(content('expected/.api/streams.json'))
}) })
function content(filepath: string) { function content(filepath: string) {

View file

@ -8,7 +8,7 @@ beforeEach(() => {
}) })
it('can format playlists', () => { it('can format playlists', () => {
const stdout = execSync('STREAMS_DIR=tests/__data__/output/streams npm run playlist:format', { execSync('STREAMS_DIR=tests/__data__/output/streams npm run playlist:format', {
encoding: 'utf8' encoding: 'utf8'
}) })

View file

@ -5,7 +5,7 @@ import * as glob from 'glob'
beforeEach(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
const stdout = execSync( execSync(
'STREAMS_DIR=tests/__data__/input/streams_generate DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs npm run playlist:generate', 'STREAMS_DIR=tests/__data__/input/streams_generate DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs npm run playlist:generate',
{ encoding: 'utf8' } { encoding: 'utf8' }
) )
@ -20,8 +20,8 @@ it('can generate playlists and logs', () => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`)) expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
}) })
expect(content(`output/logs/generators.log`).split('\n').sort()).toStrictEqual( expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
content(`expected/logs/generators.log`).split('\n').sort() content('expected/logs/generators.log').split('\n').sort()
) )
}) })

View file

@ -26,7 +26,7 @@ it('can format playlists', () => {
}) })
expect(stdout).toBe( expect(stdout).toBe(
`OUTPUT=closes #14151, closes #14140, closes #14139, closes #14110, closes #14179, closes #14178\n` 'OUTPUT=closes #14151, closes #14140, closes #14139, closes #14110, closes #14179, closes #14178\n'
) )
}) })

View file

@ -10,11 +10,13 @@ it('show an error if channel name in the blocklist', () => {
) )
console.log(stdout) console.log(stdout)
process.exit(1) process.exit(1)
} catch (error: any) { } catch (error: unknown) {
// @ts-ignore
expect(error.status).toBe(1) expect(error.status).toBe(1)
expect( expect(
// @ts-ignore
error.stdout.includes( error.stdout.includes(
`us_blocked.m3u\n 2 error "Fox Sports 2 Asia (Thai)" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0000)\n\n1 problems (1 errors, 0 warnings)\n` 'us_blocked.m3u\n 2 error "Fox Sports 2 Asia (Thai)" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0000)\n\n1 problems (1 errors, 0 warnings)\n'
) )
).toBe(true) ).toBe(true)
} }
@ -30,7 +32,7 @@ it('show a warning if channel has wrong id', () => {
expect( expect(
stdout.includes( stdout.includes(
`wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n` 'wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n'
) )
).toBe(true) ).toBe(true)
}) })

View file

@ -14,7 +14,7 @@ beforeEach(() => {
'tests/__data__/output/.readme/template.md' 'tests/__data__/output/.readme/template.md'
) )
const stdout = execSync( execSync(
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/logs README_DIR=tests/__data__/output/.readme npm run readme:update', 'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/logs README_DIR=tests/__data__/output/.readme npm run readme:update',
{ encoding: 'utf8' } { encoding: 'utf8' }
) )