Housekeeping & Make ESLint Happy

This commit is contained in:
SukkaW
2026-07-27 02:59:21 +08:00
parent 86f55a4929
commit 1b000a8cea
8 changed files with 226 additions and 168 deletions

View File

@@ -213,7 +213,7 @@ export async function fetchAssets(
return Array.fromAsync(stream);
});
if (arr.length < 1 && !allowEmpty) {
if (!allowEmpty && arr.length < 1) {
throw new ResponseError(res, url, 'empty response w/o 304');
}

View File

@@ -638,6 +638,7 @@ function onHostname(
if (
(char >= 97 && char <= 122) // 97-122 `a-z`
// eslint-disable-next-line sukka/unicorn/prefer-simple-condition-first -- dot is less common than char
|| char === 46 // 46 `.`
|| char === 45 // 45 `-`
|| (char >= 48 && char <= 57) // 48-57 `0-9`

View File

@@ -409,16 +409,16 @@ export class FileOutput {
this.strategiesWritten = true;
if (this.strategies.filter(not(false)).length === 0) {
throw new Error('No strategies to write ' + this.id);
}
// We use both DOMAIN-KEYWORD and whitelisted keyword to whitelist DOMAIN and DOMAIN-SUFFIX
const kwfilter = createKeywordFilter(
Array.from(this.domainKeywords)
.concat(Array.from(this.whitelistKeywords))
);
if (this.strategies.filter(not(false)).length === 0) {
throw new Error('No strategies to write ' + this.id);
}
const strategiesLen = this.strategies.length;
const domainEntries: Array<[domain: string, subdomain: boolean]> = [];

View File

@@ -19,7 +19,7 @@
* matters.
*/
import { fnv1a52 } from 'foxts/fnv1a52';
import { fnv1a52 } from 'fnv1a52';
import process from 'node:process';
export interface ShardConfig {

View File

@@ -9,6 +9,10 @@ import { OUTPUT_MODULES_DIR, OUTPUT_SURGE_DIR } from '../../constants/dir';
import { withBannerArray, withIdentityContent } from '../misc';
import { MARKER_DOMAIN } from '../../constants/description';
const rChar = /([a-z])\?/g;
const rWildcard = /\*+/g;
const rPattern = /\((?:([^()|]+)\|)+([^()|]*)\)/g;
export class SurgeDomainSet extends BaseWriteStrategy {
public readonly name = 'surge domainset';
@@ -204,15 +208,15 @@ export class SurgeMitmSgmodule extends BaseWriteStrategy {
// pre process regex
.replaceAll(String.raw`\.`, '.')
.replaceAll('.+', '*')
.replaceAll(/([a-z])\?/g, '($1|)')
.replaceAll(rChar, '($1|)')
// convert regex to surge hostlist syntax
.replaceAll('([a-z])', '?')
.replaceAll(String.raw`\d`, '?')
.replaceAll(/\*+/g, '*');
.replaceAll(rWildcard, '*');
let processed: string[] = [potentialHostname];
const matches = [...potentialHostname.matchAll(/\((?:([^()|]+)\|)+([^()|]*)\)/g)];
const matches = [...potentialHostname.matchAll(rPattern)];
if (matches.length > 0) {
const replaceVariant = (combinations: string[], fullMatch: string, options: string[]): string[] => {