Skip to content

Commit cec55ab

Browse files
committed
Files generated by source generator have relative path (fix #876)
1 parent 8c633e9 commit cec55ab

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Analyzers/CSharp/Analysis/AnalyzerOptionIsObsoleteAnalyzer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System;
44
using System.Collections.Immutable;
5+
using System.IO;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
78

@@ -50,6 +51,10 @@ public override void Initialize(AnalysisContext context)
5051

5152
compilationContext.RegisterSyntaxTreeAction(context =>
5253
{
54+
// files generated by source generator have relative path
55+
if (!Path.IsPathRooted(context.Tree.FilePath))
56+
return;
57+
5358
if (!CommonDiagnosticRules.AnalyzerOptionIsObsolete.IsEffective(context.Tree, compilationOptions, context.CancellationToken))
5459
return;
5560

src/Analyzers/CSharp/Analysis/RequiredConfigOptionNotSetAnalyzer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System;
44
using System.Collections.Immutable;
5+
using System.IO;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
78

@@ -50,6 +51,10 @@ public override void Initialize(AnalysisContext context)
5051

5152
compilationContext.RegisterSyntaxTreeAction(context =>
5253
{
54+
// files generated by source generator have relative path
55+
if (!Path.IsPathRooted(context.Tree.FilePath))
56+
return;
57+
5358
if (!CommonDiagnosticRules.RequiredConfigOptionNotSet.IsEffective(context.Tree, compilationOptions, context.CancellationToken))
5459
return;
5560

src/Formatting.Analyzers/CSharp/AnalyzerOptionIsObsoleteAnalyzer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System;
44
using System.Collections.Immutable;
5+
using System.IO;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
78

@@ -46,6 +47,10 @@ public override void Initialize(AnalysisContext context)
4647

4748
compilationContext.RegisterSyntaxTreeAction(context =>
4849
{
50+
// files generated by source generator have relative path
51+
if (!Path.IsPathRooted(context.Tree.FilePath))
52+
return;
53+
4954
if (!CommonDiagnosticRules.AnalyzerOptionIsObsolete.IsEffective(context.Tree, compilationOptions, context.CancellationToken))
5055
return;
5156

src/Formatting.Analyzers/CSharp/RequiredConfigOptionNotSetAnalyzer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System;
44
using System.Collections.Immutable;
5+
using System.IO;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
78

@@ -46,6 +47,10 @@ public override void Initialize(AnalysisContext context)
4647

4748
compilationContext.RegisterSyntaxTreeAction(context =>
4849
{
50+
// files generated by source generator have relative path
51+
if (!Path.IsPathRooted(context.Tree.FilePath))
52+
return;
53+
4954
if (!CommonDiagnosticRules.RequiredConfigOptionNotSet.IsEffective(context.Tree, compilationOptions, context.CancellationToken))
5055
return;
5156

0 commit comments

Comments
 (0)