@@ -72,70 +72,68 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
72
72
return null ;
73
73
}
74
74
75
- else
76
- {
77
- var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
78
- string versionTest = string . Join ( "" , PowerShellVersion ) ;
79
75
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
81
92
{
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" } ;
105
95
}
106
-
107
- var psVerList = PowerShellVersion ;
108
- string settingsPath = Settings . GetShippedSettingsDirectory ( ) ;
109
-
110
- foreach ( string reference in psVerList )
96
+ catch
111
97
{
112
- if ( settingsPath == null || ! ContainsReferenceFile ( settingsPath , reference ) )
113
- {
114
- throw new ArgumentException ( nameof ( PowerShellVersion ) ) ;
115
- }
98
+ PowerShellVersion = new [ ] { "desktop-5.1.14393.206-windows" } ;
116
99
}
100
+ finally
101
+ {
102
+ testProcess . Dispose ( ) ;
103
+ }
104
+ }
117
105
118
- ProcessDirectory ( settingsPath , psVerList ) ;
106
+ var psVerList = PowerShellVersion ;
107
+ string settingsPath = Settings . GetShippedSettingsDirectory ( ) ;
119
108
120
- if ( _cmdletMap . Keys . Count != psVerList . Count ( ) )
109
+ foreach ( string reference in psVerList )
110
+ {
111
+ if ( settingsPath == null || ! ContainsReferenceFile ( settingsPath , reference ) )
121
112
{
122
113
throw new ArgumentException ( nameof ( PowerShellVersion ) ) ;
123
114
}
115
+ }
116
+
117
+ ProcessDirectory ( settingsPath , psVerList ) ;
124
118
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 )
126
128
{
127
- string functionName = functionDef . Name ;
128
- foreach ( KeyValuePair < string , HashSet < string > > cmdletSet in _cmdletMap )
129
+ if ( cmdletSet . Value . Contains ( functionName ) )
129
130
{
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 ) ) ;
134
132
}
135
133
}
136
-
137
- return diagnosticRecords ;
138
134
}
135
+
136
+ return diagnosticRecords ;
139
137
}
140
138
141
139
0 commit comments