Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ dotnet_naming_style.local_function_style.capitalization = pascal_case

# dotnet_diagnostic options
dotnet_diagnostic.CS1591.severity = none
dotnet_diagnostic.TW0001.severity = suggestion
dotnet_diagnostic.TWD001.severity = warning
dotnet_diagnostic.TW0003.severity = none # Set to warning/error to enforce kebab-case file naming
dotnet_diagnostic.TW0003.excluded_files = *.g.cs;*.Generated.cs;*.generated.cs;*.designer.cs;*.Designer.cs;Directory.Build.props;Directory.Build.targets;Directory.Packages.props;AssemblyInfo.cs;*.AssemblyAttributes.cs;AnalyzerReleases.Shipped.md;AnalyzerReleases.Unshipped.md
dotnet_diagnostic.TWA001.severity = none # Set to warning/error to enforce kebab-case file naming
dotnet_diagnostic.TWA001.excluded_files = *.g.cs;*.Generated.cs;*.generated.cs;*.designer.cs;*.Designer.cs;*.razor.cs;Directory.Build.props;Directory.Build.targets;Directory.Packages.props;AssemblyInfo.cs;*.AssemblyAttributes.cs;AnalyzerReleases.Shipped.md;AnalyzerReleases.Unshipped.md

#### Analyzer settings ####
dotnet_code_quality.null_check_validation_methods = NotNull
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Authors>Steven T. Cramer</Authors>
<Product>TimeWarp.SourceGenerators</Product>
<PackageId>TimeWarp.SourceGenerators</PackageId>
<PackageVersion>1.0.0-beta.3</PackageVersion>
<PackageVersion>1.0.0-beta.4</PackageVersion>
<PackageProjectUrl>https://timewarpengineering.github.io/timewarp-source-generators/</PackageProjectUrl>
<PackageTags>TimeWarp; Source Generator;SourceGenerators; Delegate</PackageTags>
<PackageIcon>logo.png</PackageIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ AnalyzerReleases.Unshipped.md:
### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
TW0001 | SourceGenerator | Info | HelloWorldGenerator
TW0002 | SourceGenerator | Info | MarkdownDocsGenerator
TW0003 | Naming | Info | FileNameRuleAnalyzer, disabled by default
TWG001 | SourceGenerator | Info | MarkdownDocsGenerator
TWA001 | Naming | Info | FileNameRuleAnalyzer, disabled by default
TWA002 | Documentation | Info | XmlDocsToMarkdownAnalyzer

AnalyzerReleases.Shipped.md:
## Release 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# FileNameRuleAnalyzer (TW0003)
# FileNameRuleAnalyzer (TWA001)

## Overview

The FileNameRuleAnalyzer enforces kebab-case naming conventions for C# source files. This analyzer helps maintain consistent file naming across projects that prefer kebab-case (e.g., `my-component.cs`) over traditional PascalCase.

## Rule Details

- **Rule ID**: TW0003
- **Rule ID**: TWA001
- **Category**: Naming
- **Default Severity**: Info (disabled by default)
- **Message**: File '{0}' should use kebab-case naming convention (e.g., 'my-file.cs')
Expand Down Expand Up @@ -41,25 +41,26 @@ The analyzer is disabled by default to avoid breaking existing projects. To enab

```ini
# Enable with warning severity
dotnet_diagnostic.TW0003.severity = warning
dotnet_diagnostic.TWA001.severity = warning

# Or as an error to fail builds
dotnet_diagnostic.TW0003.severity = error
dotnet_diagnostic.TWA001.severity = error

# Or as a suggestion for gentle nudging
dotnet_diagnostic.TW0003.severity = suggestion
dotnet_diagnostic.TWA001.severity = suggestion
```

### Exception Patterns

Configure files that should be excluded from the rule:

```ini
dotnet_diagnostic.TW0003.excluded_files = *.g.cs;*.Generated.cs;GlobalUsings.cs;Program.cs;Startup.cs
dotnet_diagnostic.TWA001.excluded_files = *.g.cs;*.Generated.cs;GlobalUsings.cs;Program.cs;Startup.cs
```

Default exceptions include:
- Generated files (`*.g.cs`, `*.Generated.cs`, `*.designer.cs`)
- Razor component code-behind files (`*.razor.cs`) - must match their `.razor` file names
- Build files (`Directory.Build.props`, `Directory.Build.targets`, `Directory.Packages.props`)
- Assembly metadata (`AssemblyInfo.cs`)
- Analyzer tracking files (`AnalyzerReleases.Shipped.md`, `AnalyzerReleases.Unshipped.md`)
Expand Down Expand Up @@ -87,10 +88,10 @@ In your root `.editorconfig`:
```ini
[*.cs]
# Enable kebab-case file naming for all C# files
dotnet_diagnostic.TW0003.severity = warning
dotnet_diagnostic.TWA001.severity = warning

# But allow exceptions for specific patterns
dotnet_diagnostic.TW0003.excluded_files = *.g.cs;*.Generated.cs;*.designer.cs;Program.cs;Startup.cs;GlobalUsings.cs;AssemblyInfo.cs
dotnet_diagnostic.TWA001.excluded_files = *.g.cs;*.Generated.cs;*.designer.cs;Program.cs;Startup.cs;GlobalUsings.cs;AssemblyInfo.cs
```

### Gradual Adoption
Expand All @@ -99,29 +100,29 @@ For existing projects, start with suggestion severity:

```ini
[*.cs]
dotnet_diagnostic.TW0003.severity = suggestion
dotnet_diagnostic.TWA001.severity = suggestion

# Only enforce in new feature folders
[Features/**.cs]
dotnet_diagnostic.TW0003.severity = warning
dotnet_diagnostic.TWA001.severity = warning
```

## Suppressing Violations

For specific files that need exceptions beyond the configured patterns:

```csharp
#pragma warning disable TW0003 // File name should use kebab-case
#pragma warning disable TWA001 // File name should use kebab-case
// File: LegacyAPIClient.cs
#pragma warning restore TW0003
#pragma warning restore TWA001
```

Or in the project file:

```xml
<ItemGroup>
<Compile Update="LegacyAPIClient.cs">
<AnalyzerSuppression>TW0003</AnalyzerSuppression>
<AnalyzerSuppression>TWA001</AnalyzerSuppression>
</Compile>
</ItemGroup>
```
14 changes: 7 additions & 7 deletions documentation/developer/reference/analyzers/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## Available Analyzers

### TW0003 - File Name Rule Analyzer
### TWA001 - File Name Rule Analyzer

Enforces kebab-case naming convention for C# source files.

- **Rule ID**: TW0003
- **Rule ID**: TWA001
- **Category**: Naming
- **Default Severity**: Info (disabled)
- **Configuration**: `.editorconfig`
Expand All @@ -19,10 +19,10 @@ All analyzers are configured through `.editorconfig`:

```ini
# Enable an analyzer
dotnet_diagnostic.TW0003.severity = warning
dotnet_diagnostic.TWA001.severity = warning

# Configure exceptions
dotnet_diagnostic.TW0003.excluded_files = *.g.cs;*.Generated.cs
dotnet_diagnostic.TWA001.excluded_files = *.g.cs;*.Generated.cs
```

## Analyzer Categories
Expand All @@ -34,15 +34,15 @@ dotnet_diagnostic.TW0003.excluded_files = *.g.cs;*.Generated.cs

1. **File-level pragma**:
```csharp
#pragma warning disable TW0003
#pragma warning disable TWA001
```

2. **Project-wide**:
```xml
<NoWarn>TW0003</NoWarn>
<NoWarn>TWA001</NoWarn>
```

3. **EditorConfig**:
```ini
dotnet_diagnostic.TW0003.severity = none
dotnet_diagnostic.TWA001.severity = none
```
10 changes: 1 addition & 9 deletions documentation/developer/reference/source-generators/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

## Available Source Generators

### HelloWorldGenerator (TW0001)

A simple demonstration source generator that creates a static class with a hello message.

- **Generated File**: `HelloWorld.g.cs`
- **Namespace**: `TimeWarp.Generated`
- **Diagnostic**: Info message when loaded

### MarkdownDocsGenerator (TW0002)
### MarkdownDocsGenerator (TWG001)

Generates XML documentation from markdown files for C# classes.

Expand Down
3 changes: 1 addition & 2 deletions documentation/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ Technical documentation for developers using or contributing to the project.
## What's Included

