@@ -142,7 +142,7 @@ public void Initilaize(Dictionary<string, List<string>> result)
142
142
paths = result . ContainsKey ( "ValidDllPaths" ) ? result [ "ValidDllPaths" ] : result [ "ValidPaths" ] ;
143
143
foreach ( string path in paths )
144
144
{
145
- if ( String . Equals ( Path . GetExtension ( path ) , ".dll" , StringComparison . OrdinalIgnoreCase ) )
145
+ if ( Path . GetExtension ( path ) . ToLower ( CultureInfo . CurrentCulture ) == ".dll" )
146
146
{
147
147
catalog . Catalogs . Add ( new AssemblyCatalog ( path ) ) ;
148
148
}
@@ -241,8 +241,8 @@ public List<ExternalRule> GetExternalRule(string[] moduleNames)
241
241
242
242
FunctionInfo funcInfo = ( FunctionInfo ) psobject . ImmediateBaseObject ;
243
243
ParameterMetadata param = funcInfo . Parameters . Values
244
- . First < ParameterMetadata > ( item => item . Name . EndsWith ( "ast" , StringComparison . OrdinalIgnoreCase ) ||
245
- item . Name . EndsWith ( "token" , StringComparison . OrdinalIgnoreCase ) ) ;
244
+ . First < ParameterMetadata > ( item => item . Name . ToLower ( CultureInfo . CurrentCulture ) . EndsWith ( "ast" , StringComparison . CurrentCulture ) ||
245
+ item . Name . ToLower ( CultureInfo . CurrentCulture ) . EndsWith ( "token" , StringComparison . CurrentCulture ) ) ;
246
246
247
247
//Only add functions that are defined as rules.
248
248
if ( param != null )
@@ -251,7 +251,7 @@ public List<ExternalRule> GetExternalRule(string[] moduleNames)
251
251
string desc = posh . AddScript ( script ) . Invoke ( ) [ 0 ] . ImmediateBaseObject . ToString ( )
252
252
. Replace ( "\r \n " , " " ) . Trim ( ) ;
253
253
254
- rules . Add ( new ExternalRule ( funcInfo . Name , funcInfo . Name , desc , param . ParameterType . Name ,
254
+ rules . Add ( new ExternalRule ( funcInfo . Name , funcInfo . Name , desc , param . Name ,
255
255
funcInfo . ModuleName , funcInfo . Module . Path ) ) ;
256
256
}
257
257
}
@@ -337,7 +337,7 @@ public IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token, E
337
337
{
338
338
// Find all AstTypes that appeared in rule groups.
339
339
IEnumerable < Ast > childAsts = ast . FindAll ( new Func < Ast , bool > ( ( testAst ) =>
340
- Strings . Equals ( testAst . GetType ( ) . Name , astRuleGroup . Key ) ) , false ) ;
340
+ ( testAst . GetType ( ) . Name . ToLower ( CultureInfo . CurrentCulture ) == astRuleGroup . Key . ToLower ( CultureInfo . CurrentCulture ) ) ) , false ) ;
341
341
342
342
foreach ( Ast childAst in childAsts )
343
343
{
@@ -381,34 +381,30 @@ public IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token, E
381
381
string message = string . Empty ;
382
382
string ruleName = string . Empty ;
383
383
384
- //Make sure returned DiagnosticRecord is not null
385
- if ( psobject != null && psobject . ImmediateBaseObject != null )
384
+ // Because error stream is merged to output stream,
385
+ // we need to handle the error records.
386
+ if ( psobject . ImmediateBaseObject is ErrorRecord )
386
387
{
387
- // Because error stream is merged to output stream,
388
- // we need to handle the error records.
389
- if ( psobject . ImmediateBaseObject is ErrorRecord )
390
- {
391
- ErrorRecord record = ( ErrorRecord ) psobject . ImmediateBaseObject ;
392
- command . WriteError ( record ) ;
393
- continue ;
394
- }
395
-
396
- // DiagnosticRecord may not be correctly returned from external rule.
397
- try
398
- {
399
- Enum . TryParse < DiagnosticSeverity > ( psobject . Properties [ "Severity" ] . Value . ToString ( ) . ToUpper ( ) , out severity ) ;
400
- message = psobject . Properties [ "Message" ] . Value . ToString ( ) ;
401
- extent = ( IScriptExtent ) psobject . Properties [ "Extent" ] . Value ;
402
- ruleName = psobject . Properties [ "RuleName" ] . Value . ToString ( ) ;
403
- }
404
- catch ( Exception ex )
405
- {
406
- command . WriteError ( new ErrorRecord ( ex , ex . HResult . ToString ( "X" ) , ErrorCategory . NotSpecified , this ) ) ;
407
- continue ;
408
- }
409
-
410
- if ( ! string . IsNullOrEmpty ( message ) ) yield return new DiagnosticRecord ( message , extent , ruleName , severity , null ) ;
388
+ ErrorRecord record = ( ErrorRecord ) psobject . ImmediateBaseObject ;
389
+ command . WriteError ( record ) ;
390
+ continue ;
391
+ }
392
+
393
+ // DiagnosticRecord may not be correctly returned from external rule.
394
+ try
395
+ {
396
+ Enum . TryParse < DiagnosticSeverity > ( psobject . Properties [ "Severity" ] . Value . ToString ( ) . ToUpper ( ) , out severity ) ;
397
+ message = psobject . Properties [ "Message" ] . Value . ToString ( ) ;
398
+ extent = ( IScriptExtent ) psobject . Properties [ "Extent" ] . Value ;
399
+ ruleName = psobject . Properties [ "RuleName" ] . Value . ToString ( ) ;
400
+ }
401
+ catch ( Exception ex )
402
+ {
403
+ command . WriteError ( new ErrorRecord ( ex , ex . HResult . ToString ( "X" ) , ErrorCategory . NotSpecified , this ) ) ;
404
+ continue ;
411
405
}
406
+
407
+ if ( ! string . IsNullOrEmpty ( message ) ) yield return new DiagnosticRecord ( message , extent , ruleName , severity , null ) ;
412
408
}
413
409
}
414
410
@@ -457,11 +453,7 @@ public Dictionary<string, List<string>> CheckRuleExtension(string[] path, PSCmdl
457
453
// Adds original path, otherwise path.Except<string>(validModPaths) will fail.
458
454
// It's possible that user can provide something like this:
459
455
// "..\..\..\ScriptAnalyzer.UnitTest\modules\CommunityAnalyzerRules\CommunityAnalyzerRules.psd1"
460
- if ( moduleInfo . ExportedFunctions . Count > 0 )
461
- {
462
- validModPaths . Add ( childPath ) ;
463
- cmdlet . WriteVerbose ( string . Format ( CultureInfo . CurrentCulture , Strings . ImportCustomizedRuleSuccess , childPath ) ) ;
464
- }
456
+ if ( moduleInfo . ExportedFunctions . Count > 0 ) validModPaths . Add ( childPath ) ;
465
457
}
466
458
}
467
459
catch
@@ -486,7 +478,7 @@ public Dictionary<string, List<string>> CheckRuleExtension(string[] path, PSCmdl
486
478
487
479
cmdlet . WriteDebug ( string . Format ( CultureInfo . CurrentCulture , Strings . CheckAssemblyFile , resolvedPath ) ) ;
488
480
489
- if ( String . Equals ( Path . GetExtension ( resolvedPath ) , ".dll" , StringComparison . OrdinalIgnoreCase ) )
481
+ if ( Path . GetExtension ( resolvedPath ) . ToLower ( CultureInfo . CurrentCulture ) == ".dll" )
490
482
{
491
483
if ( ! File . Exists ( resolvedPath ) )
492
484
{
0 commit comments