Open shyndman opened 5 years ago
I think we'll have to search the list. And it won't be straightforward, because YamlMap
isn't using an ordered map under the covers (although someone's asked for it here https://github.com/dart-lang/yaml/issues/55), so it won't iterate in the same order it was defined in the file.
So instead we'll have to sort YamlMap.nodes.keys
(which are instances of YamlScalar
) by their location in the source code (via span
), then again by their value
s, then compare the two lists. If they're ordered the same way, we'll know it's alphabetically ordered.
What might even be better is to use the same insertion algorithm whether or not the deps are already sorted.
Sort the keys as I described above (using span
), then walk them in order until the name of the package we're adding comes before the key we're looking at (alphabetically), and insert it there.
It keeps sorted deps sorted, and if they aren't sorted, it still inserts the dependency somewhere.
How to determine if dependencies are sorted? Is there a current flag ir should we search the list to verify if the dependencies are ordered alphabetically?