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

Fix doubled braces in attributes #412

Merged
merged 20 commits into from
Jan 6, 2025
Merged

Fix doubled braces in attributes #412

merged 20 commits into from
Jan 6, 2025

Conversation

sungam3r
Copy link
Member

@sungam3r sungam3r commented Jan 3, 2025

fixes #410


This PR was superseded by #414.

@github-actions github-actions bot added the tests Pull request that adds new or changes existing tests label Jan 3, 2025
@sungam3r
Copy link
Member Author

sungam3r commented Jan 3, 2025

Wow! Not reproducable locally, but reproducable in CI.

@sungam3r
Copy link
Member Author

sungam3r commented Jan 3, 2025

There are no doubled (( on NET FRAMEWORK.

@siewers
Copy link

siewers commented Jan 3, 2025

Okay, then it makes more sense.
I'm not using .NET Framework so I did not test that 🙂

@sungam3r sungam3r changed the title Address issue 410 Fix doubled braces in attributes Jan 3, 2025
@sungam3r
Copy link
Member Author

sungam3r commented Jan 3, 2025

@stakx @jnyrup please take a look. I'll keep it 1-2 days before merging. I would like to release this one with #342.

Comment on lines 40 to 45
// https://github.com/PublicApiGenerator/PublicApiGenerator/issues/410
if (gennedClass.Contains(ATTRIBUTE_MARKER_AND_DOUBLED_BRACE) && gennedClass.Contains(DOUBLED_CLOSING_BRACE_IN_ATTRIBUTE))
{
gennedClass = gennedClass.Replace(ATTRIBUTE_MARKER_AND_DOUBLED_BRACE, ATTRIBUTE_MARKER_AND_BRACE);
gennedClass = gennedClass.Replace(DOUBLED_CLOSING_BRACE_IN_ATTRIBUTE, SINGLE_CLOSING_BRACE_IN_ATTRIBUTE);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work with the example from #410 because it has an extra parameter after the long string.

        [Fact]
        public void Should_handle_attribute_with_long_string_initialiser2()
        {
            AssertPublicApi<ClassWithAttributeWithLongStringInitialiser2>(
                @"namespace PublicApiGeneratorTests.Examples
{
    [System.Obsolete(""This is a veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"" +
        ""eeeeeeery long string that will be surrounded by parenthesis due to how it\'s han"" +
        ""dled by Microsoft.CodeDom"", false)]
    public class ClassWithAttributeWithLongStringInitialiser2
    {
        public ClassWithAttributeWithLongStringInitialiser2() { }
    }
}");
        }
[Obsolete("This is a veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery long string that will be surrounded by parenthesis due to how it's handled by Microsoft.CodeDom", false)]
public class ClassWithAttributeWithLongStringInitialiser2()
{
}

There's also other cases to consider:

  • Ending with long string parameter [SomeAttribute(false, "loooong string")]
  • Multiple long strings parameters [SomeAttribute("loooong string", "loooong string")]

Looking at the commit history for System.CodeDom dotnet/runtime#96948 is the only change between 8.0.0 and 9.0.0.
Skimming the fixed issue, I'm not sure if the fix is relevant for PublicApiGenerator.

So how about:

  • Downgrade System.CodeDom to 8.0.0
  • Undo the changes to CodeNormalizer
  • Keep Should_handle_attribute_with_long_string_initialiser as a regression test

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. It turned out to be not so easy to fix this error only by replacing lines. As a result, I copied all needed code to generate results and commented out problem line.

Copy link
Member Author

Choose a reason for hiding this comment

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

All tests are green now.

Downgrade System.CodeDom to 8.0.0

I understand but downgrading may lead to additional noise with dependabot.

Copy link
Contributor

@jnyrup jnyrup Jan 4, 2025

Choose a reason for hiding this comment

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

dependabot should keep silent if we fix the version using Version=[8.0.0].

In Fluent Assertions, we have configured dependabot to ignore certain dependecies
https://github.com/fluentassertions/fluentassertions/blob/ec0192465b6009ff356c31eeee9adf4187b2496e/.github/dependabot.yml#L27-L37

Copy link
Member Author

Choose a reason for hiding this comment

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

I know that feature. Nevertheless I'm 50/50 now to go on with these changes or revert to 8.

Copy link
Member Author

@sungam3r sungam3r Jan 5, 2025

Choose a reason for hiding this comment

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

@jnyrup I decided to revert System.CodeDom to 8 in #414, publish release and keep #412 opened just in case.

@sungam3r sungam3r added the bugfix Pull request that fixes a bug label Jan 5, 2025
@sungam3r
Copy link
Member Author

sungam3r commented Jan 6, 2025

@jnyrup I achieved a minimum possible diff to fix this issue.

@sungam3r sungam3r merged commit 348040f into master Jan 6, 2025
6 of 8 checks passed
@sungam3r sungam3r deleted the obsolete branch January 6, 2025 15:11
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 29.90%. Comparing base (cc2b2e5) to head (e64e7b5).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ApiGenerator/System.CodeDom/CSharpCodeGenerator.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #412       +/-   ##
===========================================
- Coverage   86.24%   29.90%   -56.35%     
===========================================
  Files          21       26        +5     
  Lines        1345     3879     +2534     
  Branches      239      634      +395     
===========================================
  Hits         1160     1160               
- Misses        147     2674     +2527     
- Partials       38       45        +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Pull request that fixes a bug tests Pull request that adds new or changes existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 11.3.0 ObsoleteAttribute behavior differs from 11.2.0
3 participants