Skip to content

Commit 250169d

Browse files
authoredSep 16, 2021
fix(htmlhint.ts): replace deprecated request module with what-wg fetch (#670)
* fix(htmlhint.ts): replace deprecated request module Replace deprecated request module with what-wg fetch. * fix(bin/htmlhint): Add execute permission. * chore(package.json): add node-fetch 2.x types * fix(package.json): @types/node-fetch should have been dev dependency
1 parent f66fca4 commit 250169d

File tree

4 files changed

+140
-362
lines changed

4 files changed

+140
-362
lines changed
 

‎bin/htmlhint

100644100755
File mode changed.

‎package-lock.json

+127-353
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@
5858
}
5959
},
6060
"dependencies": {
61+
"@types/node-fetch": "^2.5.12",
6162
"async": "3.2.0",
6263
"chalk": "4.1.0",
6364
"commander": "5.1.0",
6465
"glob": "7.1.7",
66+
"node-fetch": "^2.6.2",
6567
"parse-glob": "3.0.4",
66-
"request": "2.88.2",
6768
"strip-json-comments": "3.1.0",
6869
"xml": "1.0.1"
6970
},
@@ -80,8 +81,8 @@
8081
"@semantic-release/release-notes-generator": "9.0.3",
8182
"@types/async": "3.2.3",
8283
"@types/glob": "7.1.3",
84+
"@types/node-fetch": "^2.5.12",
8385
"@types/parse-glob": "3.0.29",
84-
"@types/request": "2.48.7",
8586
"@types/xml": "1.0.5",
8687
"@typescript-eslint/eslint-plugin": "3.6.0",
8788
"@typescript-eslint/parser": "3.6.0",

‎src/cli/htmlhint.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as glob from 'glob'
88
import { IGlob } from 'glob'
99
import * as parseGlob from 'parse-glob'
1010
import { dirname, resolve, sep } from 'path'
11-
import * as request from 'request'
11+
import fetch from 'node-fetch'
1212
import * as stripJsonComments from 'strip-json-comments'
1313
import type { HTMLHint as IHTMLHint } from '../core/core'
1414
import type { Hint, Ruleset } from '../core/types'
@@ -494,12 +494,15 @@ function hintUrl(
494494
ruleset: Ruleset | undefined,
495495
callback: (messages: Hint[]) => void
496496
) {
497-
request.get(url, (error, response, body) => {
498-
if (!error && response.statusCode == 200) {
499-
const messages = HTMLHint.verify(body, ruleset)
500-
callback(messages)
497+
const errorFn = () => callback([])
498+
fetch(url).then((response) => {
499+
if (response.ok) {
500+
response.text().then((body) => {
501+
const messages = HTMLHint.verify(body, ruleset)
502+
callback(messages)
503+
}, errorFn)
501504
} else {
502-
callback([])
505+
errorFn()
503506
}
504-
})
507+
}, errorFn)
505508
}

0 commit comments

Comments
 (0)
Please sign in to comment.