Skip to content

.pr_agent_auto_best_practices

qodo-merge-bot edited this page Dec 25, 2025 · 1 revision

Pattern 1: Correct typographical errors in documentation, code comments, configuration files, and user-facing strings. This includes fixing misspellings in variable names, method names, documentation text, changelog entries, and localization strings to maintain code quality and professionalism.

Example code before:

// Documentation or code with typos
String mesage = "File not found";
// Comment: This method handels user input
public void processInupt() { }

Example code after:

// Corrected documentation and code
String message = "File not found";
// Comment: This method handles user input
public void processInput() { }
Relevant past accepted suggestions:
Suggestion 1:

Correct typos in the welcome message

Correct the typos "assitance" to "assistance" and "upate" to "update" in the automated welcome message.

.github/workflows/on-pr-opened.yml [26-27]

-We also use [Qodo](https://www.qodo.ai/) for review assitance.
-It will upate your pull request description with a review help and offer suggestions to improve the pull request.
+We also use [Qodo](https://www.qodo.ai/) for review assistance.
+It will update your pull request description with a review help and offer suggestions to improve the pull request.

Suggestion 2:

Fix a typo in changelog

Correct the typo "issure" to "issue" in the changelog entry.

CHANGELOG.md [1739]

-- We fixed an issure where warning dialog is mixed Chinese/English after switching to zh_CN [#14654](https://github.com/JabRef/jabref/issues/14654)
+- We fixed an issue where warning dialog is mixed Chinese/English after switching to zh_CN [#14654](https://github.com/JabRef/jabref/issues/14654)

Suggestion 3:

Fix typo in Observable

Correct the typo "Obersavable" to "Observable" when referring to JavaFX lists.

AGENTS.md [52]

-Using JavaFX Obersavable lists is considered best practice, too.
+Using JavaFX Observable lists is considered best practice, too.

Suggestion 4:

Correct typo in code example

Correct the typo Sef.of(...) to Set.of(...) in the Java code example for creating a Set.

AGENTS.md [53]

 - Use modern Java data structures
 
 BAD: new HashSet<>(Arrays.asList(...))
 
-GOOD: Sef.of(...)
+GOOD: Set.of(...)

Pattern 2: Optimize file system operations by collecting all required data first, then performing a single traversal of directories instead of multiple nested iterations. This pattern applies when searching for files or validating file existence across multiple paths.

Example code before:

List<Path> results = new ArrayList<>();
for (String fileName : fileNames) {
    for (Path directory : directories) {
        Files.walk(directory).forEach(path -> {
            if (path.getFileName().toString().equals(fileName)) {
                results.add(path);
            }
        });
    }
}

Example code after:

Set<String> fileNameSet = new HashSet<>(fileNames);
List<Path> results = new ArrayList<>();
for (Path directory : directories) {
    Files.walk(directory).forEach(path -> {
        if (fileNameSet.contains(path.getFileName().toString())) {
            results.add(path);
        }
    });
}
Relevant past accepted suggestions:
Suggestion 1:

Optimize file search by reducing traversals

Optimize the findAssociatedFilesByBrokenLinkedFile method to improve performance by reducing redundant file system traversals. First, collect all unique base names of broken links, then iterate through each directory only once to find all matching files.

jabgui/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java [143-163]

 private List<Path> findAssociatedFilesByBrokenLinkedFile(BibEntry entry) throws IOException {
+    Set<String> brokenLinkBaseNames = entry.getFiles().stream()
+                                           .filter(linkedFile -> linkedFile.findIn(directories).isEmpty())
+                                           .map(linkedFile -> FileUtil.getBaseName(linkedFile.getLink()).toLowerCase())
+                                           .collect(Collectors.toSet());
+
+    if (brokenLinkBaseNames.isEmpty()) {
+        return List.of();
+    }
+
     List<Path> matches = new ArrayList<>();
-
-    for (LinkedFile linkedFile : entry.getFiles()) {
-        boolean isLinkedFileBroken = linkedFile.findIn(directories).isEmpty();
-        if (isLinkedFileBroken) {
-            String linkedFileBaseName = FileUtil.getBaseName(linkedFile.getLink());
-
-            for (Path directory : directories) {
-                try (Stream<Path> walk = Files.walk(directory)) {
-                    List<Path> found = walk.filter(path -> !Files.isDirectory(path))
-                                           .filter(path -> FileUtil.getBaseName(path).equalsIgnoreCase(linkedFileBaseName))
-                                           .toList();
-                    matches.addAll(found);
-                }
-            }
+    for (Path directory : directories) {
+        try (Stream<Path> walk = Files.walk(directory)) {
+            List<Path> found = walk.filter(path -> !Files.isDirectory(path))
+                                   .filter(path -> brokenLinkBaseNames.contains(FileUtil.getBaseName(path).toLowerCase()))
+                                   .toList();
+            matches.addAll(found);
         }
     }
 
     return matches;
 }

Suggestion 2:

Report all missing files at once

Refactor the file existence check to collect all non-existent files and report them in a single error message, rather than returning after the first one is found.

jabgui/src/main/java/org/jabref/gui/importer/ImportCommand.java [104-111]

-for (Path file : files) {
-    if (!Files.exists(file)) {
-        dialogService.showErrorDialogAndWait(
-                Localization.lang("Import"),
-                Localization.lang("File %0 not found", file.getFileName().toString()));
-        return;
-    }
+List<Path> nonExistentFiles = files.stream()
+                                   .filter(file -> !Files.exists(file))
+                                   .toList();
+if (!nonExistentFiles.isEmpty()) {
+    String fileNames = nonExistentFiles.stream()
+                                       .map(path -> path.getFileName().toString())
+                                       .collect(Collectors.joining(", "));
+    dialogService.showErrorDialogAndWait(
+            Localization.lang("Import"),
+            Localization.lang("File(s) not found: %0", fileNames));
+    return;
 }

[Auto-generated best practices - 2025-12-25]

Clone this wiki locally