You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a tool that can be used to analyze and fix named arguments in codebase.
4
-
It is implemented as a Analyzer and CodeFix provider for Roslyn.
3
+
This is a Roslyn analyzer and code fix provider that enforces the use of named arguments in C# method calls and object creations. It helps improve code readability by requiring named arguments for methods with multiple parameters, while allowing exclusions for commonly used methods where positional arguments are preferred.
4
+
5
+
## Features
6
+
7
+
-**Diagnostic**: Warns when positional arguments are used in method calls or object creations with multiple parameters.
8
+
-**Code Fix**: Automatically adds named arguments to fix the diagnostic.
9
+
-**Configurable**: Supports configuration via .editorconfig files to customize behavior.
10
+
-**Exclusions**: Built-in list of excluded methods where positional arguments are acceptable, with options to add custom exclusions.
11
+
-**Record Support**: Optional mode to only analyze record types.
5
12
6
13
## Installation
7
-
There should be a NuGet package available for this project.
8
-
9
-
## configuration
10
-
<b>How to Configure Settings for NamedArgumentsAnalyzer</b>
11
-
12
-
OnlyForRecords is a boolean and standard value is false.
13
-
setting that determines whether the analyzer should only apply to record types. If set to true,
14
-
the analyzer will only analyze named arguments in record types. If set to false,
15
-
it will analyze named arguments in all types.
16
-
17
-
UseDefaultExcludedMethods is a boolean and standard value is true.
18
-
if UseDefaultExcludedMethods is true, the following methods will be excluded by default:
Note: `string.Replace` is excluded by default, so this example won't trigger in practice. Use custom methods or disable exclusions to see the behavior.
54
+
55
+
## Configuration
56
+
57
+
The analyzer supports several configuration options via .editorconfig files.
58
+
59
+
### Options
60
+
61
+
-**OnlyForRecords** (boolean, default: false): If true, only analyzes method calls on record types.
62
+
-**UseDefaultExcludedMethods** (boolean, default: true): If true, uses the built-in list of excluded methods.
63
+
-**ExcludedMethodNames** (string, default: ""): Comma-separated list of additional method names to exclude.
64
+
65
+
If `UseDefaultExcludedMethods` is true, the following methods are excluded by default:
66
+
"char.Equals",
67
+
"char.CompareTo",
68
+
"char.GetUnicodeCategory",
69
+
"char.IsControl",
70
+
"char.IsDigit",
71
+
"char.IsLetter",
72
+
"char.IsLetterOrDigit",
73
+
"char.IsLower",
74
+
"char.IsNumber",
75
+
"char.IsPunctuation",
76
+
"char.IsSeparator",
77
+
"char.IsSurrogate",
78
+
"char.IsSymbol",
79
+
"char.IsUpper",
80
+
"char.IsWhiteSpace",
81
+
"char.ToLower",
82
+
"char.ToLowerInvariant",
83
+
"char.ToUpper",
84
+
"char.ToUpperInvariant",
85
+
"char.GetNumericValue",
86
+
"Console.Write",
87
+
"Console.WriteLine",
88
+
"Debug.WriteLine",
89
+
"Trace.WriteLine",
90
+
"string.Contains",
91
+
"string.EndsWith",
92
+
"string.StartsWith",
93
+
"string.Equals",
94
+
"string.IndexOf",
95
+
"string.LastIndexOf",
96
+
"string.Replace",
97
+
"string.Split",
98
+
"string.Trim",
99
+
"string.TrimStart",
100
+
"string.TrimEnd",
101
+
"string.Insert",
102
+
"string.Remove",
103
+
"string.Substring",
104
+
"string.IsNullOrEmpty",
105
+
"string.IsNullOrWhiteSpace",
106
+
"string.Join",
107
+
"string.Concat",
108
+
"string.Format",
109
+
"StringBuilder.Append",
110
+
"StringBuilder.AppendLine",
111
+
"StringBuilder.Insert",
112
+
"StringBuilder.Replace",
113
+
"StringBuilder.Remove",
114
+
"CharUnicodeInfo.GetUnicodeCategory",
115
+
"CharUnicodeInfo.GetDigitValue",
116
+
"CharUnicodeInfo.GetNumericValue",
117
+
"Math.Min",
118
+
"Math.Max",
119
+
"List.Add",
120
+
"Dictionary.Add",
121
+
"Enumerable.Where",
122
+
"Enumerable.Select",
123
+
"Enumerable.FirstOrDefault",
124
+
"Enumerable.First",
125
+
"Enumerable.Any",
126
+
"Enumerable.OrderBy",
127
+
"Enumerable.OrderByDescending",
128
+
"Enumerable.GroupBy",
129
+
"Enumerable.ToList",
130
+
"Enumerable.ToArray",
131
+
"Enumerable.Contains",
132
+
"Enumerable.ElementAt",
133
+
"Enumerable.ElementAtOrDefault",
134
+
"Enumerable.All",
135
+
"Enumerable.Count",
136
+
"Enumerable.Last",
137
+
"Enumerable.LastOrDefault"
138
+
139
+
### Configuration Methods
140
+
141
+
#### Option 1: Using .editorconfig File (Recommended)
142
+
143
+
1. Create or open an .editorconfig file in the root of your solution or project.
144
+
2. Add the following configuration entries:
94
145
95
146
```ini
96
147
# Named Arguments Analyzer Configuration
@@ -103,15 +154,18 @@ dotnet_diagnostic.PNA1000.UseDefaultExcludedMethods = true # or false
The most common and recommended approach is Option 1 with the .editorconfig file,
135
-
as it's the standard way to configure analyzer settings in modern .NET projects.
190
+
The most common and recommended approach is Option 1 with the .editorconfig file, as it's the standard way to configure analyzer settings in modern .NET projects.
191
+
192
+
## Contributing
193
+
194
+
Contributions are welcome! Please open issues or submit pull requests on GitHub.
0 commit comments