-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] resx analyzer #3566
[WIP] resx analyzer #3566
Conversation
@@ -6,6 +6,7 @@ RS0042 | RoslynDiagnosticsReliability | Warning | DoNotCopyValue | |||
RS0043 | RoslynDiagnosticsMaintainability | Warning | DoNotCallGetTestAccessor | |||
RS0044 | RoslynDiagnosticsMaintainability | Hidden | CreateTestAccessor | |||
RS0045 | RoslynDiagnosticsMaintainability | Hidden | ExposeMemberForTesting | |||
RS0047 | RoslynDiagnosticsDesign | Info | DefineResourceEntryCorrectly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3352 is taking RS0046
} | ||
|
||
var isDescription = false; | ||
var sourceText = file.GetText(context.CancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried a couple of resx/xml loader but we either don't have the right dll or this is failing because of the first line of the resx which doesn't seem to be xml compliant. Let me know if you know a better way that doing line by line reading.
private static readonly Regex s_dataNameRegex = new Regex("<data.*?name=\"(.*?)\"", RegexOptions.Compiled); | ||
private static readonly Regex s_valueRegex = new Regex("<value>(.*?)</value>", RegexOptions.Compiled); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's never 100% clear to me when Compiled
is better.
private static readonly Regex s_dataNameRegex = new Regex("<data.*?name=\"(.*?)\"", RegexOptions.Compiled); | ||
private static readonly Regex s_valueRegex = new Regex("<value>(.*?)</value>", RegexOptions.Compiled); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI .*?
allows a non-greedy version of .*
this prevents unwanting characters! Besides, it's usually better in term of performances because it reduces the backtracking.
{ | ||
var text = line.ToString().Trim(); | ||
|
||
var match = s_dataNameRegex.Match(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go for this line by line check, do we want to have a StartsWith
check before the regex match?
if (endsWithPeriod && !isDescription) | ||
{ | ||
var linePositionSpan = sourceText.Lines.GetLinePositionSpan(line.Span); | ||
var location = Location.Create(file.Path, line.Span, linePositionSpan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we want to report? Full line? Only the .
?
else if (isDescription && !endsWithPeriod) | ||
{ | ||
var linePositionSpan = sourceText.Lines.GetLinePositionSpan(line.Span); | ||
var location = Location.Create(file.Path, line.Span, linePositionSpan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we want to report? Full line? The last character of the sentence?
@Evangelink Looking at the current implementation, I think my proposed idea of reporting diagnostics on resx files has few big drawbacks:
I think we should take the following direction:
Sorry for the long comment, we can discuss more offline for further ideas. |
Contributes to #3525