Make ESLint Happy
Some checks failed
Build / Build (push) Has been cancelled
Build / Diff output (push) Has been cancelled
Build / Deploy (3.114.12) (push) Has been cancelled

This commit is contained in:
SukkaW
2026-06-30 16:07:44 +08:00
parent d472b9f79a
commit f1054035f7
14 changed files with 30 additions and 31 deletions

View File

@@ -129,7 +129,7 @@ function treeHtml(tree: TreeTypeArray, level = 0, closedFolderList: string[] = [
</details> </details>
</li> </li>
`; `;
} else if (/* entry.type === 'file' && */ !entry.name.endsWith('.html') && !entry.name.startsWith('_')) { } else if (/* entry.type === 'file' && */ !entry.name.endsWith('.html') && entry.name[0] !== '_') {
result += html` result += html`
<li class="file"><a class="file-link" href="${entry.path}">${entry.name}</a></li> <li class="file"><a class="file-link" href="${entry.path}">${entry.name}</a></li>
`; `;

View File

@@ -251,7 +251,8 @@ function uBOUriTransformGenerator(acc: string[], [from, to, canUboUriTransform]:
} }
// unlike Surge, which processes rules form top to bottom, uBO treats later rules with higher priority (overriden-like behavior), // unlike Surge, which processes rules form top to bottom, uBO treats later rules with higher priority (overriden-like behavior),
// so when doing uBO we need to prepend. Given the the rules count is small, the performance impact is negligible. // so when doing uBO we need to prepend.
// eslint-disable-next-line sukka/unicorn/no-array-front-mutation -- Given the the rules count is small, the performance impact is negligible.
acc.unshift( acc.unshift(
'||' '||'
+ from + from
@@ -280,7 +281,7 @@ function uBOUriTransformGeneratorForFakeWebsites(acc: string[], [from, to]: [fro
// https://www.formysql.com/en/products/navicat-for-mysql // https://www.formysql.com/en/products/navicat-for-mysql
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// https://www.navicat.com.cn // https://www.navicat.com.cn
+ String.raw`\/.*` + escapeRegexp(from).replaceAll('/', String.raw`\/`) + String.raw`.*` + String.raw`\/.*` + escapeRegexp(from).replaceAll('/', String.raw`\/`) + '.*'
+ '/' + '/'
+ to.replace('https://', '').replaceAll('/', String.raw`\/`) + to.replace('https://', '').replaceAll('/', String.raw`\/`)
+ '/' + '/'

View File

@@ -9,6 +9,7 @@ import dns from 'node:dns/promises';
import { createReadlineInterfaceFromResponse } from './lib/fetch-text-by-line'; import { createReadlineInterfaceFromResponse } from './lib/fetch-text-by-line';
import { fastIpVersion } from 'foxts/fast-ip-version'; import { fastIpVersion } from 'foxts/fast-ip-version';
import { fastStringArrayJoin } from 'foxts/fast-string-array-join'; import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
import { appendArrayInPlace } from 'foxts/append-array-in-place';
export const buildTelegramCIDR = task(require.main === module, __filename)(async (span) => { export const buildTelegramCIDR = task(require.main === module, __filename)(async (span) => {
const { timestamp, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', async () => { const { timestamp, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', async () => {
@@ -129,7 +130,7 @@ export const buildTelegramCIDR = task(require.main === module, __filename)(async
console.log('[telegram backup ip]', `Found ${backupIPs.size} backup IPs:`, backupIPs); console.log('[telegram backup ip]', `Found ${backupIPs.size} backup IPs:`, backupIPs);
ipcidr.push(...Array.from(backupIPs).map(i => i + '/32')); appendArrayInPlace(ipcidr, Array.from(backupIPs).map(i => i + '/32'));
return { timestamp: date.getTime(), ipcidr, ipcidr6 }; return { timestamp: date.getTime(), ipcidr, ipcidr6 };
}); });

View File

@@ -9,6 +9,7 @@ import dns from 'node:dns/promises';
import { createReadlineInterfaceFromResponse } from './lib/fetch-text-by-line'; import { createReadlineInterfaceFromResponse } from './lib/fetch-text-by-line';
import { fastIpVersion } from 'foxts/fast-ip-version'; import { fastIpVersion } from 'foxts/fast-ip-version';
import { fastStringArrayJoin } from 'foxts/fast-string-array-join'; import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
import { appendArrayInPlace } from 'foxts/append-array-in-place';
export const buildTelegramCIDR = task(require.main === module, __filename)(async (span) => { export const buildTelegramCIDR = task(require.main === module, __filename)(async (span) => {
const { timestamp, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', async () => { const { timestamp, ipcidr, ipcidr6 } = await span.traceChildAsync('get telegram cidr', async () => {
@@ -129,7 +130,7 @@ export const buildTelegramCIDR = task(require.main === module, __filename)(async
console.log('[telegram backup ip]', `Found ${backupIPs.size} backup IPs:`, backupIPs); console.log('[telegram backup ip]', `Found ${backupIPs.size} backup IPs:`, backupIPs);
ipcidr.push(...Array.from(backupIPs).map(i => i + '/32')); appendArrayInPlace(ipcidr, Array.from(backupIPs).map(i => i + '/32'));
return { timestamp: date.getTime(), ipcidr, ipcidr6 }; return { timestamp: date.getTime(), ipcidr, ipcidr6 };
}); });

View File

@@ -41,9 +41,8 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
} }
const writeStream = fs.createWriteStream(filePath); const writeStream = fs.createWriteStream(filePath);
let p;
for (let i = 0; i < linesALen; i++) { for (let i = 0; i < linesALen; i++) {
p = asyncWriteToStream(writeStream, linesA[i] + '\n'); const p = asyncWriteToStream(writeStream, linesA[i] + '\n');
// eslint-disable-next-line no-await-in-loop -- stream high water mark // eslint-disable-next-line no-await-in-loop -- stream high water mark
if (p) await p; if (p) await p;
} }

View File

@@ -21,6 +21,7 @@ import path from 'node:path';
import fs from 'node:fs'; import fs from 'node:fs';
import { CACHE_DIR } from '../constants/dir'; import { CACHE_DIR } from '../constants/dir';
import { isAbortErrorLike } from 'foxts/abort-error'; import { isAbortErrorLike } from 'foxts/abort-error';
import { isErrorLikeObject } from 'foxts/extract-error-message';
if (!fs.existsSync(CACHE_DIR)) { if (!fs.existsSync(CACHE_DIR)) {
fs.mkdirSync(CACHE_DIR, { recursive: true }); fs.mkdirSync(CACHE_DIR, { recursive: true });
@@ -58,6 +59,7 @@ const agent = new Agent({
if ( if (
errorCode === 'ERR_UNESCAPED_CHARACTERS' errorCode === 'ERR_UNESCAPED_CHARACTERS'
|| errorCode === 'UND_ERR_DESTROYED' || errorCode === 'UND_ERR_DESTROYED'
// eslint-disable-next-line sukka/prefer-foxts-error-util -- we already know this is Error type
|| err.message === 'Request path contains unescaped characters' || err.message === 'Request path contains unescaped characters'
|| err.name === 'AbortError' || err.name === 'AbortError'
) { ) {
@@ -277,7 +279,7 @@ export async function requestWithLog(url: string, opt?: Parameters<typeof undici
if (isAbortErrorLike(err)) { if (isAbortErrorLike(err)) {
console.log(picocolors.gray('[fetch abort]'), url); console.log(picocolors.gray('[fetch abort]'), url);
} else { } else {
console.log(picocolors.gray('[fetch fail]'), url, { name: err instanceof Error ? err.name : undefined }, err); console.log(picocolors.gray('[fetch fail]'), url, { name: isErrorLikeObject(err) ? err.name : undefined }, err);
} }
throw err; throw err;

View File

@@ -113,9 +113,8 @@ export class FileOutput {
} }
bulkAddDomain(domains: Array<string | null>) { bulkAddDomain(domains: Array<string | null>) {
let d: string | null;
for (let i = 0, len = domains.length; i < len; i++) { for (let i = 0, len = domains.length; i < len; i++) {
d = domains[i]; const d = domains[i];
if (d !== null) { if (d !== null) {
this.domainTrie.add(d, false, null, 0); this.domainTrie.add(d, false, null, 0);
} }

View File

@@ -57,7 +57,6 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
path: childRelativeToRoot path: childRelativeToRoot
}; };
node.push(newNode); node.push(newNode);
continue;
} }
} }
}; };

View File

@@ -285,10 +285,9 @@ abstract class Triebase<Meta = unknown> {
const suffixStack: string[][] = [initialSuffix]; const suffixStack: string[][] = [initialSuffix];
let node: TrieNode<Meta> = initialNode; let node: TrieNode<Meta> = initialNode;
let r;
do { do {
r = dfsImpl(nodeStack, suffixStack); const r = dfsImpl(nodeStack, suffixStack);
node = r[0]!; node = r[0]!;
const suffix = r[1]; const suffix = r[1];
@@ -588,20 +587,20 @@ export class HostnameSmolTrie<Meta = unknown> extends Triebase<Meta> {
} }
function cleanUpEmptyTrailNode(node: TrieNode<unknown>) { function cleanUpEmptyTrailNode(node: TrieNode<unknown>) {
if ( let current = node;
while (
// the current node is not an "end node", a.k.a. not the start of a domain // the current node is not an "end node", a.k.a. not the start of a domain
missingBit(node[0], START) missingBit(current[0], START)
// also no leading "." (no subdomain) // also no leading "." (no subdomain)
&& missingBit(node[0], INCLUDE_ALL_SUBDOMAIN) && missingBit(current[0], INCLUDE_ALL_SUBDOMAIN)
// child is empty // child is empty
&& node[2].size === 0 && current[2].size === 0
// has parent: we need to detele the cureent node from the parent // has parent: we need to delete the current node from the parent
// we also need to recursively clean up the parent node // we also need to clean up the parent node
&& node[1] && current[1]
) { ) {
node[1][2].delete(node[3]); current[1][2].delete(current[3]);
// finish of the current stack current = current[1];
return cleanUpEmptyTrailNode(node[1]);
} }
} }

View File

@@ -162,7 +162,6 @@ export class ClashClassicRuleSet extends BaseWriteStrategy {
} }
if (v === 6) { if (v === 6) {
this.result.push(`SRC-IP-CIDR6,${value}/128`); this.result.push(`SRC-IP-CIDR6,${value}/128`);
continue;
} }
} }
} }

View File

@@ -92,11 +92,11 @@ export async function parseGfwList() {
gfwListTrie.add('.' + line.slice(2)); gfwListTrie.add('.' + line.slice(2));
continue; continue;
} }
if (line.startsWith('|')) { if (line[0] === '|') {
gfwListTrie.add(line.slice(1)); gfwListTrie.add(line.slice(1));
continue; continue;
} }
if (line.startsWith('.')) { if (line[0] === '.') {
gfwListTrie.add(line); gfwListTrie.add(line);
continue; continue;
} }
@@ -104,7 +104,6 @@ export async function parseGfwList() {
if (d) { if (d) {
totalGfwSize++; totalGfwSize++;
gfwListTrie.add(d); gfwListTrie.add(d);
continue;
} }
} }
for await (const l of await fetchRemoteTextByLine('https://raw.githubusercontent.com/Loyalsoldier/cn-blocked-domain/release/domains.txt', true)) { for await (const l of await fetchRemoteTextByLine('https://raw.githubusercontent.com/Loyalsoldier/cn-blocked-domain/release/domains.txt', true)) {

View File

@@ -21,8 +21,8 @@ import { MARKER_DOMAIN } from './constants/description';
} }
}, 'ruleset'); }, 'ruleset');
await runAgainstSourceFile(path.join(OUTPUT_SURGE_DIR, 'non_ip', 'global.conf'), (domain, includeAllSubDomain) => { await runAgainstSourceFile(path.join(OUTPUT_SURGE_DIR, 'non_ip', 'global.conf'), (domain, includeAllSubdomain) => {
trie.add(domain, includeAllSubDomain); trie.add(domain, includeAllSubdomain);
}, 'ruleset'); }, 'ruleset');
ICP_TLD.forEach(tld => trie.whitelist(tld, true)); ICP_TLD.forEach(tld => trie.whitelist(tld, true));

View File

@@ -28,7 +28,7 @@ import { xxhash3 } from 'hash-wasm';
if (file.startsWith('domainset' + path.sep)) { if (file.startsWith('domainset' + path.sep)) {
await runHash((await readFileIntoProcessedArray(fullpath)).map(i => (i[0] === '.' ? i.slice(1) : i))); await runHash((await readFileIntoProcessedArray(fullpath)).map(i => (i[0] === '.' ? i.slice(1) : i)));
} else if (file.startsWith('non_ip' + path.sep)) { } else if (file.startsWith('non_ip' + path.sep)) {
await runHash((await readFileIntoProcessedArray(fullpath)).map(i => i.split(',')[1])); await runHash((await readFileIntoProcessedArray(fullpath)).map(i => i.split(',', 2)[1]));
} }
} }

View File

@@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
window._gaq = window._gaq || { window._gaq ||= {
push() { push() {
// noop // noop
} }