From 4a2d16214c1937aa1532049ad92a7eda42cb53d0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 12 Apr 2026 13:10:48 -0300 Subject: validators, reformat-urls: various automatable fixes --- src/validators.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/validators.js') diff --git a/src/validators.js b/src/validators.js index 19d74991..7dcd7b8c 100644 --- a/src/validators.js +++ b/src/validators.js @@ -743,6 +743,9 @@ export function isCuratedURL(string) { `not ${colors.red(url.hostname)}`); switch (url.hostname) { + case 'tumblr.com': + throw useHostname('www.tumblr.com'); + case 'www.twitter.com': case 'x.com': throw useHostname('twitter.com'); @@ -768,12 +771,49 @@ export function isCuratedURL(string) { } }; + const dropTrailingSlash = () => { + if (url.pathname.length >= 3 && url.pathname.endsWith('/')) { + throw new Error( + `Remove slash at end: ` + + url.pathname.slice(0, -1) + + colors.bright(colors.red('/'))); + } + }; + switch (url.hostname) { + case 'soundcloud.com': + dropTrailingSlash(); + break; + + case 'open.spotify.com': + dropSearchParam('si', `tracking parameter`); + dropSearchParam('nd', `unnecessary parameter`); + break; + case 'www.youtube.com': dropSearchParam('si', `tracking parameter`); break; } + if (url.hostname === 'music.apple.com') { + const countryMatch = + url.pathname.match(/^\/[a-z][a-z]\//); + + if (countryMatch) { + throw new Error(`Remove country code ${colors.red(countryMatch[0])}`); + } + } + + if (url.pathname === '/' && string === url.origin + url.hash + url.search) { + if (url.hash) { + throw new Error(`Add slash before "#" hash`); + } else if (url.search) { + throw new Error(`Add slash before "?" query`); + } else { + throw new Error(`Add slash at end`); + } + } + return true; } -- cgit 1.3.0-6-gf8a5