Skip to content
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

Check if analyzers are possible for Razor views #6

Open
ricardoboss opened this issue Nov 17, 2023 · 3 comments
Open

Check if analyzers are possible for Razor views #6

ricardoboss opened this issue Nov 17, 2023 · 3 comments

Comments

@ricardoboss
Copy link
Member

This would allow us to integrate https://www.caniemail.com/api/data.json and display warnings if we are using features not supported by our mail client targets.

@chucker
Copy link
Collaborator

chucker commented Nov 17, 2023

May not be so trivial. Roslyn doesn't seem to have an actual semantic model for the DOM; it writes most of it as literals. E.g.,

<head>
    <title></title>

    <style type="text/css">
        * { text-align: center;
        }
    </style>

…seems to become:

            WriteLiteral("\n<!DOCTYPE html>\n\n<html lang=\"en\">\n");
            __tagHelperExecutionContext = __tagHelperScopeManager.Begin("head", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "", async() => {
                WriteLiteral("\n    <title></title>\n\n    <style type=\"text/css\">\n        * { text-align: center;\n        }\n    </style>\n\n    ");

We can debug this behavior with <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> in the .csproj.

@chucker
Copy link
Collaborator

chucker commented Apr 22, 2024

Might be doable.

4>Sample.cshtml(25,11): Warning RzMa0001 : The tag '<details>' has limited support
image

@chucker
Copy link
Collaborator

chucker commented Apr 23, 2024

image

So I have a proof of concept, of sorts.

  • you add the analyzer as a NuGet package (this would be opt-in for now)
  • in your csproj, you define at least the <RazorMailAnalyzer_RequiredMailClients>gmail,outlook,apple-mail</RazorMailAnalyzer_RequiredMailClients> property; optionally also <RazorMailAnalyzer_OptionalMailClients>. The first contains e-mail clients that, if they don't fully support your markup, will raise a warning. The second contains e-mail clients that show as an informational message. (I've also considered making it three properties Error/Warning/Informational, so choosing the severity is more flexible and intuitive?)
  • in addition, we could also look at the platform. For example, Outlook on macOS vs. Windows vs. "New Outlook" are dramatically different in their support. The property could use a syntax like gmail,outlook@windows,apple-mail@ios.

Now, here come some caveats, aside from development for this being a drag (I've had VS crash, I've had the analyzer silently decide not to work, etc.):

  • I can only get the analyzer to refresh on explicit build, both in VS and in Rider. Neither will show live data, even if the file is frontmost. I've filed an issue with Roslyn, since that behavior seems odd to me, and perhaps I need to opt in to something.
  • while the diagnostic messages appear and double-clicking on them points to the right position (line, character) in the document, and they are classified as warnings, squiggly lines do not appear in VS nor in Rider.
  • I haven't yet looked much into actually parsing the JSON; it's mostly hardcoded stuff for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants