Skip to content

Add suggested corrections to allow violation fixes #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 29, 2016

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Apr 19, 2016

This change is Reviewable

Kapil Borle added 16 commits March 23, 2016 11:59
The class does not implement IScriptExtent interface anymore.
The purpose of CorrectionExtent is to emit violation extent
and the correction text but this behaviour is not consistent with
the IScriptExtent interface.
Moves the module manifest testing logic to a separate method in the Helper class. This will enable reuse of the functionality by other rules.
Suggest corrections to FunctionsToExport and AliasesToExport when their values are set to '*' or '$null', e.g., FunctionsToExport = '*'. This does not support wildcard in an array, eg @('Set-Foo', 'Get-*').
Sets the path of the test helper module correctly.
@raghushantha
Copy link
Member

README.md, line 197 [r1] (raw file):
Add documentation to about help topic


Comments from Reviewable

@raghushantha
Copy link
Member

Reviewed 23 of 23 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@raghushantha
Copy link
Member

@raghushantha
Copy link
Member

Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@raghushantha
Copy link
Member

:lgtm:


Comments from Reviewable

@kapilmb
Copy link
Author

kapilmb commented Apr 20, 2016

@raghushantha Thanks!

@lzybkr
Copy link

lzybkr commented Apr 20, 2016

Review status: all files reviewed at latest revision, 13 unresolved discussions, all commit checks successful.


Engine/Helper.cs, line 238 [r2] (raw file):
Should/can this be static?


Engine/Helper.cs, line 243 [r2] (raw file):
It might make sense for ScriptAnalyzer to provider a runspace pool to avoid creating too many runspaces - it does take ~50ms to create a default runspace, so that time can add up quickly depending on how many you create.


Engine/Helper.cs, line 244 [r2] (raw file):
This can never happen, it would throw an OutOfMemoryException instead.


Engine/Helper.cs, line 257 [r2] (raw file):
Terminating errors would turn into exceptions, you shouldn't ignore them.


Engine/Helper.cs, line 277 [r2] (raw file):
Should this be static?


Engine/Generic/DiagnosticRecord.cs, line 100 [r2] (raw file):
Collections are not recommended for public properties unless they are ReadOnly.


Rules/AvoidAlias.cs, line 79 [r2] (raw file):
It would be better to use cmdAst.CommandElements[0] to get the extent of the command name, it will correctly handle PowerShell escape sequences that IndexOf wouldn't. This relies on GetCommandName returning null if CommandElements[0] is not a string constant.


Rules/AvoidAlias.cs, line 81 [r2] (raw file):
Do you not localize strings in ScriptAnalyzer? "Replace..." is a localizable string.


Rules/AvoidUsingPlainTextForPassword.cs, line 76 [r2] (raw file):
Your correction here would remove attributes, e.g.

[string] [Parameter(ValueFromPipeline)] $Password
or
[Parameter(ValueFromPipeline)] $Password
or
[Parameter(ValueFromPipeline)] [string[]] $Password

It would also remove comments:

[string] <#whatever#> $Password

I think it's smart to use the parameter extent to show what gets "fixed", but more care is needed to replace only what you mean to.


Rules/MissingModuleManifestField.cs, line 47 [r2] (raw file):
IsMissingManifestMember instead of IsMissingMember?


Rules/MissingModuleManifestField.cs, line 51 [r2] (raw file):
Will you add a correction for the missing manifest member? That will be very helpful and ensure folks get it right.


Rules/UseToExportFieldsInManifest.cs, line 36 [r2] (raw file):
It's not (currently) important to specify VariablesToExport, so you could exclude this.


Rules/UseToExportFieldsInManifest.cs, line 100 [r2] (raw file):
You may want to wrap this and indent, for some modules this will look terrible (e.g. Azure exports 700+ commands).


Comments from Reviewable

@lzybkr
Copy link

lzybkr commented Apr 20, 2016

Review status: all files reviewed at latest revision, 14 unresolved discussions.


Tests/Rules/UseToExportFieldsInManifest.tests.ps1, line 89 [r2] (raw file):
You should some additional tests,:

  • where the entry was missing but stuff is exported
  • where the entry is present, uses a wildcard, and nothing is exported
  • where the entry is missing, nothing is exported, the suggestion should have an empty array like FunctionsToExport = @()

Comments from Reviewable

Kapil Borle added 5 commits April 22, 2016 21:41
This implementation correctly handles PowerShell escape sequences that IndexOf cannot.
Handles the following cases
* [string] [Parameter(ValueFromPipeline)] $Password
* [Parameter(ValueFromPipeline)] $Password
* [Parameter(ValueFromPipeline)] [string[]] $Password
* [string] <#whatever#> $Password
* Doesn't check for VariablesToExport
* Adds ability to wrap around correction string
Adds exception handling for a particular case in GetModuleManifest method
@kapilmb
Copy link
Author

kapilmb commented Apr 23, 2016

Review status: all files reviewed at latest revision, 14 unresolved discussions.


Engine/Helper.cs, line 238 [r2] (raw file):
Yes, this can be static in its current form. If we were to use runspace pool going forward that would change the implementation of this method. Will update its signature during that iteration.


Engine/Helper.cs, line 243 [r2] (raw file):
Will add it in a separate PR.


Rules/MissingModuleManifestField.cs, line 51 [r2] (raw file):
Yes, that is in the plan. Will send a separate PR for that.


Tests/Rules/UseToExportFieldsInManifest.tests.ps1, line 89 [r2] (raw file):
These features are not implemented in the rule itself as of now. The rule only checks for the presence of a wildcard character or $null. Will create a separate PR for this issue.


Comments from Reviewable

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.

4 participants