### Source Generators
- **HelloWorldGenerator** - Example generator
- **MarkdownDocsGenerator** - Generates markdown from XML docs

### Analyzers
- **TW0003** - File name kebab-case enforcement
- **TWA001** - File name kebab-case enforcement

## Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
TW0001 | SourceGenerator | Info | HelloWorldGenerator
TW0002 | SourceGenerator | Info | MarkdownDocsGenerator - Enhanced to support kebab-case file matching
TW0003 | Naming | Info | FileNameRuleAnalyzer, disabled by default
TW0004 | Documentation | Info | XmlDocsToMarkdownAnalyzer
TWG001 | SourceGenerator | Info | MarkdownDocsGenerator - Enhanced to support kebab-case file matching
TWA001 | Naming | Info | FileNameRuleAnalyzer, disabled by default
TWA002 | Documentation | Info | XmlDocsToMarkdownAnalyzer
5 changes: 3 additions & 2 deletions source/timewarp-source-generators/file-name-rule-analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace TimeWarp.SourceGenerators;
[Generator]
public class FileNameRuleAnalyzer : IIncrementalGenerator
{
public const string DiagnosticId = "TW0003";
public const string DiagnosticId = "TWA001";
private const string Category = "Naming";

private static readonly DiagnosticDescriptor Rule = new(
Expand All @@ -27,6 +27,7 @@ public class FileNameRuleAnalyzer : IIncrementalGenerator
"*.generated.cs",
"*.designer.cs",
"*.Designer.cs",
"*.razor.cs", // Razor component code-behind files must match their .razor file names
"Directory.Build.props",
"Directory.Build.targets",
"Directory.Packages.props",
Expand Down Expand Up @@ -98,7 +99,7 @@ private string[] GetConfiguredExceptions(AnalyzerConfigOptionsProvider configOpt

// Try to get configured exceptions from .editorconfig
if (options.TryGetValue(
"dotnet_diagnostic.TW0003.excluded_files",
"dotnet_diagnostic.TWA001.excluded_files",
out string? configuredExceptions) && !string.IsNullOrEmpty(configuredExceptions))
{
// Split by semicolon and trim whitespace
Expand Down
60 changes: 0 additions & 60 deletions source/timewarp-source-generators/hello-world-generator.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class MarkdownDocsGenerator : IIncrementalGenerator
// Regex pattern for checking if a file name is kebab-case
private static readonly Regex KebabCasePattern = new(@"^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$", RegexOptions.Compiled);
private static readonly DiagnosticDescriptor MarkdownDocsGeneratorLoadedDescriptor = new(
id: "TW0002",
id: "TWG001",
title: "MarkdownDocs Generator Loaded",
messageFormat: "The MarkdownDocs generator has been loaded and initialized",
category: "SourceGenerator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace TimeWarp.SourceGenerators;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class XmlDocsToMarkdownAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticId = "TW0004";
public const string DiagnosticId = "TWA002";
private const string Category = "Documentation";

private static readonly DiagnosticDescriptor Rule = new(
Expand Down
8 changes: 4 additions & 4 deletions tests/timewarp-source-generators-test-console/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root = true

[*.cs]

dotnet_diagnostic.TW0003.severity = error # Set to warning/error to enforce kebab-case file naming
dotnet_diagnostic.TW0003.excluded_files = PascalCaseTest.cs
# Enable TW0004 - XML documentation to markdown analyzer
dotnet_diagnostic.TW0004.severity = suggestion
dotnet_diagnostic.TWA001.severity = error # Set to warning/error to enforce kebab-case file naming
dotnet_diagnostic.TWA001.excluded_files = PascalCaseTest.cs
# Enable TWA002 - XML documentation to markdown analyzer
dotnet_diagnostic.TWA002.severity = suggestion

This file was deleted.

3 changes: 0 additions & 3 deletions tests/timewarp-source-generators-test-console/program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using TimeWarp.Generated;
using TimeWarp.SourceGenerators.TestConsole;

Console.WriteLine(HelloWorld.Message);

// Test kebab-case file matching
var kebabTest = new KebabCaseTest();
Console.WriteLine($"Kebab-case test: {kebabTest.GetTestMessage()}");
Expand Down