Skip to content

Code Action: Simplify Component tag to self-closing if body is empty and no child RenderFragment is required #11793

@Peter-Juhasz

Description

@Peter-Juhasz

It would help refactor this:

<Component Attribute="Value">
    
</Component>

To this:

<Component Attribute="Value" />

If the following conditions are met:

  • Markup element is a tag helper for a Component
  • It doesn't have any Attribute of type RenderFragment or RenderFragment<T> marked with EditorRequired (+ which is not bound via a markup attribute syntax (instead of body template))
  • It is not self-closed yet
  • Its body contains only whitespace

If accepted, I already have a draft working implementation for this in my fork/branch:
https://github.com/Peter-Juhasz/razor/blob/simplifytagtoselfclosing/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/SimplifyTagToSelfClosingCodeActionProvider.cs

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions