WiseTechGlobal / WTG.Analyzers

Analyzers from WiseTech Global to enforce our styles, behaviours, and prevent common mistakes.
Other
15 stars 3 forks source link

WTG1006 should be "FileScopedNamespace"-aware. #207

Closed brian-reichle closed 1 year ago

brian-reichle commented 1 year ago

WTG1006 reports a diagnostic if a top-level class has the internal visibility, it identifies a class as top-level by checking if the parent SyntaxNode is a compilation unit or namespace, but doesn't check for C#9's file scoped namespaces. As a result, WTG1006 fails to report a diagnostic for internal classes when using file scoped namespaces.

namespace Foo
{
    internal class Bar // <-- correctly reports WTG1006
    {
    }
}
namespace Foo;

internal class Bar // <-- fails to report WTG1006
{
}

the fix should be as simple as adding FileScopedNamespace to the switch in VisibilityAnalyzer.IsTopLevel.

WI00600526

yaakov-h commented 1 year ago

I believe this would either require Roslyn >= 4.0, or bringing back "FutureSyntaxKinds".

brian-reichle commented 1 year ago

I'm ok with FutureSyntaxKinds, at least until we drop support for VS2019. Though the tests themselves would need to be updated to 4.0 and that would require #209 to be fixed.