Skip to content

Commit 0c2dd7f

Browse files
committed
Switch PreferContentManagerDataLoader to refer to full asset name
1 parent b169de8 commit 0c2dd7f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/SMAPI.ModBuildConfig.Analyzer.Tests/ContentManagerAnalyzerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void BadType_RaisesDiagnostic(string codeText, int column, string assetNa
9797
DiagnosticResult preferDataLoader = new()
9898
{
9999
Id = "PreferContentManagerDataLoader",
100-
Message = $"'{assetName[5..]}' can be accessed using 'DataLoader.{assetName[5..]}(LocalizedContentManager content)' instead. See https://smapi.io/package/prefer-contentmanager-dataloader for details.",
100+
Message = $"'{assetName}' can be accessed using 'DataLoader.{assetName[5..]}(LocalizedContentManager content)' instead. See https://smapi.io/package/prefer-contentmanager-dataloader for details.",
101101
Severity = DiagnosticSeverity.Info,
102102
Locations = [new DiagnosticResultLocation("Test0.cs", SampleCodeLine, SampleCodeColumn + column)]
103103
};
@@ -114,15 +114,15 @@ public void BadType_RaisesDiagnostic(string codeText, int column, string assetNa
114114
/// <param name="expression">The expression which should be reported.</param>
115115
/// <param name="netType">The net type name which should be reported.</param>
116116
/// <param name="suggestedProperty">The suggested property name which should be reported.</param>
117-
[TestCase("Game1.content.Load<Dictionary<string, string>>(\"Data\\\\Fish\");", 0, "Fish")]
117+
[TestCase("Game1.content.Load<Dictionary<string, string>>(\"Data\\\\Fish\");", 0, "Data\\Fish")]
118118
public void PreferDataLoader_RaisesDiagnostic(string codeText, int column, string assetName)
119119
{
120120
// arrange
121121
string code = SampleProgram.Replace("{{test-code}}", codeText);
122122
DiagnosticResult preferDataLoader = new()
123123
{
124124
Id = "PreferContentManagerDataLoader",
125-
Message = $"'{assetName}' can be accessed using 'DataLoader.{assetName}(LocalizedContentManager content)' instead. See https://smapi.io/package/prefer-contentmanager-dataloader for details.",
125+
Message = $"'{assetName}' can be accessed using 'DataLoader.{assetName[5..]}(LocalizedContentManager content)' instead. See https://smapi.io/package/prefer-contentmanager-dataloader for details.",
126126
Severity = DiagnosticSeverity.Info,
127127
Locations = [new DiagnosticResultLocation("Test0.cs", SampleCodeLine, SampleCodeColumn + column)]
128128
};

src/SMAPI.ModBuildConfig.Analyzer/ContentManagerAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ContentManagerAnalyzer : DiagnosticAnalyzer
3030
private readonly DiagnosticDescriptor PreferDataLoader = new(
3131
id: "PreferContentManagerDataLoader",
3232
title: "Prefer using DataLoader to ContentManager Loads",
33-
messageFormat: "'{0}' can be accessed using 'DataLoader.{0}(LocalizedContentManager content)' instead. See https://smapi.io/package/prefer-contentmanager-dataloader for details.",
33+
messageFormat: "'{0}' can be accessed using 'DataLoader.{1}(LocalizedContentManager content)' instead. See https://smapi.io/package/prefer-contentmanager-dataloader for details.",
3434
category: "SMAPI.CommonErrors",
3535
defaultSeverity: DiagnosticSeverity.Info,
3636
isEnabledByDefault: true,
@@ -79,7 +79,7 @@ private void AnalyzeContentManagerLoads(SyntaxNodeAnalysisContext context)
7979
{
8080
context.ReportDiagnostic(Diagnostic.Create(this.AvoidBadTypeRule, context.Node.GetLocation(), assetName, method.ReturnType.ToString(), genericArgument.ToString()));
8181
}
82-
context.ReportDiagnostic(Diagnostic.Create(this.PreferDataLoader, context.Node.GetLocation(), dataAsset));
82+
context.ReportDiagnostic(Diagnostic.Create(this.PreferDataLoader, context.Node.GetLocation(), assetName, dataAsset));
8383
}
8484
}
8585
}

0 commit comments

Comments
 (0)