From 71c36e7bbe96bdc6dffa7e83facb7b69b84635a7 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sat, 29 Nov 2025 17:58:38 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 11 ++ README.md | 3 + commands/format-params.md | 258 +++++++++++++++++++++++++++++++++++++ plugin.lock.json | 45 +++++++ 4 files changed, 317 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/format-params.md create mode 100644 plugin.lock.json diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..5cdd130 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,11 @@ +{ + "name": "code-refactoring", + "description": "Code refactoring tools for applying consistent formatting and style across C# projects", + "version": "1.0.0", + "author": { + "name": "atc-net" + }, + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1209924 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# code-refactoring + +Code refactoring tools for applying consistent formatting and style across C# projects diff --git a/commands/format-params.md b/commands/format-params.md new file mode 100644 index 0000000..5c52e48 --- /dev/null +++ b/commands/format-params.md @@ -0,0 +1,258 @@ +# Format Method Parameters + +Apply consistent method parameter line break formatting across all C# projects in the repository. + +## Scope: What to Format + +**ALL projects:** + +All *.cs files EXCEPT auto-generated code. +Exclude files with: + +- "generated", ".g.cs", ".designer.cs" in filename +- AssemblyInfo.cs files +- [GeneratedCode] or [GeneratedCodeAttribute] +- tags +- "auto-generated" in headers +- "This code was generated by a tool" + +**ONLY format parameter lists in DECLARATIONS:** + +- ✅ Method declarations (public, private, protected, internal, static, async, virtual, override, abstract, etc.) +- ✅ Constructor declarations +- ✅ Local function declarations (functions defined inside methods) +- ✅ Delegate declarations + +**DO NOT format parameter lists in INVOCATIONS or EXPRESSIONS:** + +- ❌ Method calls/invocations (e.g., `.Replace(...)`, `.Substring(...)`) +- ❌ Constructor invocations (e.g., `new MyClass(...)`) +- ❌ Ternary operators (e.g., `condition ? value1 : value2`) +- ❌ Lambda expressions (e.g., `(x, y) => x + y`) +- ❌ LINQ query expressions +- ❌ Indexer property declarations (e.g., `this[int x, int y]`) + +## Formatting Rules + +### Rule 1: Multiple Parameters + +Break down **all parameters** if a method has **more than 1 parameter**, with each parameter on its own line. + +### Rule 2: Single Long Parameter + +Break down a **single parameter** if the total line length (including indentation) exceeds **80 characters**. + +## Examples: What TO Format + +### Method Declarations + +```csharp +// No parameters - no break +public void MyMethod1() + +// Single short parameter - no break +public void MyMethod2(int parameter1) + +// Single parameter, method name long but total < 80 chars - no break +public void MyLoooooooooooooooooooooooooooooooooooooooonMethod3(int parameter1) + +// Single parameter, total length > 80 chars - break +public void MyLooooooooooooooooooooooooooooooooooooooooooonMethod4( + int parameter1) + +// 2 parameters - break all +public void MyMethod5( + int parameter1, + int parameter2) + +// 3+ parameters - break all +public void MyMethod6( + int parameter1, + int parameter2, + int parameter3) +``` + +### Constructor Declarations + +```csharp +// Single parameter - no break +public MyClass(string name) + +// Multiple parameters - break all +public MyClass( + string name, + int age, + bool isActive) +``` + +### Local Function Declarations + +```csharp +public void OuterMethod() +{ + // Local function with multiple parameters - break all + void LocalFunction( + int param1, + string param2) + { + // implementation + } +} +``` + +### Delegate Declarations + +```csharp +// Multiple parameters - break all +public delegate void MyEventHandler( + object sender, + EventArgs e); + +// Single parameter - no break +public delegate void SimpleHandler(string message); +``` + +## Examples: What NOT TO Format + +**These should remain unchanged - do not modify invocations or expressions:** + +```csharp +// ❌ Method invocations - DO NOT format these +var result = assembly.GetBeautifiedName().Replace("Api", "API", StringComparison.Ordinal); + +var name = someObject.SomeMethod(arg1, arg2, arg3); + +// ❌ Constructor invocations - DO NOT format these +var obj = new MyClass(param1, param2, param3); + +// ❌ Ternary operators - DO NOT format these +return condition ? value1 : value2; + +return removeLastVerb + ? assemblyName.Substring(0, assemblyName.LastIndexOf(' ')) + : assemblyName; + +// ❌ Lambda expressions - DO NOT format these +var filtered = items.Where((item, index) => item.IsActive && index > 0); + +// ❌ LINQ expressions - DO NOT format these +var query = from item in items + where item.IsActive + select new { item.Name, item.Value }; + +// ❌ Indexer declarations - DO NOT format these +public string this[int row, int column] +{ + get => matrix[row, column]; +} +``` + +## Execution Instructions + +### 1. Scan for C# files + +Find all `.cs` files in the repository + +### 2. Identify DECLARATIONS (not invocations) + +**Look for these patterns to identify declarations:** + +**Method declarations:** + +- Lines starting with access modifiers: `public`, `private`, `protected`, `internal` +- Lines with method modifiers: `static`, `virtual`, `override`, `abstract`, `async`, `sealed` +- Pattern: `[modifiers] [return-type] [method-name]([parameters])` +- Must have a return type (or `void`) before the method name +- Usually followed by `{`, `;`, or `=>` + +**Constructor declarations:** + +- Pattern: `[modifiers] [class-name]([parameters])` +- Class name matches the containing class +- No return type before the name + +**Local function declarations:** + +- Found inside method bodies +- Pattern: `[return-type] [function-name]([parameters])` +- Usually indented inside a method + +**Delegate declarations:** + +- Pattern: `[modifiers] delegate [return-type] [delegate-name]([parameters]);` +- Contains the `delegate` keyword + +**Key distinction from invocations:** + +- Declarations have modifiers (public, private, static, etc.) OR are preceded by a type +- Invocations follow a `.` (member access), are on the right side of `=`, or are arguments to other methods +- Invocations do NOT have return types or access modifiers + +### 3. Apply formatting rules + +**For each declaration found:** + +- If 2+ parameters: break all parameters onto separate lines +- If 1 parameter: break only if total line length > 80 characters +- Ensure proper indentation (4 spaces per indentation level) +- Place opening parenthesis `(` on same line as method name +- Place each parameter on its own line with proper indentation +- Keep closing parenthesis `)` on same line as last parameter + +### 4. Process in batches + +Work on files in manageable batches (e.g., 10-20 files at a time) + +### 5. Verify after each batch + +Run `dotnet build` to ensure no syntax errors + +### 6. Track progress + +Use todo list to track which files have been processed + +### 7. Final verification + +Run full test suite after all changes complete + +## Important Notes + +- **Preserve all code logic and comments** +- **Maintain existing indentation style** (spaces vs tabs) +- **Handle edge cases**: attributes, generic types, default values, nullable types, ref/out/in parameters +- **Do not modify method bodies** - only parameter declarations +- **Do not modify method invocations** - only declarations +- **Leave ternary operators unchanged** +- **Leave lambda expressions unchanged** +- **Leave LINQ expressions unchanged** +- **If uncertain whether something is a declaration or invocation**, skip it and flag for manual review + +## Pattern Recognition Examples + +### ✅ These are DECLARATIONS (format these) + +```csharp +public void MyMethod(int x, int y) // Method declaration +private async Task GetDataAsync(string id) // Async method declaration +protected virtual bool TryParse(string input, out int result) // Virtual method with out param +internal static MyClass Create(string name, int age) // Static method declaration +public MyClass(string name, int age) // Constructor declaration +delegate void EventHandler(object sender, EventArgs e) // Delegate declaration + +void LocalFunc(int a, int b) // Local function (inside a method) +{ + // ... +} +``` + +### ❌ These are INVOCATIONS or EXPRESSIONS (do NOT format) + +```csharp +var result = MyMethod(x, y); // Method invocation +var name = assembly.GetName().Replace("old", "new", StringComparison.Ordinal); // Chained invocations +var obj = new MyClass(name, age); // Constructor invocation +return condition ? value1 : value2; // Ternary operator +var lambda = (int x, int y) => x + y; // Lambda expression +items.Where((item, index) => item.IsActive) // Lambda in method call +var value = this[row, column]; // Indexer usage +``` diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..87f47a8 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,45 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:atc-net/atc-agentic-toolkit:.claude/plugins/code-refactoring", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "346d6bd3d831e5a0f88a8ca4910d5d55af391c13", + "treeHash": "2699ae9e5d0631e9737d8d9da5fafb64d0c80c9594e992c13bec25fcee5dd9b1", + "generatedAt": "2025-11-28T10:13:58.463357Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "code-refactoring", + "description": "Code refactoring tools for applying consistent formatting and style across C# projects", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "a7c0ec3d8583e6bca96f31544d1cb7439a507d4c2022366facce224abcbb5ccf" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "01aa8a96707a769d4eeefb8ec717e0ea450d29f676a92236388d1727e7e188fb" + }, + { + "path": "commands/format-params.md", + "sha256": "87b1ee05377bfa89666332f64d7d41905ee60329407efeadfb104c49060f3d8f" + } + ], + "dirSha256": "2699ae9e5d0631e9737d8d9da5fafb64d0c80c9594e992c13bec25fcee5dd9b1" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file