MA0003: don't require naming extension receivers and self-named arguments - #1361
Merged
meziantou merged 1 commit intoAug 29, 2026
Merged
Conversation
…ents Two cases where MA0003 asked for a named argument that could not be written, or that would not have improved readability: - `[RequireNamedArgument]` on the receiver of an extension method (the `this` parameter) was reported when the method was called using the static syntax (`Ext.Foo(value)`), while the instance syntax (`value.Foo()`) has no argument to name at all. The attribute is now ignored on that parameter. The check covers C# 14 `extension(...)` blocks, as their synthesized static method also exposes the receiver as an extension method parameter at ordinal 0. - An argument that is a local, a parameter, a property, or a field already carrying the name of the parameter is no longer reported, as naming it would only repeat the name. The comparison ignores the case, and removes the `_` and `s_` prefixes for fields. The raw name is compared first, so a field `_value` still matches a parameter named `_value`. The new `MA0003.ignore_arguments_matching_parameter_name` option (default `true`) disables the behavior. Also fold the two `GetOperation` calls made for every argument into one.
meziantou
deleted the
feature/requirenamedargument-extension-methods-44bcf1
branch
August 29, 2026 22:17
This was referenced Aug 29, 2026
IhateTrains
pushed a commit
to ParadoxGameConverters/ImperatorToCK3
that referenced
this pull request
Aug 30, 2026
Updated [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 3.0.190 to 3.0.194. <details> <summary>Release notes</summary> _Sourced from [Meziantou.Analyzer's releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._ ## 3.0.194 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.194> ## What's Changed * chore(deps): update dependency meziantou.framework.roslyn to 1.0.6 by @renovate[bot] in meziantou/Meziantou.Analyzer#1362 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.193...3.0.194 ## 3.0.193 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.193> ## What's Changed * MA0003: don't require naming extension receivers and self-named arguments by @meziantou in meziantou/Meziantou.Analyzer#1361 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.192...3.0.193 ## 3.0.192 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.192> ## What's Changed * chore(deps): update dependency meziantou.framework.roslyn to 1.0.5 by @renovate[bot] in meziantou/Meziantou.Analyzer#1360 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.191...3.0.192 ## 3.0.191 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.191> ## What's Changed * Give Meziantou.Framework.Roslyn its own auto-merged Renovate group by @meziantou in meziantou/Meziantou.Analyzer#1358 * chore(deps): update dependency meziantou.framework.roslyn to 1.0.4 by @renovate[bot] in meziantou/Meziantou.Analyzer#1359 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.190...3.0.191 Commits viewable in [compare view](meziantou/Meziantou.Analyzer@3.0.190...3.0.194). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Aug 30, 2026
Open
Closed
This was referenced Sep 14, 2026
Open
Open
Open
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.258
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#573
Open
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.258
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#556
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two cases where MA0003 asked for a named argument that could not be written, or that would not have improved readability.
[RequireNamedArgument]on an extension-method receiverThe attribute is now ignored on the
thisparameter of an extension method.Before this change the behavior depended on the call syntax:
value.Foo()has no argument to name at all, so nothing was reported, whileExt.Foo(value)mapped the argument to thethisparameter and reported a diagnostic. Naming the receiver is never the readability win the attribute is meant to ask for, so the parameter is now skipped in both forms.The check also covers C# 14
extension(...)blocks: their synthesized static method exposes the receiver as an extension-method parameter at ordinal 0, and the attribute written on theextension(...)clause does flow to it — I verified both with a Roslyn probe, and the corresponding tests fail when the guard is removed.Arguments already carrying the name of the parameter
Foo(sample)for a parameter namedsampleis no longer reported — naming it would only repeat the name:Details:
_ands_prefixes are removed before comparing, soFoo(_sample)andFoo(s_sample)also match a parameter namedsample._sampleis still reported, since the prefix is not a convention for locals and silencing it would hide real cases._samplestill matches a parameter actually named_sample.MA0003.ignore_arguments_matching_parameter_nameoption (defaulttrue) turns the behavior off.In practice this only affects the
[RequireNamedArgument]path: the general MA0003 rule reports literals, which have no name. The check is placed on the shared path anyway so it applies to the rule as a whole.Notes for the reviewer
Ext.Foo(null)still reports as before. Only the attribute path changed, matching what was asked for.GetOperationcalls previously made for every argument were folded into one.src/Meziantou.Analyzer.Annotationschanged, so no package version bump; the attribute's new behavior is documented on the MA0003 page the annotations README already links to.Testing
NamedParameterAnalyzerTests(theextension(...)block one guarded by#if CSHARP14_OR_GREATER), passing on all five Roslyn versions.dotnet run --project src/DocumentationGeneratorrun until it reported no further changes.