validateFile method
void
validateFile(
- File file
)
Implementation
void validateFile(File file) {
final content = file.readAsStringSync();
final fieldsPattern = RegExp(r'Json[^ \n\r]+\s+([^ \n\r]+)\s+=');
final getterPattern = RegExp(r'List<JsonField> get fields => \[(.*?)\];', dotAll: true);
final fields = <String>{};
final declaredFields = <String>{};
final getterMatch = getterPattern.firstMatch(content);
if (getterMatch != null) {
final getterContent = getterMatch.group(1)!;
final getterFields =
getterContent.trim().split(RegExp(r',\s*')).map((f) => f.trim()).where((f) => f.isNotEmpty).toList();
declaredFields.addAll(getterFields);
}
for (final match in fieldsPattern.allMatches(content)) {
final matchedGroup = match.group(1)!;
fields.add(matchedGroup);
}
final missingFields = fields.difference(declaredFields);
// final duplicateFields = declaredFields.difference(fields);
if (missingFields.isNotEmpty) {
print('File ${file.path} is missing fields in the fields getter: ${missingFields.join(', ')}');
}
// if (duplicateFields.isNotEmpty) {
// print('File ${file.path} has duplicate fields in the fields getter: ${duplicateFields.join(', ')}');
// }
// if (missingFields.isEmpty && duplicateFields.isEmpty) {
// print('File ${file.path} is valid.');
// }
}