Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UseUsingScopeModifierInNewRunspaces rule (#1419)
* Add tests for AvoidUnInitializedVarsInNewRunspaces * Add strings for AvoidUnInitializedVarsInNewRunspaces * Add documentation * wrestling with Ast in C# - not working * Add sensible warning message * remove unnecessary boilerplate from test * clean up and finetune rule * Add RuleToTest parameter to Test-ScriptAnalyzer to aid with test driven rule development * increment rule count to fix test * add reference to rule documentation * exclude built-in variables * change using directive => scoope modifier * add tests for InlineScript, Invoke-Command and Start-(Thread)Job * add rule implementation for InlineScript, Invoke-Command and Start-(Thread)Job * Refactor and cleanup * small cleanup * explain all applicable situations in documentation * simplify code for adding sessions to dict * Revert "Add RuleToTest parameter to Test-ScriptAnalyzer to aid with test driven rule development" This reverts commit 99c2bea. Undo -RuleToTest param * Rename rule to UseUsingScopeModifierInNewRunspaces Because this has a posive ring to it and points the user to the solution * refactor grouping of script blocks by session name * Add suggested correction implementation * Add test for suggested corrections, fix typos * Refactor to AstVisitor/AstVisitor2 WIP TODO: finish refactor for `Invoke-Command -Session` logic * Update Rules/UseUsingScopeModifierInNewRunspaces.cs Co-Authored-By: Robert Holt <rjmholt@gmail.com> * Update Rules/UseUsingScopeModifierInNewRunspaces.cs Co-Authored-By: Robert Holt <rjmholt@gmail.com> * Process review comments - Always use braces with if statements - Use ast.VariablePath.UserPath instead of ast.Extent.Text - simplify return list of corrections - add TODO's fo invoke-command-session code - Add TODO for commandAst.GetCommandName() can be null - Invert if for readability * Add tests for command name and icm -session * Add icm -session logic to visitor and tidy up * fix build for windows powershell * Revert "fix build for windows powershell" This reverts commit 921c1d2. revert fix, because multiple unintended changes were pushed along with it. * Change private class to internal class for Windows PowerShell * Add logic to detect DSCScriptResource * Add tests for DSC Script resource * Enhance label test topic Co-Authored-By: Robert Holt <rjmholt@gmail.com> * repair test indentation and add newline at eof * Move testcases to BeforeAll blocks * Add documentation that DSC Script resource is supported * change string[] to IReadOnlyList<string> Co-Authored-By: Robert Holt <rjmholt@gmail.com> * extract scriptBlockPosition as a variable for readability Co-Authored-By: Robert Holt <rjmholt@gmail.com> * put arguments on their own line for readability * make visitor class a private, nested class in rule * change 'var' to type name for method calls * fix indentation for nested visitor class * Remove explicit 'ToList()' for performance Co-Authored-By: Robert Holt <rjmholt@gmail.com> * add check for strongly typed assignments * Add todo comments * refactor FindAll predicates to static methods to avoid closure allocation * Refactor GetSessionName for performance. * use full type for string expression variable Co-Authored-By: Robert Holt <rjmholt@gmail.com> * use full type name for foreach variable initialization Co-Authored-By: Robert Holt <rjmholt@gmail.com> * refactor diagnostic message out to local variable Co-Authored-By: Robert Holt <rjmholt@gmail.com> * WIP: apply review suggestions refactoring FindVarsInAssignmentAsts to return a dictionary in progress * apply review suggestions refactoredFindVarsInAssignmentAsts to return a dictionary * Fix CR/LF -> LF Co-authored-by: Jos Koelewijn <Jos.Koelewijn@ogd.nl> Co-authored-by: Robert Holt <rjmholt@gmail.com>
- Loading branch information