mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
chore(lint): replace ESLint with Oxlint and clear anti-slop findings
This commit is contained in:
1 parent
c6c13335e5
commit
b625acfc0c
1083 files changed
+67089
-80136
No files matched your search
@@ -16,8 +16,9 @@ const ENV_EXPRESSION_PATTERN = /\$\{\{([\s\S]*?)\}\}/g
|
||||
const ENV_EXPRESSION_REFERENCE_PATTERN = /^\s*(secrets|vars)\.(\S+)\s*$/i
|
||||
|
||||
function toReference(match: RegExpExecArray): EnvExpressionReference {
|
||||
const context = (match[1] ?? '').toLowerCase()
|
||||
return {
|
||||
context: (match[1] ?? '').toLowerCase() as EnvExpressionContext,
|
||||
context: context === 'vars' ? 'vars' : 'secrets',
|
||||
name: (match[2] ?? '').toUpperCase(),
|
||||
}
|
||||
}
|
||||
@@ -28,11 +29,6 @@ function matchReference(inner: string): EnvExpressionReference | null {
|
||||
return toReference(match)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses every `${{ ... }}` occurrence in a value, accepting only
|
||||
* `secrets.<NAME>` and `vars.<NAME>` references. The context is
|
||||
* case-insensitive and the name is normalized to upper case.
|
||||
*/
|
||||
export function parseEnvExpressionReferences(value: string): ParseEnvExpressionReferencesResult {
|
||||
const references: EnvExpressionReference[] = []
|
||||
|
||||
@@ -50,16 +46,10 @@ export function parseEnvExpressionReferences(value: string): ParseEnvExpressionR
|
||||
return { ok: true, references }
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces every `${{ secrets.<NAME> }}` / `${{ vars.<NAME> }}` occurrence with
|
||||
* the value returned by `lookup`. A reference that resolves to `undefined`
|
||||
* becomes an empty string, matching GitHub Actions. Unsupported expressions and
|
||||
* expressions with an invalid name are left untouched.
|
||||
*/
|
||||
export function interpolateEnvExpressions(
|
||||
value: string,
|
||||
lookup: (reference: EnvExpressionReference) => string | undefined,
|
||||
): { value: string } {
|
||||
) {
|
||||
const interpolated = value.replace(ENV_EXPRESSION_PATTERN, (expression, inner: string) => {
|
||||
const reference = matchReference(inner)
|
||||
if (!reference) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from './env-expressions'
|
||||
export * from './json'
|
||||
export * from './jsonc'
|
||||
export * from './record'
|
||||
export * from './repo'
|
||||
export * from './sandbox-command'
|
||||
export * from './semver'
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export type JsonValue = null | boolean | number | string | JsonValue[] | JsonObject
|
||||
|
||||
export interface JsonObject {
|
||||
[key: string]: JsonValue
|
||||
}
|
||||
|
||||
export interface JsonContainer {
|
||||
[key: string]: JsonValue | undefined
|
||||
}
|
||||
|
||||
export const JsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>
|
||||
z.union([
|
||||
z.null(),
|
||||
z.boolean(),
|
||||
z.number(),
|
||||
z.string(),
|
||||
z.array(JsonValueSchema),
|
||||
JsonObjectSchema,
|
||||
]),
|
||||
)
|
||||
|
||||
export const JsonObjectSchema: z.ZodType<JsonObject> = z.record(z.string(), JsonValueSchema)
|
||||
|
||||
export const JsonContainerSchema: z.ZodType<JsonContainer> = z.record(
|
||||
z.string(),
|
||||
z.union([JsonValueSchema, z.undefined()]),
|
||||
)
|
||||
|
||||
export function isJsonContainer(value: JsonValue | JsonContainer | undefined): value is JsonContainer {
|
||||
return JsonContainerSchema.safeParse(value).success
|
||||
}
|
||||
|
||||
export function parseJsonObject(value: JsonValue | undefined): JsonObject | null {
|
||||
const parsed = JsonObjectSchema.safeParse(value)
|
||||
return parsed.success ? parsed.data : null
|
||||
}
|
||||
|
||||
export function parseJsonString(value: JsonValue | undefined): string | null {
|
||||
const parsed = z.string().safeParse(value)
|
||||
return parsed.success ? parsed.data : null
|
||||
}
|
||||
|
||||
export function parseJsonText(text: string): JsonValue | null {
|
||||
try {
|
||||
const parsed = JsonValueSchema.safeParse(JSON.parse(text))
|
||||
return parsed.success ? parsed.data : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
+19
-18
@@ -1,6 +1,7 @@
|
||||
import { parse as parseJsoncLib, parseTree, findNodeAtLocation, type ParseError, type JSONPath } from 'jsonc-parser/lib/esm/main.js'
|
||||
import { JsonValueSchema, type JsonValue } from './json'
|
||||
|
||||
export function parseJsonc<T = unknown>(content: string): T {
|
||||
export function parseJsonc(content: string): JsonValue {
|
||||
const errors: ParseError[] = []
|
||||
const result = parseJsoncLib(content, errors, {
|
||||
allowTrailingComma: true,
|
||||
@@ -13,7 +14,7 @@ export function parseJsonc<T = unknown>(content: string): T {
|
||||
throw new SyntaxError(message)
|
||||
}
|
||||
|
||||
return result as T
|
||||
return JsonValueSchema.parse(result)
|
||||
}
|
||||
|
||||
export function getParseErrorMessage(error: number, content: string, offset: number | undefined): string {
|
||||
@@ -28,25 +29,25 @@ export function getParseErrorMessage(error: number, content: string, offset: num
|
||||
return `${message} at line ${line}, column ${col}`
|
||||
}
|
||||
|
||||
function getErrorMessageByCode(error: number): string {
|
||||
const errorMessages: Record<number, string> = {
|
||||
1: 'Invalid symbol',
|
||||
2: 'Invalid number format',
|
||||
3: 'Property name expected',
|
||||
4: 'Value expected',
|
||||
5: 'Colon expected',
|
||||
6: 'Comma expected',
|
||||
7: 'Trailing comma not allowed',
|
||||
8: 'Unexpected end of input',
|
||||
9: 'Invalid comment',
|
||||
}
|
||||
const JSONC_ERROR_MESSAGES = new Map<number, string>([
|
||||
[1, 'Invalid symbol'],
|
||||
[2, 'Invalid number format'],
|
||||
[3, 'Property name expected'],
|
||||
[4, 'Value expected'],
|
||||
[5, 'Colon expected'],
|
||||
[6, 'Comma expected'],
|
||||
[7, 'Trailing comma not allowed'],
|
||||
[8, 'Unexpected end of input'],
|
||||
[9, 'Invalid comment'],
|
||||
])
|
||||
|
||||
return errorMessages[error] || 'Invalid JSONC'
|
||||
function getErrorMessageByCode(error: number): string {
|
||||
return JSONC_ERROR_MESSAGES.get(error) || 'Invalid JSONC'
|
||||
}
|
||||
|
||||
export function parseJsoncErrorLine(error: unknown): number | null {
|
||||
if (!(error instanceof SyntaxError)) return null
|
||||
const match = error.message.match(/at line (\d+)/)
|
||||
export function parseJsoncErrorLine(cause: unknown): number | null {
|
||||
if (!(cause instanceof SyntaxError)) return null
|
||||
const match = cause.message.match(/at line (\d+)/)
|
||||
return match ? Number(match[1]) : null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
||||
}
|
||||
@@ -93,15 +93,8 @@ export function getBranchNameError(name: string): string | null {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Who owns a repo worktree: OpenCode, a schedule, or nobody (a plain git worktree).
|
||||
*/
|
||||
export type RepoWorktreeSource = 'opencode' | 'schedule' | 'git'
|
||||
|
||||
/**
|
||||
* The schedule a worktree belongs to. `runId` is null for the schedule's shared worktree,
|
||||
* `inUse` is true while a running run works in it, and `name` is the schedule's display name.
|
||||
*/
|
||||
export interface RepoWorktreeSchedule {
|
||||
repoId: number
|
||||
jobId: number
|
||||
@@ -110,10 +103,6 @@ export interface RepoWorktreeSchedule {
|
||||
name: string
|
||||
}
|
||||
|
||||
/**
|
||||
* A repository visible from another repository in the same project: the repo itself, a plain
|
||||
* git or OpenCode worktree, or a schedule worktree.
|
||||
*/
|
||||
export type RepoSibling = Repo & {
|
||||
currentBranch?: string
|
||||
worktreeSource?: RepoWorktreeSource
|
||||
|
||||
+26
-10
@@ -1,3 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export type SemverPrereleaseIdentifier = number | string
|
||||
|
||||
export interface Semver {
|
||||
@@ -27,26 +29,40 @@ export function parseSemver(version: string): Semver | null {
|
||||
}
|
||||
}
|
||||
|
||||
type PrereleaseIdentifierKind =
|
||||
| { kind: 'numeric'; value: number }
|
||||
| { kind: 'text'; value: string }
|
||||
|
||||
function classifyPrereleaseIdentifier(identifier: SemverPrereleaseIdentifier): PrereleaseIdentifierKind {
|
||||
const numeric = z.number().safeParse(identifier)
|
||||
return numeric.success ? { kind: 'numeric', value: numeric.data } : { kind: 'text', value: String(identifier) }
|
||||
}
|
||||
|
||||
function comparePrereleaseIdentifiers(
|
||||
left: SemverPrereleaseIdentifier[],
|
||||
right: SemverPrereleaseIdentifier[],
|
||||
): number {
|
||||
if (left.length === 0 || right.length === 0) return right.length - left.length
|
||||
|
||||
for (let index = 0; index < Math.max(left.length, right.length); index++) {
|
||||
const leftIdentifier = left[index]
|
||||
const rightIdentifier = right[index]
|
||||
const leftIdentifiers = left.map(classifyPrereleaseIdentifier)
|
||||
const rightIdentifiers = right.map(classifyPrereleaseIdentifier)
|
||||
|
||||
for (let index = 0; index < Math.max(leftIdentifiers.length, rightIdentifiers.length); index++) {
|
||||
const leftIdentifier = leftIdentifiers[index]
|
||||
const rightIdentifier = rightIdentifiers[index]
|
||||
|
||||
if (leftIdentifier === undefined) return -1
|
||||
if (rightIdentifier === undefined) return 1
|
||||
if (leftIdentifier === rightIdentifier) continue
|
||||
|
||||
const leftNumeric = typeof leftIdentifier === 'number'
|
||||
const rightNumeric = typeof rightIdentifier === 'number'
|
||||
if (leftNumeric && rightNumeric) return leftIdentifier > rightIdentifier ? 1 : -1
|
||||
if (leftNumeric) return -1
|
||||
if (rightNumeric) return 1
|
||||
return leftIdentifier > rightIdentifier ? 1 : -1
|
||||
if (leftIdentifier.kind === 'numeric' && rightIdentifier.kind === 'numeric') {
|
||||
if (leftIdentifier.value !== rightIdentifier.value) return leftIdentifier.value > rightIdentifier.value ? 1 : -1
|
||||
continue
|
||||
}
|
||||
if (leftIdentifier.kind === 'text' && rightIdentifier.kind === 'text') {
|
||||
if (leftIdentifier.value !== rightIdentifier.value) return leftIdentifier.value > rightIdentifier.value ? 1 : -1
|
||||
continue
|
||||
}
|
||||
return leftIdentifier.kind === 'numeric' ? -1 : 1
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
@@ -92,7 +92,12 @@ export function parseDiffLines(diff: string): DiffLine[] {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function countDiffLineChanges(text: string): { added: number; removed: number } {
|
||||
export interface DiffLineChangeCount {
|
||||
added: number
|
||||
removed: number
|
||||
}
|
||||
|
||||
export function countDiffLineChanges(text: string): DiffLineChangeCount {
|
||||
let added = 0;
|
||||
let removed = 0;
|
||||
for (const line of parseDiffLines(text)) {
|
||||
@@ -181,17 +186,17 @@ function stripDiffPathPrefix(path: string, prefix: string): string {
|
||||
return path.startsWith(prefix) ? path.slice(prefix.length) : path;
|
||||
}
|
||||
|
||||
const GIT_C_ESCAPES: Record<string, number> = {
|
||||
a: 0x07,
|
||||
b: 0x08,
|
||||
f: 0x0c,
|
||||
n: 0x0a,
|
||||
r: 0x0d,
|
||||
t: 0x09,
|
||||
v: 0x0b,
|
||||
"\\": 0x5c,
|
||||
'"': 0x22,
|
||||
};
|
||||
const GIT_C_ESCAPES = new Map<string, number>([
|
||||
["a", 0x07],
|
||||
["b", 0x08],
|
||||
["f", 0x0c],
|
||||
["n", 0x0a],
|
||||
["r", 0x0d],
|
||||
["t", 0x09],
|
||||
["v", 0x0b],
|
||||
["\\", 0x5c],
|
||||
['"', 0x22],
|
||||
])
|
||||
|
||||
function parseDiffPathToken(raw: string, prefix: string): string {
|
||||
const token = raw.startsWith('"') ? decodeGitQuotedPath(raw) : raw.split("\t")[0]!;
|
||||
@@ -219,7 +224,7 @@ function decodeGitQuotedPath(raw: string): string {
|
||||
if (next === undefined) {
|
||||
break;
|
||||
}
|
||||
const escaped = GIT_C_ESCAPES[next];
|
||||
const escaped = GIT_C_ESCAPES.get(next);
|
||||
bytes.push(...(escaped === undefined ? encoder.encode(next) : [escaped]));
|
||||
index += 2;
|
||||
continue;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
/** Trims a URL and removes its trailing slashes. */
|
||||
export function trimUrlTrailingSlashes(url: string): string {
|
||||
return url.trim().replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
/** Parses a value into a URL, or returns null when it is not an absolute http(s) URL. */
|
||||
export function parseHttpUrl(value: string): URL | null {
|
||||
let url: URL
|
||||
try {
|
||||
@@ -15,13 +13,11 @@ export function parseHttpUrl(value: string): URL | null {
|
||||
return url
|
||||
}
|
||||
|
||||
/** Reports whether two URLs share the same origin; false when either URL is invalid. */
|
||||
export function haveSameUrlOrigin(first: string, second: string): boolean {
|
||||
const origin = readUrlOrigin(first)
|
||||
return origin !== null && origin === readUrlOrigin(second)
|
||||
}
|
||||
|
||||
/** Reports whether a hostname refers to the local machine. */
|
||||
export function isLoopbackHost(hostname: string): boolean {
|
||||
const host = normalizeHostname(hostname)
|
||||
if (host === 'localhost' || host === '::1') return true
|
||||
@@ -29,7 +25,6 @@ export function isLoopbackHost(hostname: string): boolean {
|
||||
return octets !== null && octets[0] === 127
|
||||
}
|
||||
|
||||
/** Reports whether a hostname is an RFC 1918, link-local, or CGNAT address. */
|
||||
export function isPrivateNetworkHost(hostname: string): boolean {
|
||||
const host = normalizeHostname(hostname)
|
||||
const octets = parseIpv4Octets(host)
|
||||
@@ -48,7 +43,6 @@ export function isPrivateNetworkHost(hostname: string): boolean {
|
||||
return firstHextet >= 0xfc00 && firstHextet <= 0xfdff
|
||||
}
|
||||
|
||||
/** Reports whether a URL uses plain HTTP on a host other than loopback or a private network. */
|
||||
export function isPublicPlainHttpUrl(url: URL): boolean {
|
||||
return (
|
||||
url.protocol === 'http:' &&
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const UNKNOWN_DEVICE = 'Unknown device'
|
||||
const RAW_USER_AGENT_MAX_LENGTH = 80
|
||||
|
||||
/** Describes a user agent as "browser on platform", falling back to the raw string. */
|
||||
export function describeUserAgent(userAgent: string | null | undefined): string {
|
||||
const value = userAgent?.trim()
|
||||
if (!value) return UNKNOWN_DEVICE
|
||||
|
||||
Reference in new issue
Block a user