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

SA1649 and SA1402 - Doesn't work when using C# 10 File-scoped Namespaces #3435

Closed
hannahchan opened this issue Jan 14, 2022 · 0 comments · Fixed by #3436
Closed

SA1649 and SA1402 - Doesn't work when using C# 10 File-scoped Namespaces #3435

hannahchan opened this issue Jan 14, 2022 · 0 comments · Fixed by #3436
Assignees

Comments

@hannahchan
Copy link

hannahchan commented Jan 14, 2022

I'm using StyleCop.Analyzers version, 1.2.0-beta.376.

When given a file named Example.cs with the following content using file-scoped namespaces in C# 10:

namespace MyExample;

public class TestClass1
{
}

public class TestClass2
{
}

The rules SA1649 - File name should match first type name and SA1402 File may only contain a single type stop working. When switching back to block-scoped namespaces, the rules start working again. The following code triggers the rules correctly.

namespace MyExample
{
    public class TestClass1
    {
    }

    public class TestClass2
    {
    }
}

There may be other rules that don't work when using file-scoped namespaces in C# 10. I've only discovered these two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants