Skip to content

Commit

Permalink
Merge pull request #203 from hvanbakel/move
Browse files Browse the repository at this point in the history
Move logic to respective places
  • Loading branch information
andrew-boyarshin authored Sep 21, 2018
2 parents 7e21c0f + d2fb707 commit cd2624f
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 201 deletions.
2 changes: 1 addition & 1 deletion Project2015To2017.Core/Analysis/AnalysisOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class AnalysisOptions

public AnalysisOptions(IEnumerable<IDiagnostic> diagnostics = null)
{
this.Diagnostics = (diagnostics ?? DiagnosticSet.AllDefault).ToImmutableHashSet();
this.Diagnostics = (diagnostics ?? DiagnosticSet.All).ToImmutableHashSet();
}
}
}
18 changes: 6 additions & 12 deletions Project2015To2017.Core/Analysis/Analyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Project2015To2017.Definition;
using Project2015To2017.Reading;
using System;
using Project2015To2017.Analysis.Diagnostics;

namespace Project2015To2017.Analysis
{
Expand Down Expand Up @@ -58,19 +59,12 @@ public void Analyze(Solution solution)
{
if (!projectPath.ProjectFile.Exists)
{
this._reporter.Report(new[]
if (this._options.Diagnostics.Contains(DiagnosticSet.W002))
{
new DiagnosticResult
{
Code = "W002",
Message =
$"Referenced project file '{projectPath.Include}' was not found at '{projectPath.ProjectFile.FullName}'.",
Location = new DiagnosticLocation
{
Source = solution.FilePath
}
}
}, this._reporter.DefaultOptions);
this._reporter.Report(
W002MissingProjectFileDiagnostic.CreateResult(projectPath, solution),
this._reporter.DefaultOptions);
}
continue;
}

Expand Down
35 changes: 17 additions & 18 deletions Project2015To2017.Core/Analysis/DiagnosticSet.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
using System.Collections.Generic;
using Project2015To2017.Analysis.Diagnostics;
using System.Collections.Generic;

namespace Project2015To2017.Analysis
{
public sealed class DiagnosticSet : HashSet<IDiagnostic>
{
public static readonly IDiagnostic W001 = new W001IllegalProjectTypeDiagnostic();
// W002 is not a real diagnostic
public static readonly IDiagnostic W002 = new W002MissingProjectFileDiagnostic();
public static readonly IDiagnostic W010 = new W010ConfigurationsMismatchDiagnostic();
public static readonly IDiagnostic W011 = new W011UnsupportedConditionalDiagnostic();
public static readonly IDiagnostic W020 = new W020MicrosoftCSharpDiagnostic();
public static readonly IDiagnostic W021 = new W021SystemNuGetPackagesDiagnostic();
public static readonly IDiagnostic W030 = new W030LegacyDebugTypesDiagnostic();
public static readonly IDiagnostic W031 = new W031MSBuildSdkVersionSpecificationDiagnostic();
public static readonly IDiagnostic W032 = new W032OldLanguageVersionDiagnostic();
public static readonly IDiagnostic W033 = new W033ObsoletePortableClassLibrariesDiagnostic();
public static readonly IDiagnostic W034 = new W034ReferenceAliasesDiagnostic();

public static readonly DiagnosticSet AllDefault = new DiagnosticSet
public static readonly DiagnosticSet NoneDefault = new DiagnosticSet();

public static readonly DiagnosticSet System = new DiagnosticSet
{
W001,
W002,
};

public static readonly DiagnosticSet GenericProjectIssues = new DiagnosticSet
{
W010,
W011,
W020,
W021,
W030,
W031,
W032,
W033,
W034,
};

public static readonly DiagnosticSet NoneDefault = new DiagnosticSet();
public static readonly DiagnosticSet All = new DiagnosticSet();

static DiagnosticSet()
{
All.UnionWith(System);
All.UnionWith(GenericProjectIssues);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Project2015To2017.Definition;
using System;
using System.Collections.Generic;

namespace Project2015To2017.Analysis.Diagnostics
{
public sealed class W002MissingProjectFileDiagnostic : DiagnosticBase
{
public override bool SkipForLegacyProject => true;
public override bool SkipForModernProject => true;
public override IReadOnlyList<IDiagnosticResult> Analyze(Project project) =>
throw new InvalidOperationException("W002 is not an executable diagnostic");

public static IReadOnlyList<IDiagnosticResult> CreateResult(ProjectReference @ref, Solution solution = null)
{
return new[]
{
new DiagnosticResult
{
Code = "W002",
Message =
$"Referenced project file '{@ref.Include}' was not found at '{@ref.ProjectFile.FullName}'.",
Location = new DiagnosticLocation
{
Source = solution?.FilePath
}
}
};
}

public W002MissingProjectFileDiagnostic() : base(2)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Project2015To2017.Definition;
using System;
using System.Collections.Generic;
using System.Linq;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W020MicrosoftCSharpDiagnostic : DiagnosticBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W021SystemNuGetPackagesDiagnostic : DiagnosticBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W030LegacyDebugTypesDiagnostic : DiagnosticBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W031MSBuildSdkVersionSpecificationDiagnostic : DiagnosticBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W032OldLanguageVersionDiagnostic : DiagnosticBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W033ObsoletePortableClassLibrariesDiagnostic : DiagnosticBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Project2015To2017.Analysis;
using Project2015To2017.Definition;

namespace Project2015To2017.Analysis.Diagnostics
namespace Project2015To2017.Migrate2017.Diagnostics
{
public sealed class W034ReferenceAliasesDiagnostic : DiagnosticBase
{
Expand Down
46 changes: 46 additions & 0 deletions Project2015To2017.Migrate2017.Library/Vs15DiagnosticSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;
using Project2015To2017.Analysis;
using Project2015To2017.Analysis.Diagnostics;
using Project2015To2017.Migrate2017.Diagnostics;
using static Project2015To2017.Analysis.DiagnosticSet;

namespace Project2015To2017.Migrate2017
{
public static class Vs15DiagnosticSet
{
public static readonly IDiagnostic W020 = new W020MicrosoftCSharpDiagnostic();
public static readonly IDiagnostic W021 = new W021SystemNuGetPackagesDiagnostic();

public static readonly IDiagnostic W030 = new W030LegacyDebugTypesDiagnostic();
public static readonly IDiagnostic W031 = new W031MSBuildSdkVersionSpecificationDiagnostic();
public static readonly IDiagnostic W032 = new W032OldLanguageVersionDiagnostic();
public static readonly IDiagnostic W033 = new W033ObsoletePortableClassLibrariesDiagnostic();
public static readonly IDiagnostic W034 = new W034ReferenceAliasesDiagnostic();

public static readonly DiagnosticSet ModernIssues = new DiagnosticSet
{
W020,
W021,
};

public static readonly DiagnosticSet ModernizationTips = new DiagnosticSet
{
W030,
W031,
W032,
W033,
W034,
};

public static readonly DiagnosticSet All = new DiagnosticSet();

static Vs15DiagnosticSet()
{
All.UnionWith(DiagnosticSet.All);
All.UnionWith(ModernIssues);
All.UnionWith(ModernizationTips);
}
}
}
Loading

0 comments on commit cd2624f

Please sign in to comment.