Skip to content

Commit 7fb8891

Browse files
committed
Add strict to tsconfig.json
1 parent 5c6975f commit 7fb8891

File tree

4 files changed

+63
-91
lines changed

4 files changed

+63
-91
lines changed

lib/atom.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ export function atom(channel, data) {
2525
const now = new Date()
2626
/** @type {Channel} */
2727
const meta = channel || {title: null, url: null}
28-
/** @type {Array.<Element>} */
29-
const items = []
30-
let index = -1
31-
/** @type {number} */
32-
let offset
33-
/** @type {Array.<Element>} */
34-
let children
35-
/** @type {Entry} */
36-
let datum
37-
/** @type {string} */
38-
let url
39-
/** @type {Author} */
40-
let author
41-
/** @type {Enclosure} */
42-
let enclosure
4328

4429
if (meta.title === undefined || meta.title === null) {
4530
throw new Error('Expected `channel.title` to be set')
@@ -49,17 +34,16 @@ export function atom(channel, data) {
4934
throw new Error('Expected `channel.url` to be set')
5035
}
5136

52-
url = new URL(meta.url).href
53-
54-
items.push(
37+
const url = new URL(meta.url).href
38+
const items = [
5539
x('title', String(meta.title)),
5640
x('subtitle', String(meta.description || '') || null),
5741
// `rel: 'alternate'` is the default.
5842
x('link', url),
5943
x('id', url),
60-
// @ts-ignore `toGTMString` is exactly what we need.
44+
// @ts-expect-error `toGTMString` is exactly what we need.
6145
x('updated', now.toGMTString())
62-
)
46+
]
6347

6448
if (meta.feedUrl) {
6549
items.push(
@@ -72,24 +56,27 @@ export function atom(channel, data) {
7256
}
7357

7458
if (meta.author) {
75-
author = toAuthor(meta.author)
59+
const author = toAuthor(meta.author)
7660
items.push(
7761
x('rights', '© ' + now.getUTCFullYear() + ' ' + author.name),
7862
createAuthor(author)
7963
)
8064
}
8165

8266
if (meta.tags) {
83-
offset = -1
84-
while (++offset < meta.tags.length) {
85-
items.push(x('category', {term: String(meta.tags[offset])}))
67+
let index = -1
68+
while (++index < meta.tags.length) {
69+
items.push(x('category', {term: String(meta.tags[index])}))
8670
}
8771
}
8872

8973
if (data) {
74+
let index = -1
75+
9076
while (++index < data.length) {
91-
datum = data[index]
92-
children = []
77+
const datum = data[index]
78+
/** @type {Array.<Element>} */
79+
const children = []
9380

9481
if (!datum.title && !datum.description && !datum.descriptionHtml) {
9582
throw new Error(
@@ -112,7 +99,7 @@ export function atom(channel, data) {
11299
}
113100

114101
if (datum.url) {
115-
url = new URL(datum.url).href
102+
const url = new URL(datum.url).href
116103
children.push(x('link', {href: url}), x('id', url))
117104
}
118105

@@ -125,13 +112,13 @@ export function atom(channel, data) {
125112
}
126113

127114
if (datum.tags) {
128-
offset = -1
115+
let offset = -1
129116
while (++offset < datum.tags.length) {
130117
items.push(x('category', {term: String(datum.tags[offset])}))
131118
}
132119
}
133120

134-
enclosure = datum.enclosure
121+
const enclosure = datum.enclosure
135122

136123
if (enclosure) {
137124
if (!enclosure.url) {

lib/rss.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,8 @@ export function rss(channel, data) {
2525
const now = new Date()
2626
/** @type {Channel} */
2727
const meta = channel || {title: null, url: null}
28-
/** @type {Array.<Element>} */
29-
const items = []
30-
let index = -1
31-
/** @type {boolean} */
28+
/** @type {boolean|undefined} */
3229
let atom
33-
/** @type {number} */
34-
let offset
35-
/** @type {Array.<Element>} */
36-
let children
37-
/** @type {Entry} */
38-
let datum
39-
/** @type {string} */
40-
let lang
41-
/** @type {string} */
42-
let copy
43-
/** @type {string} */
44-
let url
45-
/** @type {Author} */
46-
let author
47-
/** @type {Enclosure} */
48-
let enclosure
4930

5031
if (meta.title === undefined || meta.title === null) {
5132
throw new Error('Expected `channel.title` to be set')
@@ -55,14 +36,14 @@ export function rss(channel, data) {
5536
throw new Error('Expected `channel.url` to be set')
5637
}
5738

58-
items.push(
39+
const items = [
5940
x('title', String(meta.title)),
6041
x('description', String(meta.description || '') || null),
6142
x('link', new URL(meta.url).href),
62-
// @ts-ignore `toGTMString` is exactly what we need.
43+
// @ts-expect-error `toGTMString` is exactly what we need.
6344
x('lastBuildDate', now.toGMTString()),
6445
x('dc:date', now.toISOString())
65-
)
46+
]
6647

6748
if (meta.feedUrl) {
6849
atom = true
@@ -76,26 +57,28 @@ export function rss(channel, data) {
7657
}
7758

7859
if (meta.lang) {
79-
lang = normalize(meta.lang)
60+
const lang = normalize(meta.lang)
8061
items.push(x('language', lang), x('dc:language', lang))
8162
}
8263

8364
if (meta.author) {
84-
copy = '© ' + now.getUTCFullYear() + ' ' + meta.author
65+
const copy = '© ' + now.getUTCFullYear() + ' ' + meta.author
8566
items.push(x('copyright', copy), x('dc:rights', copy))
8667
}
8768

8869
if (meta.tags) {
89-
offset = -1
90-
while (++offset < meta.tags.length) {
91-
items.push(x('category', String(meta.tags[offset])))
70+
let index = -1
71+
while (++index < meta.tags.length) {
72+
items.push(x('category', String(meta.tags[index])))
9273
}
9374
}
9475

9576
if (data) {
77+
let index = -1
9678
while (++index < data.length) {
97-
datum = data[index]
98-
children = []
79+
const datum = data[index]
80+
/** @type {Array.<Element>} */
81+
const children = []
9982

10083
if (!datum.title && !datum.description && !datum.descriptionHtml) {
10184
throw new Error(
@@ -108,7 +91,7 @@ export function rss(channel, data) {
10891
if (datum.title) children.push(x('title', String(datum.title)))
10992

11093
if (datum.author) {
111-
author = toAuthor(datum.author)
94+
const author = toAuthor(datum.author)
11295
children.push(x('dc:creator', author.name))
11396

11497
if (author.email) {
@@ -117,7 +100,7 @@ export function rss(channel, data) {
117100
}
118101

119102
if (datum.url) {
120-
url = new URL(datum.url).href
103+
const url = new URL(datum.url).href
121104
children.push(
122105
x('link', url),
123106
// Do not treat it as a URL, just an opaque identifier.
@@ -130,7 +113,7 @@ export function rss(channel, data) {
130113

131114
if (datum.published !== undefined && datum.published !== null) {
132115
children.push(
133-
// @ts-ignore `toGTMString` is exactly what we need.
116+
// @ts-expect-error `toGTMString` is exactly what we need.
134117
x('pubDate', toDate(datum.published).toGMTString()),
135118
x('dc:date', toDate(datum.published).toISOString())
136119
)
@@ -141,13 +124,14 @@ export function rss(channel, data) {
141124
}
142125

143126
if (datum.tags) {
144-
offset = -1
127+
let offset = -1
145128
while (++offset < datum.tags.length) {
146129
children.push(x('category', String(datum.tags[offset])))
147130
}
148131
}
149132

150-
enclosure = datum.enclosure
133+
const enclosure = datum.enclosure
134+
151135
if (enclosure) {
152136
if (!enclosure.url) {
153137
throw new Error(

0 commit comments

Comments
 (0)