Skip to content

Add a language attribute code fix and MA0218/MA0219 for XML comments - #1320

Merged
meziantou merged 1 commit into
mainfrom
feature/ma0154-lang-attribute-fixer-1eb249
Aug 26, 2026
Merged

meziantou merged 1 commit into
mainfrom
feature/ma0154-lang-attribute-fixer-1eb249

Conversation

@meziantou

Copy link
Copy Markdown
Owner

What

Extends the MA0154 analyzer file with a second code fix and two new rules.

New code fix for MA0154UseLangwordInXmlCommentAddLanguageAttributeFixer

<c>void</c> could only be fixed by replacing the element with <see langword="void" />. The new fix adds an empty language attribute instead (<c language="">void</c>), which is the right answer when the content is not meant to be a C# keyword. It intentionally does not support fix all (GetFixAllProvider() => null), since the user has to fill in the value.

MA0218 — The language attribute is empty (info, enabled by default)

Reports a language/lang attribute on <c>/<code> that has no value (whitespace-only counts as empty). The diagnostic is on the attribute itself. This is the follow-up to the new code fix, which produces language="".

MA0219 — Set the language attribute in XML comment (hidden, enabled by default)

Reports a <c>/<code> element that has no language, lang, or langword attribute. Being hidden, it does not show up in the build, but the "Add language attribute" fix is offered in the IDE, and the severity can be raised via editorconfig.

Notes for the reviewer

  • MA0219 does not fire when MA0154 does. For a bare keyword such as <c>void</c>, MA0154 already suggests <see langword="void" />, so asking for a language attribute on the same span would be contradictory. The continue in the analyzer is what implements this.
  • Both attribute names are recognized. language is what the code fix writes and what the rule titles/docs use, but lang is still detected by MA0218/MA0219 so existing comments are handled.
  • The rule docs note that the language attribute is only a convention: it is not part of the XML documentation comments specification, and tools may ignore it.
  • Generated files (README.md, docs/README.md, the five packed .editorconfig) were refreshed with dotnet run --project src/DocumentationGenerator, which re-runs clean.

Validation

  • dotnet build on the solution: 0 warnings, 0 errors.
  • Full Meziantou.Analyzer.Test.roslyn5.9 suite: 3791/3791 passing.
  • UseLangwordInXmlCommentAnalyzerTests on roslyn5.9 and roslyn4.8: 26/26 each.

MA0154 could only be fixed by replacing the element with <see langword="..." />.
Add a second code fix that adds an empty language attribute instead, which is
the right fix when the content is not a C# keyword. It does not support fix all,
as the value has to be filled in by the user.

Add two rules to the same analyzer:

- MA0218 (info): the language (or lang) attribute is set but empty
- MA0219 (hidden): the <c>/<code> element has no language, lang, or langword
  attribute. It is not reported when MA0154 already suggests using langword.
@meziantou
meziantou merged commit 9fcbc8a into main Aug 26, 2026
12 checks passed
@meziantou
meziantou deleted the feature/ma0154-lang-attribute-fixer-1eb249 branch August 26, 2026 18:38
This was referenced Aug 26, 2026
This was referenced Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant