Consider suggesting spelling fixes for unrecognized pubspec keys
I recently helped somebody diagnose an issue where their dependency overrides weren't working, and they had just left off the s.
I realize that pub cannot more generally error on keys it doesn't recognize, but it could potentially check if unrecognized keys are within a close edit distance of a known key, and in that case give a warning about the likely misspelling.
See package:args as an example https://github.com/dart-lang/core/blob/0b2bd3fcd7f3e082f4cc9b14c19ffa93894b85ae/pkgs/args/lib/command_runner.dart#L526C5-L526C18
We are actually doing this when publishing. Doing it on pub get is probably too noisy.
@jonasfj suggests hardcoding a list of likely misspellings of the hardest-to-spell properties, and have pub get error if those are present.
We could also do the spell-check in a lint. That would enable ignoreing it - and not be noisy on the command line.
We are actually doing this when publishing. Doing it on
pub getis probably too noisy.
Is the thought that there would be lots of false positives? That seems somewhat unlikely to me, certainly it could happen, but if you only warn on an edit distance of say 2, it will catch a lot of cases still while reducing false positives.
Is the thought that there would be lots of false positives? That seems somewhat unlikely to me, certainly it could happen, but if you only warn on an edit distance of say 2, it will catch a lot of cases still while reducing false positives.
No, more that a single false positive will be bothering on every invocation - and if you indeed rely on the new property name (pubspec.yaml is open-ended) then there should be a way to turn off the warning.
Yaml does support comments so we could allow some form of ignore comment, but I don't know how easy they are to get at.
A lint could be reasonable but I would worry that keeping it in sync with the known keys would be a bit weird.
Yaml does support comments so we could allow some form of ignore comment, but I don't know how easy they are to get at.
I implemented # ignore: comments for pubspec.yaml lints at some point: https://dart-review.googlesource.com/c/sdk/+/311980
A lint could be reasonable but I would worry that keeping it in sync with the known keys would be a bit weird.
We could do the lint in a similar way to our current typo-validator. It only complains if the edit distance to a known key is short: https://github.com/dart-lang/pub/blob/master/lib/src/validator/pubspec_typo.dart . That way unknown keys are ignored (unless they happen to be very similar to known keys.)
That way unknown keys are ignored
Yes, and I agree it should only warn on very short edit distances (2?), but it also means that the lint won't fire on any examples when new pubspec keys are added.
Since the lint would have to be totally separate from pub itself, it seems very unlikely to me that it would get updated to provide help for any of these new keys, because we just won't think about doing so.
If it is built into pub itself, it would automatically work for any known keys.