Skip to content
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

Parsing option: lenient. #36

Merged
merged 6 commits into from
Jan 8, 2019
Merged

Parsing option: lenient. #36

merged 6 commits into from
Jan 8, 2019

Conversation

isoos
Copy link
Contributor

@isoos isoos commented Jan 4, 2019

A bit of alternative to @jonasfj's per-property parsing: instead of parsing it on per-property, we remove the top-level key on each reporter error.

This does not yet delegate the lenient flag to embedded classes like Dependency (and I'm not sure if it is feasible to without either json_serializable support or using zones).

lib/src/pubspec.dart Outdated Show resolved Hide resolved
lib/src/pubspec.dart Outdated Show resolved Hide resolved
@@ -116,9 +116,30 @@ class Pubspec {
}
}

factory Pubspec.fromJson(Map json) => _$PubspecFromJson(json);
factory Pubspec.fromJson(Map json, {bool lenient = false}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't permissive a better way to write it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dart SDK doesn't have either, and Java's date parsing uses lenient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also shouldn't this be the default mode?

Copy link
Contributor Author

@isoos isoos Jan 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think defaulting to strict mode is better. (e.g. being explicit that we don't need strict checks).

@@ -116,9 +116,31 @@ class Pubspec {
}
}

factory Pubspec.fromJson(Map json) => _$PubspecFromJson(json);
factory Pubspec.fromJson(Map json, {bool lenient = false}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doc comment describing what lenient does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, PTAL.

CHANGELOG.md Outdated Show resolved Hide resolved
@jonasfj
Copy link
Member

jonasfj commented Jan 8, 2019

Do we still need this parsing mode if we get rid of the broken package on pub?

@isoos
Copy link
Contributor Author

isoos commented Jan 8, 2019

Do we still need this parsing mode if we get rid of the broken package on pub?

We may not need it right now (assumed that package will be removed), but I'd rather use lenient parsing on the read-access part of the pub site. While we would remember this incident for a few more months, it could be well forgotten in a year or so, and the next similar incident could cause similar issues.

Having said that, it may be worth to add logging to pubspec_parse, and we should log an info message on the cases where lenient parsing dismissed a value.

kevmoo
kevmoo previously requested changes Jan 8, 2019
lib/src/pubspec.dart Outdated Show resolved Hide resolved
@kevmoo kevmoo dismissed their stale review January 8, 2019 15:11

let's see how travis goes...

Copy link
Member

@kevmoo kevmoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do a clean squash-merge 😄

@isoos
Copy link
Contributor Author

isoos commented Jan 8, 2019

please do a clean squash-merge 😄

I would, but I have no permission to do so, please do the merge for me.

@kevmoo kevmoo merged commit a961892 into dart-lang:master Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants