Handle duplicate route declaration better #968
Merged
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.
Fixes issue when you accidentally have
@Router /some/route
declared twice.Previously this would cause either of the 2 definitions to be used and it leaves the user very confused.
Tbh I'd personally just prefer the hard error when this mistake is made, but I think for backwards compatibility it might be nice to either have it warn by default (as it is now in this PR) or have the option to turn it into a warning, so I added the
Strict
option flag.I think this could also be useful for more checks in the future?
Additionally I made
RangeFiles
sort the files to make sure it happens in deterministic order, prior to my fix to warn / error when there's a duplicate route and without this you'd randomly get one of the 2 routes and that really confuses the hell of you because instead of thinking you made a mistake it just looks like a very weird bug.The "fix issue with files being parsed twice" was something that came up when I added the warning about duplicate routes and I noticed that in
TestGen_cgoImports
it was triggering as well, this was because it was parsingsimple_cgo/api
from both the searchDirs and from theParseDependency
block.If you'd like me to split the PR into multiple then please let me know, or if you want it without the
Strict
config option for example