Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions analyzers/SonarAnalyzer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ITs.JsonParser", "src\ITs.J
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ITs.JsonParser.Test", "tests\ITs.JsonParser.Test\ITs.JsonParser.Test.csproj", "{A60741AF-6809-430E-AD3D-F4B91C52BD95}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SonarAnalyzer.CSharp.Styling", "src\SonarAnalyzer.CSharp.Styling\SonarAnalyzer.CSharp.Styling.csproj", "{7F1A25AD-2EEF-4CF9-92D9-FE5B203EECE3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SonarAnalyzer.CSharp.Styling.Test", "tests\SonarAnalyzer.CSharp.Styling.Test\SonarAnalyzer.CSharp.Styling.Test.csproj", "{6F4F7666-8A0D-47FE-A312-56010C4CE082}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,6 +133,14 @@ Global
{A60741AF-6809-430E-AD3D-F4B91C52BD95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A60741AF-6809-430E-AD3D-F4B91C52BD95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A60741AF-6809-430E-AD3D-F4B91C52BD95}.Release|Any CPU.Build.0 = Release|Any CPU
{7F1A25AD-2EEF-4CF9-92D9-FE5B203EECE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F1A25AD-2EEF-4CF9-92D9-FE5B203EECE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F1A25AD-2EEF-4CF9-92D9-FE5B203EECE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F1A25AD-2EEF-4CF9-92D9-FE5B203EECE3}.Release|Any CPU.Build.0 = Release|Any CPU
{6F4F7666-8A0D-47FE-A312-56010C4CE082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F4F7666-8A0D-47FE-A312-56010C4CE082}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F4F7666-8A0D-47FE-A312-56010C4CE082}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F4F7666-8A0D-47FE-A312-56010C4CE082}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -145,6 +157,7 @@ Global
{ADBE6CFE-980F-4D4F-8E25-E391581D291E} = {B7233F78-E142-4882-B084-7C83BE472109}
{4C1DB1C4-C1FC-4AA1-B855-0D1948E68FB8} = {B7233F78-E142-4882-B084-7C83BE472109}
{A60741AF-6809-430E-AD3D-F4B91C52BD95} = {B7233F78-E142-4882-B084-7C83BE472109}
{6F4F7666-8A0D-47FE-A312-56010C4CE082} = {B7233F78-E142-4882-B084-7C83BE472109}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4259CA71-C565-42DD-8D58-F59819A11065}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SonarAnalyzer for .NET
* Copyright (C) 2015-2024 SonarSource SA
* mailto: contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarAnalyzer.CSharp.Styling.Common;

internal static class DescriptorFactory
{
public static DiagnosticDescriptor Create(string id, string messageFormat, SourceScope scope = SourceScope.All) =>
DiagnosticDescriptorFactory.Create(
AnalyzerLanguage.CSharp,
new RuleDescriptor(id, $"Internal Styling Rule {id}", "CODE_SMELL", "Major", null, scope, true, null),
messageFormat,
true,
false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* SonarAnalyzer for .NET
* Copyright (C) 2015-2024 SonarSource SA
* mailto: contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarAnalyzer.Rules.CSharp.Styling;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class FileScopeNamespace : SonarDiagnosticAnalyzer // ToDo: https://github.com/SonarSource/sonar-dotnet/issues/9035 Extract into a usefull base class
{
private static readonly DiagnosticDescriptor Rule = DescriptorFactory.Create("T0001", "Use file-scoped namespaces");

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(Rule); // ToDo: https://github.com/SonarSource/sonar-dotnet/issues/9035 Remove this

protected override void Initialize(SonarAnalysisContext context)
{
// ToDo: https://github.com/SonarSource/sonar-dotnet/issues/9035
if (context is null)
{
return; // This is a useless coverage test for now. It will be removed
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
<!-- We need to update NuGet and JAR packaging after changing references -->
<ProjectReference Include="..\SonarAnalyzer.Common\SonarAnalyzer.Common.csproj" />
<ProjectReference Include="..\SonarAnalyzer.Common\SonarAnalyzer.CSharp.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.

This path is wrong. It is fixed in the next PR

Suggested change
<ProjectReference Include="..\SonarAnalyzer.Common\SonarAnalyzer.CSharp.csproj" />
<ProjectReference Include="..\SonarAnalyzer.CSharp\SonarAnalyzer.CSharp.csproj" />

</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.CodeAnalysis.CSharp" />
<Using Include="Microsoft.CodeAnalysis.CSharp.Syntax" />
<Using Include="SonarAnalyzer.AnalysisContext" />
<Using Include="SonarAnalyzer.Common" />
<Using Include="SonarAnalyzer.CSharp.Styling.Common" />
<Using Include="SonarAnalyzer.Extensions" />
<Using Include="SonarAnalyzer.Helpers" />
<Using Include="StyleCop.Analyzers.Lightup" />
<Using Include="Microsoft.CodeAnalysis" />
<Using Include="Microsoft.CodeAnalysis.Diagnostics" />
</ItemGroup>

</Project>
Loading