-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix exclude consistency fields 13131 #13305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix exclude consistency fields 13131 #13305
Conversation
assertTrue(result.entryTypeToResultMap().isEmpty(), | ||
"Differences only in filtered fields must be ignored"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of assertTrue to check for an empty map is less informative than using assertEquals to directly compare the map to an empty map, which would provide clearer test failure messages.
// AUTHOR should be reported as a unique field | ||
var typeResult = result.entryTypeToResultMap().get(StandardEntryType.Misc); | ||
assertNotNull(typeResult); | ||
assertTrue(typeResult.fields().contains(StandardField.AUTHOR)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using assertTrue to check if a collection contains an element is less informative than using assertEquals to compare the collection to an expected collection, which would provide clearer test failure messages.
@@ -69,7 +114,10 @@ public Result check(List<BibEntry> entries, BiConsumer<Integer, Integer> entries | |||
|
|||
List<BibEntry> differingEntries = entryTypeToEntriesMap | |||
.get(entryType).stream() | |||
.filter(entry -> !entry.getFields().equals(commonFields)) | |||
.filter(entry -> { | |||
Set<Field> entryFiltered = filterFields(entry.getFields()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'entryFiltered' is not descriptive enough. It should convey the purpose or content of the variable more clearly.
JUnit tests of You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide. |
import java.util.function.BiConsumer; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkstyle
// – plus any SpecialField or UserSpecificCommentField (filtered at runtime) | ||
// ---------------------------------------------------------------- | ||
private static final Set<Field> FILTERED_FIELDS = Stream | ||
// start with JabRef’s built‐in AUTOMATIC_FIELDS set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment, code is self-explanatory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with AI comments is that if humans and AI both work in the code, it is not ensured if the comments match the implementation if the code is updated.
import org.jabref.model.entry.types.EntryType; | ||
|
||
public class BibliographyConsistencyCheck { | ||
|
||
// ---------------------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper Java doc, keep comment style
.filter(f -> !FILTERED_FIELDS.contains(f)) | ||
.filter(f -> !(f instanceof SpecialField)) | ||
.filter(f -> !(f instanceof UserSpecificCommentField)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid abbreviations
.filter(f -> !FILTERED_FIELDS.contains(f)) | |
.filter(f -> !(f instanceof SpecialField)) | |
.filter(f -> !(f instanceof UserSpecificCommentField)) | |
.filter(field -> !FILTERED_FIELDS.contains(field)) | |
.filter(field -> !(field instanceof SpecialField)) | |
.filter(field -> !(field instanceof UserSpecificCommentField)) |
/** | ||
* Drop any field we don’t want to check. | ||
*/ | ||
private static Set<Field> filterFields(Collection<Field> fields) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Can you use a better method name, hinting at what we are filtering against? "filterFIelds" is a bit generic. Lets consider filterXFields or removeXFields - think what one word can "X" be, based on the logic?
If no such crisp word is possible, you can ignore this suggestion.
/** | ||
* Drop any field we don’t want to check. | ||
*/ | ||
private static Set<Field> filterFields(Collection<Field> fields) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we can be more specific here wrt the parameter
private static Set<Field> filterFields(Collection<Field> fields) { | |
private static Set<Field> filterFields(SequencedSet<Field> fields) { |
"Differences only in filtered fields must be ignored"); | ||
} | ||
|
||
@SuppressWarnings("checkstyle:RegexpMultiline") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not suppress checkstyle warnings without having a good reason to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi subhramit,
thank you for your advice. I will fix it.
.withField(StandardField.COMMENT, "another note") | ||
.withField(StandardField.PDF, "other.pdf"); | ||
|
||
var result = new BibliographyConsistencyCheck().check(List.of(a, b)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use var
. At JabRef, we prefer strict types.
Also, did the compiler not complain here? You sent one argument instead of two, so the unit test is failing. Did you run the test before filing the PR?
var result = new BibliographyConsistencyCheck().check(List.of(withAuthor, withoutAuthor)); | ||
|
||
// AUTHOR should be reported as a unique field | ||
var typeResult = result.entryTypeToResultMap().get(StandardEntryType.Misc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comments regarding var
and number of arguments here as https://github.com/JabRef/jabref/pull/13305/files#r2140865139.
Closes #13131
This PR modifies the BibliographyConsistencyCheck to exclude specific fields from consistency checks. Fields such as COMMENT, CROSSREF, and AUTOMATIC_FIELDS, along with any SpecialField or UserSpecificCommentField, are now filtered out to avoid false positives during consistency validation. This improves the relevance of reported issues and aligns the behavior with user expectations.
Steps to test
No UI changes were made, so testing is limited to data checks and developer view.
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)