Skip to content

Make SA1117 work with multiline arguments - #3115

Merged
sharwell merged 4 commits into
DotNetAnalyzers:masterfrom
pantosha:fix-3106
Sep 28, 2020
Merged

sharwell merged 4 commits into
DotNetAnalyzers:masterfrom
pantosha:fix-3106

Conversation

@pantosha

@pantosha pantosha commented Feb 8, 2020

Copy link
Copy Markdown
Contributor

Fix #3106

@pantosha
pantosha requested a review from sharwell February 8, 2020 11:13
@codecov

codecov Bot commented Feb 8, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #3115 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3115   +/-   ##
=======================================
  Coverage   97.13%   97.14%           
=======================================
  Files         841      841           
  Lines      104943   104903   -40     
  Branches     3416     3402   -14     
=======================================
- Hits       101934   101905   -29     
+ Misses       2095     2089    -6     
+ Partials      914      909    -5     

@Piedone

Piedone commented Aug 6, 2020

Copy link
Copy Markdown

@sharwell @vweijsters We at Lombiq would sponsor the review and integration of this fix if you're open to it.

@sharwell sharwell changed the title Make SA1117 work with multiline arguments (fix #3106) Make SA1117 work with multiline arguments Sep 26, 2020
@sharwell

Copy link
Copy Markdown
Member

@pantosha I am planning to experiment and see if I can clean up some of this slightly. Do you mind if I just update the pull request with the result by pushing extra commits to your branch?

@pantosha

Copy link
Copy Markdown
Contributor Author

@sharwell feel free to modify my PR.

@sharwell sharwell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already updated this from master branch to simplify some of the review, and am in the process of applying the changes noted in comments. I believe it will be ready for merge once I complete this step.

}

private static void Analyze(SyntaxNodeAnalysisContext context, SeparatedSyntaxList<ParameterSyntax> parameters)
private static void Analyze(SyntaxNodeAnalysisContext context, IReadOnlyList<SyntaxNode> arguments)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 This can be made generic to avoid boxing at the call sites.

Suggested change
private static void Analyze(SyntaxNodeAnalysisContext context, IReadOnlyList<SyntaxNode> arguments)
private static void Analyze<T>(SyntaxNodeAnalysisContext context, SeparatedSyntaxList<T> arguments)
where T : SyntaxNode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Fixed!

@pantosha This was a case where the original code was unnecessarily complex to apply a performance optimization. Your initial change was a dramatic improvement to readability, and together we also made it just as fast 👍

{
// arguments should be on same line
lineCondition = (param1Line, param2Line) => param1Line == param2Line;
lineCondition = (param1, param2) => param1.GetLine() == param2.GetEndLine();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This one I'm not so sure about. For now I'm going to relax the condition:

Suggested change
lineCondition = (param1, param2) => param1.GetLine() == param2.GetEndLine();
lineCondition = (param1, param2) => param1.GetLine() == param2.GetLine();

This change means we still fix #3106, but it doesn't address #3183 which is still in discussion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ This one is now changed back to only compare starting lines.

@sharwell

Copy link
Copy Markdown
Member

@pantosha no action is needed from you at this time; just giving you a heads-up regarding the changes being made

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.

SA1117 treats multi line arguments as only existing on single line.

3 participants