From 6e1a44ae59eaa6d513014bbafdaa26d14ac8107c Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 25 May 2026 07:47:18 +0300 Subject: [PATCH 1/4] index: make references a const After 4942da3 this is safe. --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 9ab10c3..f8abd52 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,6 @@ export interface Options { } function detective(src: string, options: Options = { url: false }): string[] { - let references: string[] = []; let root: Root; try { @@ -30,6 +29,8 @@ function detective(src: string, options: Options = { url: false }): string[] { throw new MalformedCssError(); } + const references: string[] = []; + root.walkAtRules((rule) => { let file = null; From bdbd381a3245797cc08d43173d16f63af277a0ae Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 25 May 2026 07:52:57 +0300 Subject: [PATCH 2/4] index: use optional chaining --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f8abd52..2b39df8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -99,7 +99,7 @@ function getUrlContent(urlNode: Func): string { const first = urlNode.nodes[0]; // Quoted: url('foo.css') or url("foo.css") - if (first && first.type === 'quoted') { + if (first?.type === 'quoted') { return first.contents; } From 6c5c4f5619ddc909127cbaa3f4b3d5beaee27e78 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 25 May 2026 07:59:30 +0300 Subject: [PATCH 3/4] index: avoid object literal as default for options Fixes unicorn/no-object-as-default-parameter. url is optional and only checked for truthiness, so the empty default is equivalent. --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2b39df8..e55f442 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ export interface Options { url?: boolean; } -function detective(src: string, options: Options = { url: false }): string[] { +function detective(src: string, options: Options = {}): string[] { let root: Root; try { From 5af9b0d92b1f67cabe23e01f872d032fd0f6481c Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 25 May 2026 08:06:22 +0300 Subject: [PATCH 4/4] index: simplify url filtering Return undefined for absent values instead of false, and cast filter(Boolean) to string[] instead of using a type predicate. --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index e55f442..0256422 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,7 +75,7 @@ function detective(src: string, options: Options = {}): string[] { const files = nodes .filter((node) => isUrlNode(node)) .map((node) => getValueOrUrl(node)) - .filter((file): file is string => Boolean(file)); + .filter(Boolean) as string[]; for (const file of files) { debug('found %s of %s', 'url() in declaration', file); @@ -87,12 +87,12 @@ function detective(src: string, options: Options = {}): string[] { return references; } -function getValueOrUrl(node: ChildNode): string | false { +function getValueOrUrl(node: ChildNode): string | undefined { const ret = isUrlNode(node) ? getUrlContent(node) : getValue(node); // is-url-superb uses new URL() which doesn't accept protocol-relative URLs; // prepend http: so they get correctly identified and filtered out - return !isUrl(ret.startsWith('//') ? `http:${ret}` : ret) && ret; + return isUrl(ret.startsWith('//') ? `http:${ret}` : ret) ? undefined : ret; } function getUrlContent(urlNode: Func): string {