Skip to content

Commit f47d617

Browse files
committed
Update ESLint config with more strict TS rules
1 parent dcff896 commit f47d617

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+366
-374
lines changed

api/http/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function fetchJSON<Response = unknown>(
4545
throw new Error(await response.text())
4646
}
4747
if (opts.response) opts.response(response)
48-
return response.json()
48+
return response.json() as Response
4949
}
5050

5151
export interface Endpoint<

core/download.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface TextResponse {
55
readonly contentType: string
66
readonly headers: Headers
77
readonly ok: boolean
8-
parseJson(): null | unknown
8+
parseJson(): unknown
99
parseXml(): Document | null | XMLDocument
1010
readonly redirected: boolean
1111
readonly status: number
@@ -67,7 +67,7 @@ export function createTextResponse(
6767
}
6868

6969
try {
70-
return JSON.parse(text)
70+
return JSON.parse(text) as unknown
7171
} catch (e) {
7272
if (e instanceof SyntaxError) {
7373
warning('Parse JSON error', e.message)

core/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ export function getTestEnvironment(): EnvironmentAndStore {
141141
persistentEvents: { addEventListener() {}, removeEventListener() {} },
142142
persistentStore: {},
143143
restartApp: () => {},
144-
translationLoader: async () => ({})
144+
translationLoader: () => Promise.resolve({})
145145
}
146146
}

core/export.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,23 @@ export function getOPMLBlob(): Blob {
9191
return new Blob([opml], { type: 'application/xml' })
9292
}
9393

94-
export async function getInternalBlob(isIncludePosts: Boolean): Promise<Blob> {
94+
export type InternalExport = {
95+
data: [CategoryValue, FeedWithPosts[]][]
96+
type: 'feedsByCategory'
97+
}
98+
99+
export async function getInternalBlob(isIncludePosts: boolean): Promise<Blob> {
95100
$exporting.set(true)
96101
let posts: PostValue[]
97-
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
102+
98103
if (isIncludePosts) {
99104
posts = await loadValue(getPosts()).then(value => value.list)
100105
}
101106
let enrichedData = $exportingFeedsByCategory
102107
.get()
103108
.map(([category, feeds]: [CategoryValue, FeedWithPosts[]]) => {
104109
let categoryTitle = getCategoryTitle(category)
105-
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
110+
106111
if (isIncludePosts) {
107112
feeds.forEach(feed => {
108113
feed.posts = posts.filter(post => post.feedId === feed.id)

core/import.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import {
66
type CategoryValue,
77
type FeedsByCategory
88
} from './category.ts'
9+
import type { InternalExport } from './export.ts'
910
import { addFeed, type FeedValue } from './feed.ts'
1011
import { readonlyExport } from './lib/stores.ts'
12+
import { unique } from './loader/utils.ts'
1113
import { importMessages } from './messages/index.ts'
1214
import { createFeedFromUrl } from './preview.ts'
13-
import { unique } from './loader/utils.ts'
1415

1516
let $importedFeedsByCategory = atom<FeedsByCategory>([])
1617
export const importedFeedsByCategory = readonlyExport($importedFeedsByCategory)
@@ -139,6 +140,17 @@ export const toggleImportedFeed = (
139140
$importedFeeds.set(Array.from(selectedFeeds))
140141
}
141142

143+
function isInternalExport(json: unknown): json is InternalExport {
144+
return (
145+
typeof json === 'object' &&
146+
json !== null &&
147+
'type' in json &&
148+
json.type === 'feedsByCategory' &&
149+
'data' in json &&
150+
Array.isArray(json.data)
151+
)
152+
}
153+
142154
export const handleImportFile = (file: File): Promise<void> => {
143155
return new Promise(resolve => {
144156
$reading.set(true)
@@ -155,7 +167,7 @@ export const handleImportFile = (file: File): Promise<void> => {
155167
if (fileExtension === 'json') {
156168
try {
157169
let jsonData = JSON.parse(content)
158-
if (jsonData.type === 'feedsByCategory') {
170+
if (isInternalExport(jsonData)) {
159171
$importedFeedsByCategory.set(jsonData.data)
160172
importSubscribe()
161173
selectAllImportedFeeds()

core/lib/stores.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ export function increaseKey<Store extends MapStore>(
3333
store: Store,
3434
key: NumberKeys<StoreValue<Store>>
3535
): void {
36-
store.setKey(key, store.get()[key] + 1)
36+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
37+
let value = store.get()[key] as number
38+
store.setKey(key, value + 1)
3739
}
3840

3941
export function listenMany<SourceStores extends ReadableAtom[]>(
4042
stores: [...SourceStores],
4143
cb: (...values: StoreValues<SourceStores>) => void
4244
): () => void {
4345
function listener(): void {
46+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
4447
let values = stores.map(store => store.get()) as StoreValues<SourceStores>
4548
cb(...values)
4649
}

core/loader/json-feed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function isObject(value: unknown): value is Record<string, unknown> {
7373
}
7474

7575
function stringify(value: unknown): string {
76-
return typeof value === 'object' ? JSON.stringify(value) : `${value}`
76+
return typeof value === 'object' ? JSON.stringify(value) : String(value)
7777
}
7878

7979
function validate<ValidatedType>(

core/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export const onPreviewUrlType = debounce((value: string) => {
288288
}
289289
}, 500)
290290

291-
export async function setPreviewCandidate(url: string): Promise<void> {
291+
export function setPreviewCandidate(url: string): void {
292292
let candidate = $candidates.get().find(i => i.url === url)
293293
if (candidate) {
294294
$candidate.set(url)

core/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function expectRequest(url: string): RequestMock {
8080
expect.response = body
8181
},
8282
andWait() {
83-
let resolveWait: Function
83+
let resolveWait: () => void
8484
expect.wait = new Promise(resolve => {
8585
resolveWait = resolve
8686
})

core/test/dom-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JSDOM } from 'jsdom'
22

33
let window = new JSDOM().window
4-
// @ts-expect-error
4+
// @ts-expect-error JSDOM types are incomplete
55
global.window = window
66
global.DOMParser = window.DOMParser
77
global.File = window.File

0 commit comments

Comments
 (0)