@@ -502,68 +502,48 @@ private void AnalyzeFile(string filePath)
502
502
}
503
503
504
504
// Check if the supplied artifact is indeed part of the DSC resource
505
- // Step 1: Check if the artifact is under the "DSCResources" folder
506
- DirectoryInfo dscResourceParent = Directory . GetParent ( filePath ) ;
507
- if ( null != dscResourceParent )
505
+ if ( Helper . Instance . IsDscResourceModule ( filePath ) )
508
506
{
509
- DirectoryInfo dscResourcesFolder = Directory . GetParent ( dscResourceParent . ToString ( ) ) ;
510
- if ( null != dscResourcesFolder )
511
- {
512
- if ( String . Equals ( dscResourcesFolder . Name , "dscresources" , StringComparison . OrdinalIgnoreCase ) )
507
+ // Run all DSC Rules
508
+ foreach ( IDSCResourceRule dscResourceRule in ScriptAnalyzer . Instance . DSCResourceRules )
509
+ {
510
+ bool includeRegexMatch = false ;
511
+ bool excludeRegexMatch = false ;
512
+ foreach ( Regex include in includeRegexList )
513
+ {
514
+ if ( include . IsMatch ( dscResourceRule . GetName ( ) ) )
515
+ {
516
+ includeRegexMatch = true ;
517
+ break ;
518
+ }
519
+ }
520
+ foreach ( Regex exclude in excludeRegexList )
521
+ {
522
+ if ( exclude . IsMatch ( dscResourceRule . GetName ( ) ) )
523
+ {
524
+ excludeRegexMatch = true ;
525
+ }
526
+ }
527
+ if ( ( includeRule == null || includeRegexMatch ) && ( excludeRule == null || ! excludeRegexMatch ) )
513
528
{
514
- // Step 2: Ensure there is a Schema.mof in the same folder as the artifact
515
- string schemaMofParentFolder = Directory . GetParent ( filePath ) . ToString ( ) ;
516
- string [ ] schemaMofFile = Directory . GetFiles ( schemaMofParentFolder , "*.schema.mof" ) ;
529
+ WriteVerbose ( string . Format ( CultureInfo . CurrentCulture , Strings . VerboseRunningMessage , dscResourceRule . GetName ( ) ) ) ;
517
530
518
- // Ensure Schema file exists and is the only one in the DSCResource folder
519
- if ( schemaMofFile != null && schemaMofFile . Count ( ) == 1 )
531
+ // Ensure that any unhandled errors from Rules are converted to non-terminating errors
532
+ // We want the Engine to continue functioning even if one or more Rules throws an exception
533
+ try
520
534
{
521
- // Run DSC Rules only on module that matches the schema.mof file name without extension
522
- if ( schemaMofFile [ 0 ] . Replace ( "schema.mof" , "psm1" ) == filePath )
523
- {
524
- // Run all DSC Rules
525
- foreach ( IDSCResourceRule dscResourceRule in ScriptAnalyzer . Instance . DSCResourceRules )
526
- {
527
- bool includeRegexMatch = false ;
528
- bool excludeRegexMatch = false ;
529
- foreach ( Regex include in includeRegexList )
530
- {
531
- if ( include . IsMatch ( dscResourceRule . GetName ( ) ) )
532
- {
533
- includeRegexMatch = true ;
534
- break ;
535
- }
536
- }
537
- foreach ( Regex exclude in excludeRegexList )
538
- {
539
- if ( exclude . IsMatch ( dscResourceRule . GetName ( ) ) )
540
- {
541
- excludeRegexMatch = true ;
542
- }
543
- }
544
- if ( ( includeRule == null || includeRegexMatch ) && ( excludeRule == null || ! excludeRegexMatch ) )
545
- {
546
- WriteVerbose ( string . Format ( CultureInfo . CurrentCulture , Strings . VerboseRunningMessage , dscResourceRule . GetName ( ) ) ) ;
547
-
548
- // Ensure that any unhandled errors from Rules are converted to non-terminating errors
549
- // We want the Engine to continue functioning even if one or more Rules throws an exception
550
- try
551
- {
552
- var records = Helper . Instance . SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , dscResourceRule . AnalyzeDSCResource ( ast , filePath ) . ToList ( ) ) ;
553
- diagnostics . AddRange ( records . Item2 ) ;
554
- suppressed . AddRange ( records . Item1 ) ;
555
- }
556
- catch ( Exception dscResourceRuleException )
557
- {
558
- WriteError ( new ErrorRecord ( dscResourceRuleException , Strings . RuleErrorMessage , ErrorCategory . InvalidOperation , filePath ) ) ;
559
- }
560
- }
561
- }
562
- }
535
+ var records = Helper . Instance . SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , dscResourceRule . AnalyzeDSCResource ( ast , filePath ) . ToList ( ) ) ;
536
+ diagnostics . AddRange ( records . Item2 ) ;
537
+ suppressed . AddRange ( records . Item1 ) ;
538
+ }
539
+ catch ( Exception dscResourceRuleException )
540
+ {
541
+ WriteError ( new ErrorRecord ( dscResourceRuleException , Strings . RuleErrorMessage , ErrorCategory . InvalidOperation , filePath ) ) ;
563
542
}
564
543
}
565
544
}
566
- }
545
+
546
+ }
567
547
}
568
548
#endregion
569
549
0 commit comments