KirillOsenkov / XmlParser

A Roslyn-inspired full-fidelity XML parser with no dependencies and a simple Visual Studio XML language service
Apache License 2.0
328 stars 49 forks source link

Introduce analyzers for modification API same as Roslyn RS1014 #58

Open FrediKats opened 10 months ago

FrediKats commented 10 months ago

Roslyn have analyzers for usage of tree modification api: https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md?plain=1#L18

Today I spend some time for searching bug in this code:

public void MyMethod(...)
{
  XmlDocumentSyntax document = ...;
  document.ReplaceNode(...);
  return document;
}

Same code in Roslyn return diagnostic:

Warning RS1014  'ClassDeclarationSyntax' is immutable and 'AddBaseListTypes' will not have any effect on it. Consider using the return value from 'AddBaseListTypes'.

Many objects exposed by Roslyn are immutable. The return value from a method invocation on these objects should not be ignored.