roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

Fix analyzer RCS1208

Open josefpihrt opened this issue 1 year ago • 4 comments

fixes #1454

josefpihrt avatar May 08 '24 18:05 josefpihrt

Would this fix this issue?

public void Setup(MarkdownPipelineBuilder pipeline)
{
	if (pipeline.BlockParsers.Find<HeadingBlockParser>() is HeadingBlockParser headingBlockParser)
	{
		// Install a hook on the HeadingBlockParser when a HeadingBlock is actually processed
		headingBlockParser.Closed -= HeadingBlockParser_Closed;
		headingBlockParser.Closed += HeadingBlockParser_Closed;
	}
	if (pipeline.BlockParsers.FindExact<ParagraphBlockParser>() is ParagraphBlockParser paragraphBlockParser) // Reduce 'if' nesting RCS1208
	{
		// Install a hook on the ParagraphBlockParser when a HeadingBlock is actually processed as a Setex heading
		paragraphBlockParser.Closed -= HeadingBlockParser_Closed;
		paragraphBlockParser.Closed += HeadingBlockParser_Closed;
	}
}

BenjaminBrienen avatar May 01 '25 14:05 BenjaminBrienen

I'm not sure that I'm following you.

josefpihrt avatar May 01 '25 14:05 josefpihrt

It suggests to invert that second if-block even though it wouldn't improve readability. This PR seems to add the concept of a "last if-block" and allows them.

BenjaminBrienen avatar May 01 '25 15:05 BenjaminBrienen

Tbh, I was working on this fix couple of months ago and the only thing I recall is that fix is almost impossible so I gave up 🙂

josefpihrt avatar May 01 '25 15:05 josefpihrt