@@ -121,12 +121,13 @@ export abstract class NagPack implements IAspect {
121
121
const ruleId = `${ this . packName } -${ ruleSuffix } ` ;
122
122
try {
123
123
const ruleCompliance = params . rule ( params . node ) ;
124
- if (
125
- this . reports === true &&
126
- ruleCompliance === NagRuleCompliance . COMPLIANT
127
- ) {
128
- this . writeToStackComplianceReport ( params , ruleId , ruleCompliance ) ;
129
- } else if ( this . isNonCompliant ( ruleCompliance ) ) {
124
+ if ( this . reports === true ) {
125
+ this . initializeStackReport ( params ) ;
126
+ if ( ruleCompliance === NagRuleCompliance . COMPLIANT ) {
127
+ this . writeToStackComplianceReport ( params , ruleId , ruleCompliance ) ;
128
+ }
129
+ }
130
+ if ( this . isNonCompliant ( ruleCompliance ) ) {
130
131
const findings = this . asFindings ( ruleCompliance ) ;
131
132
for ( const findingId of findings ) {
132
133
const suppressionReason = this . ignoreRule (
@@ -243,7 +244,7 @@ export abstract class NagPack implements IAspect {
243
244
}
244
245
245
246
/**
246
- * Write a line to the rule packs compliance report for the resource's Stack
247
+ * Write a line to the rule pack's compliance report for the resource's Stack
247
248
* @param params The @IApplyRule interface with rule details.
248
249
* @param ruleId The id of the rule.
249
250
* @param compliance The compliance status of the rule.
@@ -264,20 +265,33 @@ export abstract class NagPack implements IAspect {
264
265
compliance ,
265
266
explanation
266
267
) ;
267
- let outDir = App . of ( params . node ) ?. outdir ;
268
+ const outDir = App . of ( params . node ) ?. outdir ;
268
269
const stackName = params . node . stack . nested
269
270
? Names . uniqueId ( params . node . stack )
270
271
: params . node . stack . stackName ;
271
272
const fileName = `${ this . packName } -${ stackName } -NagReport.csv` ;
272
273
const filePath = join ( outDir ? outDir : '' , fileName ) ;
274
+ appendFileSync ( filePath , line ) ;
275
+ }
276
+
277
+ /**
278
+ * Initialize the report for the rule pack's compliance report for the resource's Stack if it doesn't exist
279
+ * @param params
280
+ */
281
+ protected initializeStackReport ( params : IApplyRule ) : void {
282
+ const stackName = params . node . stack . nested
283
+ ? Names . uniqueId ( params . node . stack )
284
+ : params . node . stack . stackName ;
285
+ const fileName = `${ this . packName } -${ stackName } -NagReport.csv` ;
273
286
if ( ! this . reportStacks . includes ( fileName ) ) {
287
+ const outDir = App . of ( params . node ) ?. outdir ;
288
+ const filePath = join ( outDir ? outDir : '' , fileName ) ;
274
289
this . reportStacks . push ( fileName ) ;
275
290
writeFileSync (
276
291
filePath ,
277
292
'Rule ID,Resource ID,Compliance,Exception Reason,Rule Level,Rule Info\n'
278
293
) ;
279
294
}
280
- appendFileSync ( filePath , line ) ;
281
295
}
282
296
283
297
/**
0 commit comments