Skip to content

Commit 5c6975f

Browse files
committed
Refactor code-style
1 parent 52d81ef commit 5c6975f

File tree

5 files changed

+75
-77
lines changed

5 files changed

+75
-77
lines changed

lib/atom.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @typedef {import('./types.js').Entry} Entry
88
*/
99

10-
import {URL} from 'url'
10+
import {URL} from 'node:url'
1111
import {u} from 'unist-builder'
1212
import {x} from 'xastscript'
1313
import {bcp47Normalize as normalize} from 'bcp-47-normalize'
@@ -22,27 +22,32 @@ import {toAuthor, toDate} from './util.js'
2222
* @returns {Root}
2323
*/
2424
export function atom(channel, data) {
25-
var now = new Date()
25+
const now = new Date()
2626
/** @type {Channel} */
27-
var meta = channel || {title: null, url: null}
27+
const meta = channel || {title: null, url: null}
2828
/** @type {Array.<Element>} */
29-
var items = []
30-
var index = -1
29+
const items = []
30+
let index = -1
3131
/** @type {number} */
32-
var offset
32+
let offset
3333
/** @type {Array.<Element>} */
34-
var children
34+
let children
3535
/** @type {Entry} */
36-
var datum
36+
let datum
3737
/** @type {string} */
38-
var url
38+
let url
3939
/** @type {Author} */
40-
var author
40+
let author
4141
/** @type {Enclosure} */
42-
var enclosure
42+
let enclosure
4343

44-
if (meta.title == null) throw new Error('Expected `channel.title` to be set')
45-
if (meta.url == null) throw new Error('Expected `channel.url` to be set')
44+
if (meta.title === undefined || meta.title === null) {
45+
throw new Error('Expected `channel.title` to be set')
46+
}
47+
48+
if (meta.url === undefined || meta.url === null) {
49+
throw new Error('Expected `channel.url` to be set')
50+
}
4651

4752
url = new URL(meta.url).href
4853

@@ -111,11 +116,11 @@ export function atom(channel, data) {
111116
children.push(x('link', {href: url}), x('id', url))
112117
}
113118

114-
if (datum.published != null) {
119+
if (datum.published !== undefined && datum.published !== null) {
115120
children.push(x('published', toDate(datum.published).toISOString()))
116121
}
117122

118-
if (datum.modified != null) {
123+
if (datum.modified !== undefined && datum.modified !== null) {
119124
children.push(x('updated', toDate(datum.modified).toISOString()))
120125
}
121126

lib/rss.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @typedef {import('./types.js').Entry} Entry
88
*/
99

10-
import {URL} from 'url'
10+
import {URL} from 'node:url'
1111
import {u} from 'unist-builder'
1212
import {x} from 'xastscript'
1313
import {bcp47Normalize as normalize} from 'bcp-47-normalize'
@@ -22,33 +22,38 @@ import {toAuthor, toDate} from './util.js'
2222
* @returns {Root}
2323
*/
2424
export function rss(channel, data) {
25-
var now = new Date()
25+
const now = new Date()
2626
/** @type {Channel} */
27-
var meta = channel || {title: null, url: null}
27+
const meta = channel || {title: null, url: null}
2828
/** @type {Array.<Element>} */
29-
var items = []
30-
var index = -1
29+
const items = []
30+
let index = -1
3131
/** @type {boolean} */
32-
var atom
32+
let atom
3333
/** @type {number} */
34-
var offset
34+
let offset
3535
/** @type {Array.<Element>} */
36-
var children
36+
let children
3737
/** @type {Entry} */
38-
var datum
38+
let datum
3939
/** @type {string} */
40-
var lang
40+
let lang
4141
/** @type {string} */
42-
var copy
42+
let copy
4343
/** @type {string} */
44-
var url
44+
let url
4545
/** @type {Author} */
46-
var author
46+
let author
4747
/** @type {Enclosure} */
48-
var enclosure
48+
let enclosure
4949

50-
if (meta.title == null) throw new Error('Expected `channel.title` to be set')
51-
if (meta.url == null) throw new Error('Expected `channel.url` to be set')
50+
if (meta.title === undefined || meta.title === null) {
51+
throw new Error('Expected `channel.title` to be set')
52+
}
53+
54+
if (meta.url === undefined || meta.url === null) {
55+
throw new Error('Expected `channel.url` to be set')
56+
}
5257

5358
items.push(
5459
x('title', String(meta.title)),
@@ -123,15 +128,15 @@ export function rss(channel, data) {
123128
)
124129
}
125130

126-
if (datum.published != null) {
131+
if (datum.published !== undefined && datum.published !== null) {
127132
children.push(
128133
// @ts-ignore `toGTMString` is exactly what we need.
129134
x('pubDate', toDate(datum.published).toGMTString()),
130135
x('dc:date', toDate(datum.published).toISOString())
131136
)
132137
}
133138

134-
if (datum.modified != null) {
139+
if (datum.modified !== undefined && datum.modified !== null) {
135140
children.push(x('dc:modified', toDate(datum.modified).toISOString()))
136141
}
137142

package.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,7 @@
7575
"prettier": true,
7676
"rules": {
7777
"complexity": "off",
78-
"eqeqeq": [
79-
"error",
80-
"always",
81-
{
82-
"null": "ignore"
83-
}
84-
],
85-
"no-eq-null": "off",
86-
"no-var": "off",
87-
"prefer-arrow-callback": "off",
88-
"unicorn/explicit-length-check": "off",
89-
"unicorn/numeric-separators-style": "off",
90-
"unicorn/prefer-node-protocol": "off"
78+
"unicorn/explicit-length-check": "off"
9179
}
9280
},
9381
"remarkConfig": {

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ Say we have the following module, `example.js`
4444
import {atom, rss} from 'xast-util-feed'
4545
import {toXml} from 'xast-util-to-xml'
4646

47-
var channel = {
47+
const channel = {
4848
title: 'NYT > Top Stories',
4949
url: 'https://www.nytimes.com',
5050
feedUrl: 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml',
5151
lang: 'en',
5252
author: 'The New York Times Company'
5353
}
5454

55-
var data = [
55+
const data = [
5656
{
5757
title: 'Senate Balances Impeachment Trial With an Incoming President',
5858
url:

0 commit comments

Comments
 (0)