Skip to content

Commit

Permalink
Merge pull request #64 from naminodarie/feature/config_location
Browse files Browse the repository at this point in the history
Add config file path to diagnostics
  • Loading branch information
kzrnm authored Apr 7, 2021
2 parents 2046d35 + 7d012f4 commit e15c5b4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.1] - 2021-04-06
### Added
- SourceExpander.Embedder, SourceExpander.Generator: Add config file path to diagnostics

## [3.1.0] - 2021-04-06
### Added
- SourceExpander.Embedder: Add `minify-level` to Embedder config
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<RepositoryUrl>https://github.com/naminodarie/SourceExpander</RepositoryUrl>
<PackageReleaseNotes>https://github.com/naminodarie/SourceExpander/blob/master/CHANGELOG.md</PackageReleaseNotes>

<Version>3.1.0</Version>
<AssemblyVersion>3.1.0.100</AssemblyVersion>
<Version>3.1.1</Version>
<AssemblyVersion>3.1.1.100</AssemblyVersion>

<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)key.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace SourceExpander
{
public static class DiagnosticDescriptors
{
private static Location AdditionalFileLocation(string filePath) => Location.Create(filePath, new(), new());

public static Diagnostic EMBED0001_UnknownError(string message)
=> Diagnostic.Create(EMBED0001_UnknownError_Descriptor, Location.None, message);
private static readonly DiagnosticDescriptor EMBED0001_UnknownError_Descriptor = new(
Expand Down Expand Up @@ -37,7 +39,8 @@ public static Diagnostic EMBED0002_OlderVersion(Version embbederVersion, string
DiagnosticSeverity.Warning,
true);
public static Diagnostic EMBED0003_ParseConfigError(string configFile, string message)
=> Diagnostic.Create(EMBED0003_ParseConfigError_Descriptor, Location.None, configFile, message);
=> Diagnostic.Create(EMBED0003_ParseConfigError_Descriptor,
AdditionalFileLocation(configFile), configFile, message);
private static readonly DiagnosticDescriptor EMBED0003_ParseConfigError_Descriptor = new(
"EMBED0003",
new LocalizableResourceString(
Expand Down Expand Up @@ -158,8 +161,9 @@ public static Diagnostic EMBED0010_UsingAliasDirective(Location location)
true);


public static Diagnostic EMBED0011_ObsoleteConfigProperty(string obsoleteProperty, string insteadProperty)
=> Diagnostic.Create(EMBED0011_ObsoleteConfigProperty_Descriptor, Location.None, obsoleteProperty, insteadProperty);
public static Diagnostic EMBED0011_ObsoleteConfigProperty(string configFile, string obsoleteProperty, string insteadProperty)
=> Diagnostic.Create(EMBED0011_ObsoleteConfigProperty_Descriptor,
AdditionalFileLocation(configFile), obsoleteProperty, insteadProperty);
private static readonly DiagnosticDescriptor EMBED0011_ObsoleteConfigProperty_Descriptor = new(
"EMBED0011",
new LocalizableResourceString(
Expand Down
2 changes: 1 addition & 1 deletion Source/SourceExpander.Embedder/EmbedderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Execute(GeneratorExecutionContext context)
config = EmbedderConfig.Parse(configText);
foreach (var p in config.ObsoleteConfigProperties)
context.ReportDiagnostic(
DiagnosticDescriptors.EMBED0011_ObsoleteConfigProperty(p.Name, p.Instead));
DiagnosticDescriptors.EMBED0011_ObsoleteConfigProperty(configFile.Path, p.Name, p.Instead));
}
catch (ParseConfigException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace SourceExpander
{
public static class DiagnosticDescriptors
{
private static Location AdditionalFileLocation(string filePath) => Location.Create(filePath, new(), new());

public static Diagnostic EXPAND0001_UnknownError(string message)
=> Diagnostic.Create(EXPAND0001_UnknownError_Descriptor, Location.None, message);
private static readonly DiagnosticDescriptor EXPAND0001_UnknownError_Descriptor = new(
Expand Down Expand Up @@ -98,7 +100,8 @@ public static Diagnostic EXPAND0006_AllowUnsafe(string assemblyName)
DiagnosticSeverity.Warning,
true);
public static Diagnostic EXPAND0007_ParseConfigError(string configFile, string message)
=> Diagnostic.Create(EXPAND0007_ParseConfigError_Descriptor, Location.None, configFile, message);
=> Diagnostic.Create(EXPAND0007_ParseConfigError_Descriptor,
AdditionalFileLocation(configFile), configFile, message);
private static readonly DiagnosticDescriptor EXPAND0007_ParseConfigError_Descriptor = new(
"EXPAND0007",
new LocalizableResourceString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void EMBED0010()
[Fact]
public void EMBED0011()
{
DiagnosticDescriptors.EMBED0011_ObsoleteConfigProperty("old-property", "instead-property")
DiagnosticDescriptors.EMBED0011_ObsoleteConfigProperty(
"/home/user/SourceExpander.Embedder.Config.json", "old-property", "instead-property")
.GetMessage(formatProvider)
.Should()
.Be("Obsolete embedder config property. old-property is obsolete. Use instead-property.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void EMBED0010()
[Fact]
public void EMBED0011()
{
DiagnosticDescriptors.EMBED0011_ObsoleteConfigProperty("old-property", "instead-property")
DiagnosticDescriptors.EMBED0011_ObsoleteConfigProperty(
"/home/user/SourceExpander.Embedder.Config.json", "old-property", "instead-property")
.GetMessage(formatProvider)
.Should()
.Be("old-property は廃止されました。代わりに instead-property を使用してください");
Expand Down
27 changes: 20 additions & 7 deletions Test/SourceExpander.Embedder.Test/Generate/ConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ namespace SourceExpander.Embedder.Generate.Test
{
public class ConfigTest : EmbedderGeneratorTestBase
{
public static TheoryData ParseErrorJsons = new TheoryData<InMemorySourceText>
public static TheoryData ParseErrorJsons = new TheoryData<InMemorySourceText, object[]>
{
{
new InMemorySourceText(
"/foo/bar/SourceExpander.Embedder.Config.json", @"
"/foo/directory/SourceExpander.Embedder.Config.json", @"
{
""$schema"": ""https://raw.githubusercontent.com/naminodarie/SourceExpander/master/schema/embedder.schema.json"",
""embedding-type"": ""Raw"",
""exclude-attributes"": 1
}
")
"),
new object[]
{
"/foo/directory/SourceExpander.Embedder.Config.json",
"Error converting value 1 to type 'System.String[]'. Path 'exclude-attributes', line 5, position 27."
}
},
{
new InMemorySourceText(
Expand All @@ -29,13 +34,18 @@ public class ConfigTest : EmbedderGeneratorTestBase
""embedding-type"": ""Raw"",
""exclude-attributes"": 1
}
")
"),
new object[]
{
"/foo/bar/sourceExpander.embedder.config.json",
"Error converting value 1 to type 'System.String[]'. Path 'exclude-attributes', line 5, position 27."
}
},
};

[Theory]
[MemberData(nameof(ParseErrorJsons))]
public async Task ParseErrorTest(InMemorySourceText additionalText)
public async Task ParseError(InMemorySourceText additionalText, object[] diagnosticsArg)
{
var test = new Test
{
Expand Down Expand Up @@ -69,7 +79,9 @@ static void Main()
},
ExpectedDiagnostics =
{
DiagnosticResult.CompilerError("EMBED0003"),
DiagnosticResult.CompilerError("EMBED0003")
.WithSpan(additionalText.Path, 1, 1, 1, 1)
.WithArguments(diagnosticsArg),
}
}
};
Expand Down Expand Up @@ -1070,7 +1082,8 @@ public async Task ObsoleteConfigProperty(string configJson, (string Obsolete, st
foreach (var (obsolete, instead) in diagnosticsArgs)
test.ExpectedDiagnostics.Add(
new DiagnosticResult("EMBED0011", DiagnosticSeverity.Warning)
.WithArguments(obsolete, instead));
.WithSpan("/foo/bar/SourceExpander.Embedder.Config.json", 1, 1, 1, 1)
.WithArguments(obsolete, instead));
await test.RunAsync();
}

Expand Down
4 changes: 3 additions & 1 deletion Test/SourceExpander.Generator.Test/Generate/ConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ static void M()
},
ExpectedDiagnostics =
{
DiagnosticResult.CompilerError("EXPAND0007").WithArguments(diagnosticsArg),
DiagnosticResult.CompilerError("EXPAND0007")
.WithSpan(additionalText.Path, 1, 1, 1, 1)
.WithArguments(diagnosticsArg),
},
}
};
Expand Down

0 comments on commit e15c5b4

Please sign in to comment.