Skip to content

Support C# format strings in config #4605

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

9swampy
Copy link
Contributor

@9swampy 9swampy commented Jun 28, 2025

Description

Support C# format strings in config

Related Issue

Fixes #4156

Motivation and Context

#4156

How Has This Been Tested?

I've implemented a number of formatters and added scenario coverage for implementation but a 4-eyes verification and feedback on appropriateness of scenarios included (or not) would be welcome. The specific scenrio noted on the wish-issue tested here and here.

I've an aversion to Helper classes but that's where I've dropped all this as an extension of the original StringFormatWith but please redirect if it should live elsewhere (or just needs some structure).

Screenshots (if appropriate):

image

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@9swampy 9swampy marked this pull request as ready for review June 28, 2025 17:15
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch 7 times, most recently from f192c56 to 92fa63f Compare June 28, 2025 22:21
@arturcic arturcic self-requested a review June 29, 2025 09:27
@arturcic
Copy link
Member

please rebase and resolve the conflicts

@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from 92fa63f to 9a18634 Compare June 29, 2025 11:21
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from 9a18634 to e7652ec Compare July 7, 2025 00:39
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from e7652ec to 16f557c Compare July 9, 2025 20:40
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

Awesome work! ❤️

using System.Text.RegularExpressions;
using GitVersion.Core;
using GitVersion.Formatting;
Copy link
Contributor Author

@9swampy 9swampy Jul 15, 2025

Choose a reason for hiding this comment

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

The type or namespace name 'Formatting' does not exist in the namespace 'GitVersion' (are you missing an assembly reference?)

Unclear what's gone wrong here. Clearly that's what the PR introduces and VS is happy. Is there something in the pipeline to prevent unapproved namespace additions?

Copy link
Member

Choose a reason for hiding this comment

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

Weird. Not that I know of. @arturcic, do you have an idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Twigged what was going on. Needed to link added files in Common.csproj.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's still something messed up in the pipeline though. Now CI's not happy with the Common.csproj.

  • If I only add the 1 line needed and keep 2-space indent consistent then I get a single whole-file conflict,
  • if I reformat the whole file to 4-space indent to align with what the CI expected to avoid the "conflict" then I get 3 conflicts in the same file.

Really don't see what would make CI happy, so have reverted back to minimal delta of not changing the indent irrespective of what CI expects. When you eyeball the "Resolve conflict" let me know if there's something I need to do?

Copy link
Member

Choose a reason for hiding this comment

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

There's still something messed up in the pipeline though. Now CI's not happy with the Common.csproj.

  • If I only add the 1 line needed and keep 2-space indent consistent then I get a single whole-file conflict,
  • if I reformat the whole file to 4-space indent to align with what the CI expected to avoid the "conflict" then I get 3 conflicts in the same file.

Really don't see what would make CI happy, so have reverted back to minimal delta of not changing the indent irrespective of what CI expects. When you eyeball the "Resolve conflict" let me know if there's something I need to do?

I probably missed it, but what's the reason for another csproj? Why not in the Core?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add the csproj, I just added one line but something odd's going on in the pipeline. I added 1 line keeping true to the 2 space indent, but the CI pipe detects a conflict expecting everything to be 4 space indent (which isn't what the current check in is at all). Doesn't make sense, it's as if the prior file is being formatted and changed to 4 space indent BEFORE determining if there's a conflict.

@9swampy 9swampy requested a review from asbjornu July 15, 2025 18:55
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from 3e5bf0e to 65a39f5 Compare July 19, 2025 22:19
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

Besides the build failure, this is looking really good! The only missing part is documentation.

@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from 65a39f5 to c7fbede Compare July 19, 2025 22:46
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from c7fbede to 646a634 Compare July 19, 2025 22:53
@9swampy 9swampy requested a review from asbjornu July 20, 2025 01:19
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch 2 times, most recently from d8b08a6 to 53547ee Compare July 20, 2025 12:22
@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from 53547ee to 625c32f Compare July 20, 2025 12:39
@arturcic
Copy link
Member

@9swampy if you don't mind I'll have a review of this in 2 weeks time as I'm on vacation. I need to understand it a bit in detail the changes as there is a chance we will need to maintain these changes.

@phatcher
Copy link
Contributor

Can I also suggest adding some tests that use the zero-suppression syntax so that we can get versions without a commits number e.g.

[TestCase(0, "{0:0000}", "0000")]
[TestCase(1, "{0:0000}", "0001")]
[TestCase(0, "{0:-0000;;''}", "")]
[TestCase(1, "{0:-0000;;''}", "-0001")]
public void ZeroFormatting(int value, string template, string expected)
{
    var candidate = string.Format(template, value);

    Assert.That(candidate, Is.EqualTo(expected));
}

@9swampy 9swampy force-pushed the SupportFormatStringsInConfig branch from 0c3e0c0 to f0e2983 Compare July 26, 2025 18:41
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.

Support C# format strings in config
4 participants