Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Multiple improvements by CodeRush Static Analysis#5132

Merged
TravisEz13 merged 2 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
Himura2la:masterCopy head branch name to clipboard
Nov 10, 2017
Merged

Multiple improvements by CodeRush Static Analysis#5132
TravisEz13 merged 2 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
Himura2la:masterCopy head branch name to clipboard

Conversation

@Himura2la

@Himura2la Himura2la commented Oct 16, 2017

Copy link
Copy Markdown
Contributor

Hi guys!
I have checked the PowerShell solution with the CodeRush Static Analyzer and fixed several code issues. Here's the summary:

I hope this will help, here's the full report: CodeIssuesReport.txt. Thanks for being open source!

@msftclas

msftclas commented Oct 16, 2017

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@PaulHigin PaulHigin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for finding and fixing these!

else
{
//if inside the current buffer, we still cannot read the events, as the handles.
//if inside the current buffer (_currentIndex + offset >= 0), we still cannot read the events, as the handles.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment still doesn't make sense to me. Maybe just remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, removing the whole comment

}
i += 1;
}
for (; i < _singleton._buffer.Length && !InWord(i, wordDelimiters); i++) ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel this is easier to read (with the additional parentheses):
for (; (i < _singleton._buffer.Length) && !InWord(I, wordDelimiters); I++);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Submit a PR to https://github.com/lzybkr/PSReadLine for any changes in the PSReadLine directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And I'll likely reject the change - In general I'm not a fan of empty loop bodies.

@Himura2la Himura2la Oct 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I reverted the file, this change is a anyway just a preference. Maybe I'll try to push it to the correct repository, thanks for the link.

// Since drive1 is null it is less than drive2 which is not null
return false;
}
// Since both drives are null, they are equal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't look right. I believe it should be.
return (drive2Object != null);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks, I didn't notice that the refactoring can go even further

{
throw PSTraceSource.NewArgumentException("name");
}
// FIXME: Other checks?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this comment and verify that helpfile, description, psSnapIn parameters can be null.

@Himura2la Himura2la Oct 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I think I didn't catch whether I should ensure the helpfile, description and psSnapIn are not null or just remove the 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.

@Himura2la Can you either remove this comment or file an issue and update the comment to reference the issue?

// writing the cache out in a timely matter isn't too important
// now anyway.
await Task.Delay(10000);
await Task.Delay(10000).ConfigureAwait(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is not clear to me that this is needed. Isn't the Task always configured as "false" be default?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems right though, so I think it's good to keep it.

@Himura2la Himura2la Oct 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@PaulHigin As far as I know, the default option is 'true'. And that's the reason for adding an explicit ConfigureAwait() everywhere.

Diagnostics.Assert(error != 0 || signature != null, "GetSignatureFromWintrustData: general crypto failure");

if ((signature == null) && (error != 0))
if (signature == null && error != 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel the code is more readable with parentheses back in. I am not sure what our coding guidelines say.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this area, coding guidelines say - be consistent, but we also ask for no formatting changes mixed with other changes.


In reply to: 144931951 [](ancestors = 144931951)

@Himura2la Himura2la Oct 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I reverted this.
Sorry, I should have kept myself from removing parentheses everywhere. I think I write too much Python

{
Dbg.Assert((inputRecords[0].KeyEvent.KeyDown && inputRecords[0].KeyEvent.RepeatCount != 0) ||
!inputRecords[0].KeyEvent.KeyDown,
Dbg.Assert(inputRecords[0].KeyEvent.RepeatCount != 0 || !inputRecords[0].KeyEvent.KeyDown,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes the order of evaluation - probably safe here, but before, RepeatCount would not be evaluated if KeyDown was false.

@Himura2la Himura2la Oct 17, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I swapped them, thanks for noticing. Although it seems really safe assuming there's even no null-checks

{
Dbg.Assert((inputRecords[i].KeyEvent.KeyDown && inputRecords[i].KeyEvent.RepeatCount != 0) ||
!inputRecords[i].KeyEvent.KeyDown,
Dbg.Assert(inputRecords[i].KeyEvent.RepeatCount != 0 || !inputRecords[i].KeyEvent.KeyDown,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes the order of evaluation - probably safe here, but before, RepeatCount would not be evaluated if KeyDown was false.

}
//if (!(resUri.ToLowerInvariant().Contains(URI_IPMI) || resUri.ToLowerInvariant().Contains(URI_WMI)))
// tmpNs += ".xsd";
//This was reported by Intel as an interop issue. So now we are not appending a .xsd in the end.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment can probably be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I also inlined the tmpNs variable. I hope it's OK

RemotePipeline currentPipeline = (RemotePipeline)((RemoteRunspace)_runspace).GetCurrentlyRunningPipeline();
if (currentPipeline == null ||
currentPipeline != null && !ReferenceEquals(currentPipeline, this))
if (currentPipeline == null || !ReferenceEquals(currentPipeline, this))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think currentPipeline == null is redundant with ReferenceEquals here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems like.

@TravisEz13

Copy link
Copy Markdown
Member

@Himura2la What is your status on signing the CLA?

@Himura2la

Copy link
Copy Markdown
Contributor Author

I'm done with the changes and CLA. The only thing left is extra checks here

@TravisEz13

Copy link
Copy Markdown
Member

@PaulHigin Just a reminder to update your review.

Restarted macOS due to random brew download failure.

@PaulHigin PaulHigin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

{
throw PSTraceSource.NewArgumentException("name");
}
// FIXME: Other checks?

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.

@Himura2la Can you either remove this comment or file an issue and update the comment to reference the issue?

@TravisEz13

Copy link
Copy Markdown
Member

I'm following up on one issue. Hopefully there will be no more delays once I have the answer.

@Himura2la

Himura2la commented Oct 18, 2017

Copy link
Copy Markdown
Contributor Author

@TravisEz13, I've removed the comment in my second commit

@TravisEz13

Copy link
Copy Markdown
Member

@Himura2la Yeah, that is not the issue.

@iSazonov

iSazonov commented Nov 8, 2017

Copy link
Copy Markdown
Collaborator

Is the PR ready to merge?

@Himura2la

Copy link
Copy Markdown
Contributor Author

I wonder

@SteveL-MSFT

Copy link
Copy Markdown
Member

@TravisEz13 is this ready to merge?

@TravisEz13 TravisEz13 merged commit 6530b77 into PowerShell:master Nov 10, 2017
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.

7 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.