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

Retain comments and linebreaks when writting new yaml #19

Closed
wants to merge 5 commits into from

Conversation

Agraphie
Copy link

@Agraphie Agraphie commented Jun 7, 2019

Resolves #17 by parsing and updating version in place.

@Agraphie Agraphie changed the title Retain comments and linebreaks when writting new yalm Retain comments and linebreaks when writting new yaml Jun 7, 2019
@f3ath
Copy link
Owner

f3ath commented Jun 13, 2019

OK, so I discussed this with a friend. Yaml seems to be trickier than I thought. For instance, what if the version: line has a comment in itself?

version: 0.2.3 # lol parse me 

Or what if there is a multiline string?

version: 0.2.3 # i am the version line
description: 'and I am a line with a
version: 3.2.1
in it'

I don't see an easy way to avoid using a real yaml parser.

@Agraphie
Copy link
Author

Agraphie commented Jun 13, 2019

Yes good thought, you are right about that. But nothing a little regex can't fix. We just use a positive lookahead and match the version which is not contained in " or '. Then we non-greedily match until # to exclude any comments behind the version. I also included the things you mentioned in the test yaml.

Can you think of any other tests or problems?

@@ -1,6 +1,10 @@
description: "A CLI tool to set/bump the `version` key in pubspec.yaml."
description: "A CLI tool to set/bump the `version` key in pubspec.yaml.
version: 1.2.3
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a test checking this line is not getting changed?

Future _writeNewPubSpec(
File pubSpec, Version oldVersion, Version newVersion) async {
String newPubSpec = pubSpec.readAsStringSync().replaceFirst(
'version: "${oldVersion}"', "version: " + '"${newVersion.toString()}"');
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand how different quotation is processed. This line seems to only deal with double quotes. Is there a test for double/single/no quotes?


import 'package:pub_semver/pub_semver.dart';

abstract class VersionExtractor {
Copy link
Owner

Choose a reason for hiding this comment

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

Why is it a class and why is the class abstract? A simple function would be enough.

@Agraphie Agraphie closed this Aug 24, 2020
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.

2 participants