Skip to content

Commit 97e6f67

Browse files
committed
links: don't check favicon.ico if it's not provided
1 parent 0e34c64 commit 97e6f67

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

lib/rules/links/linkchecker.js

+30-27
Original file line numberDiff line numberDiff line change
@@ -84,39 +84,42 @@ export async function check(sr, done) {
8484
});
8585
const page = await browser.newPage();
8686
const docPath = sr.url.replace(/\/[^/]+$/, '/').replace(/^https?:/, '');
87+
const origin = new URL(sr.url).origin;
8788

8889
page.on('response', response => {
8990
const url = simplifyURL(response.url());
9091
const { referer } = response.request().headers();
9192

92-
// check if resource is in same folder as base document
93-
if (
94-
!url.replace(/^https?:/, '').startsWith(docPath) &&
95-
!(includedByReg(url) || includedByReg(referer)) &&
96-
url !== sr.url
97-
) {
98-
sr.error(compound, 'not-same-folder', { base: docPath, url });
99-
}
93+
if (url !== `${origin}/favicon.ico`) {
94+
// check if resource is in same folder as base document
95+
if (
96+
!url.replace(/^https?:/, '').startsWith(docPath) &&
97+
!(includedByReg(url) || includedByReg(referer)) &&
98+
url !== sr.url
99+
) {
100+
sr.error(compound, 'not-same-folder', { base: docPath, url });
101+
}
100102

101-
// check if every resource's status code is ok, ignore 3xx
102-
if (response.status() >= 400 && !noRespondAllowList.includes(url)) {
103-
const chain = response.request().redirectChain();
104-
// If an url is redirected from another, chain shall exist
105-
if (chain.length) {
106-
sr.error(compound, 'response-error-with-redirect', {
107-
url,
108-
originUrl: chain[0].url(),
109-
status: response.status(),
110-
text: response.statusText(),
111-
referer,
112-
});
113-
} else {
114-
sr.error(compound, 'response-error', {
115-
url,
116-
status: response.status(),
117-
text: response.statusText(),
118-
referer,
119-
});
103+
// check if every resource's status code is ok, ignore 3xx
104+
if (response.status() >= 400 && !noRespondAllowList.includes(url)) {
105+
const chain = response.request().redirectChain();
106+
// If an url is redirected from another, chain shall exist
107+
if (chain.length) {
108+
sr.error(compound, 'response-error-with-redirect', {
109+
url,
110+
originUrl: chain[0].url(),
111+
status: response.status(),
112+
text: response.statusText(),
113+
referer,
114+
});
115+
} else {
116+
sr.error(compound, 'response-error', {
117+
url,
118+
status: response.status(),
119+
text: response.statusText(),
120+
referer,
121+
});
122+
}
120123
}
121124
}
122125
});

0 commit comments

Comments
 (0)