[Duplicate imports] Fix issue that would cause duplicate imports #300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the given schema file, we can see the class
board_activityreferences itself:This causes multiple
BoardActivityimports inBoardActivity.m. The issue is inObjCIR.Root.importsrenderImplementationmethod. This is how the imports are being generated:Using the schema above,
classNameswould include“BoardActivity “. Note the space.myNamewould be”BoardActivity”. Note the lack of space.These two get unioned together in a set. The result is
["BoardActivity ", "BoardActivity"]. We sort this set, then remove any trailing spaces. But at this point we are an array, and we now have two duplicate entries in our array:["BoardActivity", "BoardActivity"]. This leads plank to render#import "BoardActivity.h"twice in our implementation file.A solution would be to trim these strings BEFORE the union:
I created
strippedClassNameswhich holds the trimmedclassNames. This gets unioned that with the stripped version ofmyNameto get the list of imports. Now we end up with the array only have one entry["BoardActivity"].Note: I also made a change in
ObjectiveCNSCodingExtension.swiftbecause the compiler was telling me that the return value was too complicated for it to figure out.