@@ -72,70 +72,68 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
7272 return null ;
7373 }
7474
75- else
76- {
77- var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
78- string versionTest = string . Join ( "" , PowerShellVersion ) ;
7975
80- if ( string . IsNullOrEmpty ( versionTest ) )
76+ var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
77+ string versionTest = string . Join ( "" , PowerShellVersion ) ;
78+
79+ if ( string . IsNullOrEmpty ( versionTest ) )
80+ {
81+ // PowerShellVersion is not already set to one of the acceptable defaults
82+ // Try launching `pwsh -v` to see if PowerShell 6+ is installed, and use those cmdlets
83+ // as a default. If 6+ is not installed this will throw an error, which when caught will
84+ // allow us to use the PowerShell 5 cmdlets as a default.
85+ var testProcess = new Process ( ) ;
86+ testProcess . StartInfo . FileName = "pwsh" ;
87+ testProcess . StartInfo . Arguments = "-v" ;
88+ testProcess . StartInfo . CreateNoWindow = true ;
89+ testProcess . StartInfo . UseShellExecute = false ;
90+
91+ try
8192 {
82- // PowerShellVersion is not already set to one of the acceptable defaults
83- // Try launching `pwsh -v` to see if PowerShell 6+ is installed, and use those cmdlets
84- // as a default. If 6+ is not installed this will throw an error, which when caught will
85- // allow us to use the PowerShell 5 cmdlets as a default.
86- var testProcess = new Process ( ) ;
87- testProcess . StartInfo . FileName = "pwsh" ;
88- testProcess . StartInfo . Arguments = "-v" ;
89- testProcess . StartInfo . CreateNoWindow = true ;
90- testProcess . StartInfo . UseShellExecute = false ;
91-
92- try
93- {
94- testProcess . Start ( ) ;
95- PowerShellVersion = new [ ] { "core-6.1.0-windows" } ;
96- }
97- catch
98- {
99- PowerShellVersion = new [ ] { "desktop-5.1.14393.206-windows" } ;
100- }
101- finally
102- {
103- testProcess . Dispose ( ) ;
104- }
93+ testProcess . Start ( ) ;
94+ PowerShellVersion = new [ ] { "core-6.1.0-windows" } ;
10595 }
106-
107- var psVerList = PowerShellVersion ;
108- string settingsPath = Settings . GetShippedSettingsDirectory ( ) ;
109-
110- foreach ( string reference in psVerList )
96+ catch
11197 {
112- if ( settingsPath == null || ! ContainsReferenceFile ( settingsPath , reference ) )
113- {
114- throw new ArgumentException ( nameof ( PowerShellVersion ) ) ;
115- }
98+ PowerShellVersion = new [ ] { "desktop-5.1.14393.206-windows" } ;
11699 }
100+ finally
101+ {
102+ testProcess . Dispose ( ) ;
103+ }
104+ }
117105
118- ProcessDirectory ( settingsPath , psVerList ) ;
106+ var psVerList = PowerShellVersion ;
107+ string settingsPath = Settings . GetShippedSettingsDirectory ( ) ;
119108
120- if ( _cmdletMap . Keys . Count != psVerList . Count ( ) )
109+ foreach ( string reference in psVerList )
110+ {
111+ if ( settingsPath == null || ! ContainsReferenceFile ( settingsPath , reference ) )
121112 {
122113 throw new ArgumentException ( nameof ( PowerShellVersion ) ) ;
123114 }
115+ }
116+
117+ ProcessDirectory ( settingsPath , psVerList ) ;
124118
125- foreach ( FunctionDefinitionAst functionDef in functionDefinitions )
119+ if ( _cmdletMap . Keys . Count != psVerList . Count ( ) )
120+ {
121+ throw new ArgumentException ( nameof ( PowerShellVersion ) ) ;
122+ }
123+
124+ foreach ( FunctionDefinitionAst functionDef in functionDefinitions )
125+ {
126+ string functionName = functionDef . Name ;
127+ foreach ( KeyValuePair < string , HashSet < string > > cmdletSet in _cmdletMap )
126128 {
127- string functionName = functionDef . Name ;
128- foreach ( KeyValuePair < string , HashSet < string > > cmdletSet in _cmdletMap )
129+ if ( cmdletSet . Value . Contains ( functionName ) )
129130 {
130- if ( cmdletSet . Value . Contains ( functionName ) )
131- {
132- diagnosticRecords . Add ( CreateDiagnosticRecord ( functionName , cmdletSet . Key , functionDef . Extent ) ) ;
133- }
131+ diagnosticRecords . Add ( CreateDiagnosticRecord ( functionName , cmdletSet . Key , functionDef . Extent ) ) ;
134132 }
135133 }
136-
137- return diagnosticRecords ;
138134 }
135+
136+ return diagnosticRecords ;
139137 }
140138
141139
0 commit comments