chore: enforce brackets for if clause and for/while loops
This commit is contained in:
@@ -171,7 +171,9 @@ export class CharacterComparisonEngine {
|
||||
|
||||
for (let sIdx = start.segmentIndex; sIdx <= end.segmentIndex; sIdx++) {
|
||||
const segmentText = this.#preparedA!.segments[sIdx];
|
||||
if (segmentText === undefined) continue;
|
||||
if (segmentText === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// PERFORMANCE: Reuse segmenter results if possible, but for now just optimize the loop
|
||||
const graphemes = Array.from(this.#segmenter.segment(segmentText), s => s.segment);
|
||||
@@ -242,7 +244,9 @@ export class CharacterComparisonEngine {
|
||||
const line = this.#lastResult.lines[lineIndex];
|
||||
const char = line.chars[charIndex];
|
||||
|
||||
if (!char) return { proximity: 0, isPast: false };
|
||||
if (!char) {
|
||||
return { proximity: 0, isPast: false };
|
||||
}
|
||||
|
||||
// Center the comparison on the unified width
|
||||
// In the UI, lines are centered. So we need to calculate the global X.
|
||||
@@ -279,9 +283,15 @@ export class CharacterComparisonEngine {
|
||||
|
||||
unified.breakableFitAdvances = intA.breakableFitAdvances.map((advA: number[] | null, i: number) => {
|
||||
const advB = intB.breakableFitAdvances[i];
|
||||
if (!advA && !advB) return null;
|
||||
if (!advA) return advB;
|
||||
if (!advB) return advA;
|
||||
if (!advA && !advB) {
|
||||
return null;
|
||||
}
|
||||
if (!advA) {
|
||||
return advB;
|
||||
}
|
||||
if (!advB) {
|
||||
return advA;
|
||||
}
|
||||
|
||||
return advA.map((w: number, j: number) => Math.max(w, advB[j]));
|
||||
});
|
||||
|
||||
@@ -127,7 +127,9 @@ export class TextLayoutEngine {
|
||||
// Both cursors are grapheme-level: start is inclusive, end is exclusive.
|
||||
for (let sIdx = start.segmentIndex; sIdx <= end.segmentIndex; sIdx++) {
|
||||
const segmentText = prepared.segments[sIdx];
|
||||
if (segmentText === undefined) continue;
|
||||
if (segmentText === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const graphemes = Array.from(this.#segmenter.segment(segmentText), s => s.segment);
|
||||
const advances = breakableFitAdvances[sIdx];
|
||||
|
||||
@@ -150,7 +150,9 @@ export function createResponsiveManager(customBreakpoints?: Partial<Breakpoints>
|
||||
* @returns Cleanup function to remove listeners
|
||||
*/
|
||||
function init() {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleResize = () => {
|
||||
width = window.innerWidth;
|
||||
|
||||
@@ -175,7 +175,9 @@ export function createVirtualizer<T>(
|
||||
const { count, data } = options;
|
||||
// Implicit dependency
|
||||
const v = _version;
|
||||
if (count === 0 || containerHeight === 0 || !data) return [];
|
||||
if (count === 0 || containerHeight === 0 || !data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const overscan = options.overscan ?? 5;
|
||||
|
||||
@@ -264,7 +266,9 @@ export function createVirtualizer<T>(
|
||||
containerHeight = window.innerHeight;
|
||||
|
||||
const handleScroll = () => {
|
||||
if (rafId !== null) return;
|
||||
if (rafId !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(() => {
|
||||
// Get current position of element relative to viewport
|
||||
@@ -323,7 +327,9 @@ export function createVirtualizer<T>(
|
||||
};
|
||||
|
||||
const resizeObserver = new ResizeObserver(([entry]) => {
|
||||
if (entry) containerHeight = entry.contentRect.height;
|
||||
if (entry) {
|
||||
containerHeight = entry.contentRect.height;
|
||||
}
|
||||
});
|
||||
|
||||
node.addEventListener('scroll', handleScroll, { passive: true });
|
||||
@@ -423,7 +429,9 @@ export function createVirtualizer<T>(
|
||||
* ```
|
||||
*/
|
||||
function scrollToIndex(index: number, align: 'start' | 'center' | 'end' | 'auto' = 'auto') {
|
||||
if (!elementRef || index < 0 || index >= options.count) return;
|
||||
if (!elementRef || index < 0 || index >= options.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemStart = offsets[index];
|
||||
const itemSize = measuredSizes[index] ?? options.estimateSize(index);
|
||||
@@ -431,16 +439,24 @@ export function createVirtualizer<T>(
|
||||
const { useWindowScroll } = optionsGetter();
|
||||
|
||||
if (useWindowScroll) {
|
||||
if (align === 'center') target = itemStart - window.innerHeight / 2 + itemSize / 2;
|
||||
if (align === 'end') target = itemStart - window.innerHeight + itemSize;
|
||||
if (align === 'center') {
|
||||
target = itemStart - window.innerHeight / 2 + itemSize / 2;
|
||||
}
|
||||
if (align === 'end') {
|
||||
target = itemStart - window.innerHeight + itemSize;
|
||||
}
|
||||
|
||||
// Add container offset to target to get absolute document position
|
||||
const absoluteTarget = target + elementOffsetTop;
|
||||
|
||||
window.scrollTo({ top: absoluteTarget, behavior: 'smooth' });
|
||||
} else {
|
||||
if (align === 'center') target = itemStart - containerHeight / 2 + itemSize / 2;
|
||||
if (align === 'end') target = itemStart - containerHeight + itemSize;
|
||||
if (align === 'center') {
|
||||
target = itemStart - containerHeight / 2 + itemSize / 2;
|
||||
}
|
||||
if (align === 'end') {
|
||||
target = itemStart - containerHeight + itemSize;
|
||||
}
|
||||
|
||||
elementRef.scrollTo({ top: target, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ export function smoothScroll(node: HTMLAnchorElement) {
|
||||
event.preventDefault();
|
||||
|
||||
const hash = node.getAttribute('href');
|
||||
if (!hash || hash === '#') return;
|
||||
if (!hash || hash === '#') {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetElement = document.querySelector(hash);
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ export function throttle<T extends (...args: any[]) => any>(
|
||||
fn(...args);
|
||||
} else {
|
||||
// Schedule for end of wait period (trailing edge)
|
||||
if (timeoutId) clearTimeout(timeoutId);
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
timeoutId = setTimeout(() => {
|
||||
lastCall = Date.now();
|
||||
fn(...args);
|
||||
|
||||
@@ -66,7 +66,9 @@ let open = $state(false);
|
||||
// Smart value formatting matching the Figma design
|
||||
const formattedValue = $derived(() => {
|
||||
const v = control.value;
|
||||
if (Number.isInteger(v)) return String(v);
|
||||
if (Number.isInteger(v)) {
|
||||
return String(v);
|
||||
}
|
||||
return control.step < 0.1 ? v.toFixed(2) : v.toFixed(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -61,7 +61,9 @@ const style = $derived.by(() => {
|
||||
|
||||
// Calculate horizontal constraints based on region
|
||||
const regionStyleStr = $derived(() => {
|
||||
if (region === 'full') return '';
|
||||
if (region === 'full') {
|
||||
return '';
|
||||
}
|
||||
const side = region === 'left' ? 'left' : 'right';
|
||||
return `position: absolute; ${side}: 0; width: ${regionWidth}%; top: 0; bottom: 0;`;
|
||||
});
|
||||
|
||||
@@ -136,7 +136,9 @@ const estimatedTotalSize = $derived.by(() => {
|
||||
|
||||
// Add estimated size for unloaded rows
|
||||
const unloadedRows = totalRows - rowCount;
|
||||
if (unloadedRows <= 0) return loadedSize;
|
||||
if (unloadedRows <= 0) {
|
||||
return loadedSize;
|
||||
}
|
||||
|
||||
// Estimate the size of unloaded rows
|
||||
const estimateFn = typeof itemHeight === 'function'
|
||||
|
||||
Reference in New Issue
Block a user