Skip to content

Commit

Permalink
Merge pull request #138 from leancodepl/fix-analyzer-thread-safety
Browse files Browse the repository at this point in the history
Fix analyzer thread safety and stray nullability warning
  • Loading branch information
Saancreed authored Jun 20, 2023
2 parents b0bda21 + 057bd0e commit 2081a09
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/LeanCode.ContractsGenerator/AnalyzeFailedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class AnalyzeFailedException : Exception
public IReadOnlyList<AnalyzeError> Errors { get; }

public AnalyzeFailedException(IReadOnlyList<AnalyzeError> errors)
: base("Analyze phase failed.")
: base(string.Join('\n', errors.Select(e => e.ToString()).Prepend("Analyze phase failed.")))
{
Errors = errors;
}
Expand Down
4 changes: 2 additions & 2 deletions src/LeanCode.ContractsGenerator/Analyzers/AllAnalyzers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace LeanCode.ContractsGenerator.Analyzers;

public class AllAnalyzers : IAnalyzer
{
private static readonly IReadOnlyList<IAnalyzer> Analyzers = new IAnalyzer[]
private readonly IReadOnlyList<IAnalyzer> analyzers = new IAnalyzer[]
{
new InternalStructureCheck(),
new KnownTypeCheck(),
Expand All @@ -13,6 +13,6 @@ public class AllAnalyzers : IAnalyzer

public IEnumerable<AnalyzeError> Analyze(Export export)
{
return Analyzers.SelectMany(a => a.Analyze(export));
return analyzers.SelectMany(a => a.Analyze(export));
}
}
6 changes: 4 additions & 2 deletions src/LeanCode.ContractsGenerator/Compilation/ProjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ await Console.Error.WriteLineAsync(
foreach (var projectPath in projectPathsList)
{
if (msbuildWorkspace.CurrentSolution.Projects
.Where(p => p.FilePath is not null)
.Any(p => ResolveCanonicalPath(p.FilePath) == projectPath))
.Select(p => p.FilePath)
.OfType<string>()
.Select(ResolveCanonicalPath)
.Contains(projectPath))
{
continue;
}
Expand Down
5 changes: 4 additions & 1 deletion src/LeanCode.ContractsGenerator/IAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ public interface IAnalyzer
IEnumerable<AnalyzeError> Analyze(Export export);
}

public record AnalyzeError(string Code, string Message, AnalyzerContext Context);
public record AnalyzeError(string Code, string Message, AnalyzerContext Context)
{
public override string ToString() => $"{Code}: {Message}\n at {Context.Path}";
}

0 comments on commit 2081a09

Please sign in to comment.