chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
findFenceSpanAt,
|
||||
isSafeFenceBreak,
|
||||
parseFenceSpans,
|
||||
} from "../markdown/fences.js";
|
||||
import { findFenceSpanAt, isSafeFenceBreak, parseFenceSpans } from "../markdown/fences.js";
|
||||
|
||||
export type BlockReplyChunking = {
|
||||
minChars: number;
|
||||
@@ -61,10 +57,7 @@ export class EmbeddedBlockChunker {
|
||||
return;
|
||||
}
|
||||
|
||||
while (
|
||||
this.#buffer.length >= minChars ||
|
||||
(force && this.#buffer.length > 0)
|
||||
) {
|
||||
while (this.#buffer.length >= minChars || (force && this.#buffer.length > 0)) {
|
||||
const breakResult =
|
||||
force && this.#buffer.length <= maxChars
|
||||
? this.#pickSoftBreakIndex(this.#buffer, 1)
|
||||
@@ -80,9 +73,7 @@ export class EmbeddedBlockChunker {
|
||||
const breakIdx = breakResult.index;
|
||||
let rawChunk = this.#buffer.slice(0, breakIdx);
|
||||
if (rawChunk.trim().length === 0) {
|
||||
this.#buffer = stripLeadingNewlines(
|
||||
this.#buffer.slice(breakIdx),
|
||||
).trimStart();
|
||||
this.#buffer = stripLeadingNewlines(this.#buffer.slice(breakIdx)).trimStart();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -118,10 +109,7 @@ export class EmbeddedBlockChunker {
|
||||
}
|
||||
|
||||
#pickSoftBreakIndex(buffer: string, minCharsOverride?: number): BreakResult {
|
||||
const minChars = Math.max(
|
||||
1,
|
||||
Math.floor(minCharsOverride ?? this.#chunking.minChars),
|
||||
);
|
||||
const minChars = Math.max(1, Math.floor(minCharsOverride ?? this.#chunking.minChars));
|
||||
if (buffer.length < minChars) return { index: -1 };
|
||||
const fenceSpans = parseFenceSpans(buffer);
|
||||
const preference = this.#chunking.breakPreference ?? "paragraph";
|
||||
@@ -144,10 +132,7 @@ export class EmbeddedBlockChunker {
|
||||
if (preference === "paragraph" || preference === "newline") {
|
||||
let newlineIdx = buffer.indexOf("\n");
|
||||
while (newlineIdx !== -1) {
|
||||
if (
|
||||
newlineIdx >= minChars &&
|
||||
isSafeFenceBreak(fenceSpans, newlineIdx)
|
||||
) {
|
||||
if (newlineIdx >= minChars && isSafeFenceBreak(fenceSpans, newlineIdx)) {
|
||||
return { index: newlineIdx };
|
||||
}
|
||||
newlineIdx = buffer.indexOf("\n", newlineIdx + 1);
|
||||
@@ -172,10 +157,7 @@ export class EmbeddedBlockChunker {
|
||||
}
|
||||
|
||||
#pickBreakIndex(buffer: string, minCharsOverride?: number): BreakResult {
|
||||
const minChars = Math.max(
|
||||
1,
|
||||
Math.floor(minCharsOverride ?? this.#chunking.minChars),
|
||||
);
|
||||
const minChars = Math.max(1, Math.floor(minCharsOverride ?? this.#chunking.minChars));
|
||||
const maxChars = Math.max(minChars, Math.floor(this.#chunking.maxChars));
|
||||
if (buffer.length < minChars) return { index: -1 };
|
||||
const window = buffer.slice(0, Math.min(maxChars, buffer.length));
|
||||
|
||||
Reference in New Issue
Block a user