| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
|
hankyi95 please fill out the PR description template |
Sorry, something went wrong.
| <data name="AvoidMultipleTypesParameterName" xml:space="preserve"> | ||
| <value>AvoidMultipleTypesParameter</value> | ||
| </data> | ||
| </root> No newline at end of file |
There was a problem hiding this comment.
| </root> | |
| </root> | |
Sorry, something went wrong.
| # Double typing is not allowed even for switch and boolean, because: | ||
| # switch maps to System.Management.Automation.SwitchParameter | ||
| # boolean maps to System.Boolean | ||
| function F11 ([switch][boolean] $s1, [int] $p1){} No newline at end of file |
There was a problem hiding this comment.
| function F11 ([switch][boolean] $s1, [int] $p1){} | |
| function F11 ([switch][boolean] $s1, [int] $p1){} | |
Sorry, something went wrong.
| $noViolations.Count | Should -Be 0 | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
| } | |
| } | |
Sorry, something went wrong.
| @@ -0,0 +1,3 @@ | |||
| function F10 ([int] $s1, [int] $p1){} | |||
|
|
|||
| function F11 ([switch] $s1, [int] $p1){} No newline at end of file | |||
There was a problem hiding this comment.
| function F11 ([switch] $s1, [int] $p1){} | |
| function F11 ([switch] $s1, [int] $p1){} | |
Sorry, something went wrong.
| $violations = Invoke-ScriptAnalyzer $PSScriptRoot\AvoidMultipleTypesParameter.ps1 | Where-Object {$_.RuleName -eq $violationName} | ||
| $noViolations = Invoke-ScriptAnalyzer $PSScriptRoot\AvoidMultipleTypesParameterNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName} |
There was a problem hiding this comment.
Rather than using files and running the analyzer in BeforeAll, I would:
Sorry, something went wrong.
Co-authored-by: Robert Holt <rjmholt@gmail.com>
|
|
||
| ## How | ||
|
|
||
| Make each parameter has only 1 type spcifier. |
There was a problem hiding this comment.
| Make each parameter has only 1 type spcifier. | |
| Ensure each parameter has only 1 type specifier. |
Sorry, something went wrong.
|
|
||
| ## Description | ||
|
|
||
| Parameter should not have more than one type specifier. |
There was a problem hiding this comment.
| Parameter should not have more than one type specifier. | |
| Parameters should not have more than one type specifier. |
Sorry, something went wrong.
| /// </summary> | ||
| public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) | ||
| { | ||
| if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage); |
There was a problem hiding this comment.
| if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage); | |
| if (ast is null) | |
| { | |
| throw new ArgumentNullException(Strings.NullAstErrorMessage); | |
| } |
Sorry, something went wrong.
| yield return new DiagnosticRecord( | ||
| String.Format(CultureInfo.CurrentCulture, Strings.AvoidMultipleTypesParameterError, paramAst.Name), | ||
| paramAst.Name.Extent, GetName(), DiagnosticSeverity.Warning, fileName); |
There was a problem hiding this comment.
| yield return new DiagnosticRecord( | |
| String.Format(CultureInfo.CurrentCulture, Strings.AvoidMultipleTypesParameterError, paramAst.Name), | |
| paramAst.Name.Extent, GetName(), DiagnosticSeverity.Warning, fileName); | |
| yield return new DiagnosticRecord( | |
| String.Format(CultureInfo.CurrentCulture, Strings.AvoidMultipleTypesParameterError, paramAst.Name), | |
| paramAst.Name.Extent, | |
| GetName(), | |
| DiagnosticSeverity.Warning, | |
| fileName); |
Sorry, something went wrong.
| <value>When using an explicit process block, no preceding code is allowed, only begin, end and dynamicparams blocks.</value> | ||
| </data> | ||
| <data name="AvoidMultipleTypesParameterCommonName" xml:space="preserve"> | ||
| <value>Avoid Multiple Types Parameter</value> |
There was a problem hiding this comment.
| <value>Avoid Multiple Types Parameter</value> | |
| <value>Avoid multiple type specifiers on parameters.</value> |
Sorry, something went wrong.
| } | ||
| } | ||
|
|
||
| Describe 'AvoidMultipleTypesParameter' { |
There was a problem hiding this comment.
So I would rewrite your test structure like this:
We could also use a few more tests:
Sorry, something went wrong.
| $Param1, | ||
|
|
||
| [switch] | ||
| $Switch=$False |
There was a problem hiding this comment.
| $Switch=$False | |
| $Switch |
Sorry, something went wrong.
|
|
||
| ## Description | ||
|
|
||
| Parameter should not have more than one type specifier. |
There was a problem hiding this comment.
Can we also add a description why we do not want to have more than one type, i.e. what is the impact? \Just a runtime error or potentially also unpredictable or unintuitive behavior?
Sorry, something went wrong.
There was a problem hiding this comment.
Just a few comments but looks good from a high level, Rob already pointed out some low level code things to address, I'd be happy to merge after that
Sorry, something went wrong.
…ub.com/hankyi95/PSScriptAnalyzer into hankyi/feature/avoidmultipletypesparam
| /// </summary> | ||
| public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) | ||
| { | ||
| if (ast == null) |
There was a problem hiding this comment.
| if (ast == null) | |
| if (ast is null) |
Sorry, something went wrong.
| } | ||
|
|
||
| Describe 'AvoidMultipleTypesParameter' { | ||
| it 'Should find 3 violations for paramters have more than one type spceifiers' { |
There was a problem hiding this comment.
| it 'Should find 3 violations for paramters have more than one type spceifiers' { | |
| It 'Should find 3 violations for paramters have more than one type spceifiers' { |
Below as well
Sorry, something went wrong.
| $def = @' | ||
| function F1 ($s1, $p1){} | ||
| function F2 ([int] $s2, [int] $p2){} | ||
| function F3 ([int][switch] $s3, [int] $p3){} | ||
| function F4 ([int][ref] $s4, [int] $p4){} | ||
| function F5 ([int][switch][boolean] $s5, [int] $p5){} | ||
| '@ |
There was a problem hiding this comment.
This is the kind of thing that the -TestCases parameter on It is designed for.
Here's a simple example, and a more sophisticated example.
Each example should be its own test, but each test should assert (with Should):
Sorry, something went wrong.
There was a problem hiding this comment.
Just realised the rule name AvoidMultipleTypesParameter doesn't quite work.
My suggestion is AvoidMultipleTypeAttributes (means we could generalise the rule later), but doesn't have to be that. Some other possibilities:
Sorry, something went wrong.
| @@ -0,0 +1,50 @@ | |||
| # AvoidMultipleTypesParameter | |||
There was a problem hiding this comment.
| # AvoidMultipleTypesParameter | |
| # AvoidMultipleTypeAttributes |
Sorry, something went wrong.
| |[AvoidGlobalVars](./AvoidGlobalVars.md) | Warning | | | ||
| |[AvoidInvokingEmptyMembers](./AvoidInvokingEmptyMembers.md) | Warning | | | ||
| |[AvoidLongLines](./AvoidLongLines.md) | Warning | | | ||
| |[AvoidMultipleTypesParameter](./AvoidMultipleTypesParameter.md) | Warning | | |
There was a problem hiding this comment.
| |[AvoidMultipleTypesParameter](./AvoidMultipleTypesParameter.md) | Warning | | | |
| |[AvoidMultipleTypeAttributes](./AvoidMultipleTypesParameter.md) | Warning | | |
Sorry, something went wrong.
| #if !CORECLR | ||
| [Export(typeof(IScriptRule))] | ||
| #endif | ||
| public sealed class AvoidMultipleTypesParameter : IScriptRule |
There was a problem hiding this comment.
| public sealed class AvoidMultipleTypesParameter : IScriptRule | |
| public sealed class AvoidMultipleTypeAttributesRule: IScriptRule |
Sorry, something went wrong.
| <data name="InvalidSyntaxAroundProcessBlockError" xml:space="preserve"> | ||
| <value>When using an explicit process block, no preceding code is allowed, only begin, end and dynamicparams blocks.</value> | ||
| </data> | ||
| <data name="AvoidMultipleTypesParameterCommonName" xml:space="preserve"> |
There was a problem hiding this comment.
| <data name="AvoidMultipleTypesParameterCommonName" xml:space="preserve"> | |
| <data name="AvoidMultipleTypeAttributesCommonName" xml:space="preserve"> |
Sorry, something went wrong.
| <data name="AvoidMultipleTypesParameterCommonName" xml:space="preserve"> | ||
| <value>Avoid multiple type specifiers on parameters</value> | ||
| </data> | ||
| <data name="AvoidMultipleTypesParameterDescription" xml:space="preserve"> |
There was a problem hiding this comment.
| <data name="AvoidMultipleTypesParameterDescription" xml:space="preserve"> | |
| <data name="AvoidMultipleTypeAttributesDescription" xml:space="preserve"> |
Sorry, something went wrong.
| <data name="AvoidMultipleTypesParameterDescription" xml:space="preserve"> | ||
| <value>Prameter should not have more than one type specifier.</value> | ||
| </data> | ||
| <data name="AvoidMultipleTypesParameterError" xml:space="preserve"> |
There was a problem hiding this comment.
| <data name="AvoidMultipleTypesParameterError" xml:space="preserve"> | |
| <data name="AvoidMultipleTypeAttributesError" xml:space="preserve"> |
Sorry, something went wrong.
| <data name="AvoidMultipleTypesParameterError" xml:space="preserve"> | ||
| <value>Parameter '{0}' has more than one type specifier.</value> | ||
| </data> | ||
| <data name="AvoidMultipleTypesParameterName" xml:space="preserve"> |
There was a problem hiding this comment.
| <data name="AvoidMultipleTypesParameterName" xml:space="preserve"> | |
| <data name="AvoidMultipleTypeAttributesName" xml:space="preserve"> |
Sorry, something went wrong.
| <value>Parameter '{0}' has more than one type specifier.</value> | ||
| </data> | ||
| <data name="AvoidMultipleTypesParameterName" xml:space="preserve"> | ||
| <value>AvoidMultipleTypesParameter</value> |
There was a problem hiding this comment.
| <value>AvoidMultipleTypesParameter</value> | |
| <value>AvoidMultipleTypeAttributes</value> |
Sorry, something went wrong.
| # Licensed under the MIT License. | ||
|
|
||
| BeforeAll { | ||
| $ruleName = "PSAvoidMultipleTypesParameter" |
There was a problem hiding this comment.
| $ruleName = "PSAvoidMultipleTypesParameter" | |
| $ruleName = "PSAvoidMultipleTypeAttributes" |
Sorry, something went wrong.
…ub.com/hankyi95/PSScriptAnalyzer into hankyi/feature/avoidmultipletypesparam
| Back | FazBrowse Home | New Git URL |
PR Summary
PR Checklist