chore(lint): hoist top-level inline arrays in diff-viewer

This commit is contained in:
Mohamed Boudra
2026-04-24 02:04:01 +07:00
parent 243c859709
commit 1f4f0c020c
2 changed files with 107 additions and 97 deletions

View File

@@ -31,6 +31,20 @@ export function DiffViewer({
[],
);
const outerScrollStyle = React.useMemo(
() => [
styles.verticalScroll,
maxHeight !== undefined && { maxHeight },
fillAvailableHeight && styles.fillHeight,
webScrollbarStyle,
],
[maxHeight, fillAvailableHeight, webScrollbarStyle],
);
const linesContainerStyle = React.useMemo(
() => [styles.linesContainer, scrollViewWidth > 0 && { minWidth: scrollViewWidth }],
[scrollViewWidth],
);
if (!diffLines.length) {
return (
<View style={styles.emptyState}>
@@ -41,12 +55,7 @@ export function DiffViewer({
return (
<ScrollView
style={[
styles.verticalScroll,
maxHeight !== undefined && { maxHeight },
fillAvailableHeight && styles.fillHeight,
webScrollbarStyle,
]}
style={outerScrollStyle}
contentContainerStyle={styles.verticalContent}
nestedScrollEnabled
showsVerticalScrollIndicator
@@ -59,7 +68,7 @@ export function DiffViewer({
contentContainerStyle={styles.horizontalContent}
onLayout={handleInnerLayout}
>
<View style={[styles.linesContainer, scrollViewWidth > 0 && { minWidth: scrollViewWidth }]}>
<View style={linesContainerStyle}>
{diffLines.map((line, index) => (
<View
key={`${line.type}-${index}`}

View File

@@ -193,6 +193,24 @@ function matchesPattern(filename: string, pattern: string): boolean {
return filename === pattern;
}
async function isExistingFile(fullPath: string): Promise<boolean> {
try {
const stats = await stat(fullPath);
return stats.isFile();
} catch {
return false;
}
}
async function isExistingDirectory(fullPath: string): Promise<boolean> {
try {
const stats = await stat(fullPath);
return stats.isDirectory();
} catch {
return false;
}
}
async function findIconInDir(dir: string, patterns: string[]): Promise<string | null> {
let entries: string[];
try {
@@ -204,16 +222,12 @@ async function findIconInDir(dir: string, patterns: string[]): Promise<string |
// Check each pattern in order of priority
for (const pattern of patterns) {
for (const entry of entries) {
if (matchesPattern(entry, pattern)) {
const fullPath = join(dir, entry);
try {
const stats = await stat(fullPath);
if (stats.isFile()) {
return fullPath;
}
} catch {
// File may have been deleted, continue
}
if (!matchesPattern(entry, pattern)) {
continue;
}
const fullPath = join(dir, entry);
if (await isExistingFile(fullPath)) {
return fullPath;
}
}
}
@@ -221,6 +235,29 @@ async function findIconInDir(dir: string, patterns: string[]): Promise<string |
return null;
}
async function searchPriorityDirs(
basePath: string,
ignoredDirsSet: Set<string>,
remainingDepth: number,
): Promise<string | null> {
for (const priorityDir of PRIORITY_DIRS) {
const priorityPath = join(basePath, priorityDir);
if (!(await isExistingDirectory(priorityPath))) {
continue;
}
const result = await searchDirRecursively(
priorityPath,
ICON_PATTERNS,
ignoredDirsSet,
remainingDepth,
);
if (result) {
return result;
}
}
return null;
}
async function searchDirRecursively(
dir: string,
patterns: string[],
@@ -252,22 +289,18 @@ async function searchDirRecursively(
}
const fullPath = join(dir, entry);
try {
const stats = await stat(fullPath);
if (stats.isDirectory()) {
const result = await searchDirRecursively(
fullPath,
patterns,
ignoredDirs,
maxDepth,
currentDepth + 1,
);
if (result) {
return result;
}
}
} catch {
// Directory may be inaccessible, continue
if (!(await isExistingDirectory(fullPath))) {
continue;
}
const result = await searchDirRecursively(
fullPath,
patterns,
ignoredDirs,
maxDepth,
currentDepth + 1,
);
if (result) {
return result;
}
}
@@ -289,24 +322,9 @@ export async function findProjectIcon(
const ignoredDirsSet = new Set(IGNORED_DIRS);
// First search priority directories
for (const priorityDir of PRIORITY_DIRS) {
const priorityPath = join(projectDir, priorityDir);
try {
const stats = await stat(priorityPath);
if (stats.isDirectory()) {
const result = await searchDirRecursively(
priorityPath,
ICON_PATTERNS,
ignoredDirsSet,
maxDepth - 1,
);
if (result) {
return result;
}
}
} catch {
// Directory doesn't exist, continue
}
const priorityResult = await searchPriorityDirs(projectDir, ignoredDirsSet, maxDepth - 1);
if (priorityResult) {
return priorityResult;
}
// Then search monorepo package directories (packages/*, apps/*)
@@ -321,32 +339,17 @@ export async function findProjectIcon(
for (const packageName of packageEntries) {
const packagePath = join(monoPath, packageName);
try {
const packageStats = await stat(packagePath);
if (!packageStats.isDirectory()) continue;
} catch {
if (!(await isExistingDirectory(packagePath))) {
continue;
}
// Search priority dirs within the package
for (const priorityDir of PRIORITY_DIRS) {
const priorityPath = join(packagePath, priorityDir);
try {
const priorityStats = await stat(priorityPath);
if (priorityStats.isDirectory()) {
const result = await searchDirRecursively(
priorityPath,
ICON_PATTERNS,
ignoredDirsSet,
maxDepth - 1,
);
if (result) {
return result;
}
}
} catch {
// Directory doesn't exist, continue
}
const packagePriorityResult = await searchPriorityDirs(
packagePath,
ignoredDirsSet,
maxDepth - 1,
);
if (packagePriorityResult) {
return packagePriorityResult;
}
// Search package root
@@ -385,31 +388,29 @@ async function findDirRecursively(
}
// Don't recurse further from root - we already searched priority dirs
if (currentDepth > 0) {
let entries: string[];
try {
entries = await readdir(dir);
} catch {
return null;
if (currentDepth === 0) {
return null;
}
let entries: string[];
try {
entries = await readdir(dir);
} catch {
return null;
}
for (const entry of entries) {
if (ignoredDirsSet.has(entry) || priorityDirsSet.has(entry)) {
continue;
}
for (const entry of entries) {
if (ignoredDirsSet.has(entry) || priorityDirsSet.has(entry)) {
continue;
}
const fullPath = join(dir, entry);
try {
const stats = await stat(fullPath);
if (stats.isDirectory()) {
const result = await findDirRecursively(fullPath, maxDepth, currentDepth + 1);
if (result) {
return result;
}
}
} catch {
// Continue
}
const fullPath = join(dir, entry);
if (!(await isExistingDirectory(fullPath))) {
continue;
}
const result = await findDirRecursively(fullPath, maxDepth, currentDepth + 1);
if (result) {
return result;
}
}