From d6424cb9505759e50b8fdd4e12b3c5aa03a88416 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Thu, 20 Jun 2024 22:29:22 +0100 Subject: [PATCH] feat(aa): ensure comments are neither merged nor sorted. --- pkg/aa/preamble.go | 2 +- pkg/aa/rules.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/aa/preamble.go b/pkg/aa/preamble.go index 37d30a61..d9e8b1f2 100644 --- a/pkg/aa/preamble.go +++ b/pkg/aa/preamble.go @@ -34,7 +34,7 @@ func (r *Comment) Validate() error { } func (r *Comment) Compare(other Rule) int { - return 0 + return 0 // Comments are always equal to each other as they are not compared } func (r *Comment) String() string { diff --git a/pkg/aa/rules.go b/pkg/aa/rules.go index 409b4861..675a8a73 100644 --- a/pkg/aa/rules.go +++ b/pkg/aa/rules.go @@ -157,20 +157,19 @@ func (r Rules) Merge() Rules { continue } kindOfI := r[i].Kind() - kindOfJ := r[j].Kind() - if kindOfI != kindOfJ { + if kindOfI != r[j].Kind() { continue } - // If rules are identical, merge them - if r[i].Compare(r[j]) == 0 { + // If rules are identical, merge them. Ignore comments + if kindOfI != COMMENT && r[i].Compare(r[j]) == 0 { r = r.Delete(j) j-- continue } // File rule - if kindOfI == FILE && kindOfJ == FILE { + if kindOfI == FILE { // Merge access fileI := r[i].(*File) fileJ := r[j].(*File)