Skip to content

Commit b05fc96

Browse files
committed
Ignore missing classname error
1 parent 2c9fd5d commit b05fc96

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/CSSErrorCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Microsoft.CodeAnalysis.Razor.Diagnostics;
77
internal static class CSSErrorCodes
88
{
99
public const string UnrecognizedBlockType = "CSS002";
10+
public const string MissingClassNameAfterDot = "CSS008";
1011
public const string MissingOpeningBrace = "CSS023";
1112
public const string MissingSelectorAfterCombinator = "CSS029";
1213
public const string MissingSelectorBeforeCombinatorCode = "CSS031";

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private static bool ShouldFilterHtmlDiagnosticBasedOnErrorCode(LspDiagnostic dia
241241
{
242242
CSSErrorCodes.UnrecognizedBlockType => IsEscapedAtSign(diagnostic, sourceText),
243243
CSSErrorCodes.MissingOpeningBrace => IsCSharpInStyleBlock(diagnostic, sourceText, syntaxTree),
244+
CSSErrorCodes.MissingClassNameAfterDot => IsCSharpInStyleBlock(diagnostic, sourceText, syntaxTree),
244245
CSSErrorCodes.MissingSelectorAfterCombinator => IsCSharpInStyleBlock(diagnostic, sourceText, syntaxTree),
245246
CSSErrorCodes.MissingSelectorBeforeCombinatorCode => IsCSharpInStyleBlock(diagnostic, sourceText, syntaxTree),
246247
HtmlErrorCodes.UnexpectedEndTagErrorCode => IsHtmlWithBangAndMatchingTags(diagnostic, sourceText, syntaxTree),

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentPullDiagnosticsTest.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,40 @@ public Task FilterRazorCommentsFromCss_Inside()
163163
}]);
164164
}
165165

166+
[Fact]
167+
public Task FilterMissingClassNameInCss()
168+
{
169+
TestCode input = """
170+
<div>
171+
172+
<style>
173+
.@(className)
174+
background-color: lightblue;
175+
}
176+
</style>
177+
178+
</div>
179+
180+
@code
181+
{
182+
private string className = "foo";
183+
}
184+
""";
185+
186+
return VerifyDiagnosticsAsync(input,
187+
htmlResponse: [new VSInternalDiagnosticReport
188+
{
189+
Diagnostics =
190+
[
191+
new Diagnostic
192+
{
193+
Code = CSSErrorCodes.MissingClassNameAfterDot,
194+
Range = SourceText.From(input.Text).GetRange(new TextSpan(input.Text.IndexOf("@"), 1))
195+
},
196+
]
197+
}]);
198+
}
199+
166200
[Fact]
167201
public Task CombinedAndNestedDiagnostics()
168202
=> VerifyDiagnosticsAsync("""

0 commit comments

Comments
 (0)