Skip to content

Analyzer should have exception for Razor component files to require PascalCase #21

@StevenTCramer

Description

@StevenTCramer

Issue

The kebab-case analyzer should have an exception for Razor component files (.razor) as they must be PascalCase.

Background

When Razor components are compiled, they become C# classes with the class name derived from the filename. For example:

  • _Imports.razor becomes the _Imports class
  • Counter.razor becomes the Counter class
  • MainLayout.razor becomes the MainLayout class

Using kebab-case for these files (like _imports.razor or main-layout.razor) causes compilation errors because:

  1. The generated class names would be invalid C# identifiers
  2. References to these components in code expect PascalCase names

Discovered During

This was discovered during the kebab-case migration of the timewarp-state project where renaming _imports.razor to lowercase caused build failures with errors like:

error CS0234: The type or namespace name '_Imports' does not exist in the namespace

Related Issue

This is related to the .NET issue: dotnet/razor#12131 which discusses Razor component naming requirements.

Recommendation

The analyzer should:

  1. Exclude all .razor files from kebab-case requirements
  2. Optionally enforce PascalCase for .razor files to match C# naming conventions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions