processFile method
Process a single file and return FileInfo
Implementation
Future<FileInfo> processFile(File file) async {
final relativePath = p.relative(file.path, from: p.join(workingDir, config.sourceDir));
// Check if file should be ignored (pattern check first, no I/O)
final patternReason = IgnorePatterns.getIgnoreReason(
relativePath,
null,
config.effectiveIgnorePatterns,
config.ignoreFiles,
);
if (patternReason != null) {
return FileInfo.ignored(
path: file.path,
relativePath: relativePath,
reason: patternReason,
);
}
// Read file content
String content;
try {
content = await file.readAsString();
} catch (e) {
return FileInfo.ignored(
path: file.path,
relativePath: relativePath,
reason: 'Could not read file: $e',
);
}
// Check for generated markers in content (language-aware)
if (IgnorePatterns.hasGeneratedMarker(content, commentStyle)) {
return FileInfo.ignored(
path: file.path,
relativePath: relativePath,
reason: 'Contains generated file marker',
);
}
// Get file stats
final stat = await file.stat();
// Process content (remove comments if configured)
final processedContent = config.removeComments
? CommentRemover.removeComments(content, commentStyle)
: content;
return FileInfo(
path: file.path,
relativePath: relativePath,
sizeBytes: stat.size,
lastModified: stat.modified,
content: processedContent,
);
}