Skip to content

Update#19

Merged
jbsmith7741 merged 2 commits intomainfrom
update
Jan 23, 2026
Merged

Update#19
jbsmith7741 merged 2 commits intomainfrom
update

Conversation

@jbsmith7741
Copy link
Member

@jbsmith7741 jbsmith7741 commented Jan 23, 2026

PR Type

Enhancement, Documentation


Description

  • Add new IgnoreFieldsOf function for embedded struct field comparison

  • Expand CI/CD testing to Go 1.20-1.24 and update GitHub Actions versions

  • Create comprehensive documentation with API reference, comparers guide, examples, and helpers

  • Improve code formatting and documentation in README with cleaner structure

  • Comment out unused const block and fix minor typos throughout codebase


Diagram Walkthrough

flowchart LR
  A["Code Changes"] --> B["IgnoreFieldsOf Function"]
  A --> C["CI/CD Updates"]
  A --> D["Code Cleanup"]
  E["Documentation"] --> F["API Reference"]
  E --> G["Comparers Guide"]
  E --> H["Examples & Patterns"]
  E --> I["Helpers Documentation"]
  E --> J["README Restructure"]
Loading

File Walkthrough

Relevant files
Enhancement
1 files
functions.go
Add IgnoreFieldsOf and comment unused constants                   
+16/-5   
Formatting
2 files
functions_test.go
Fix struct literal syntax and typo in test names                 
+3/-3     
trial_test.go
Simplify struct initialization syntax in test cases           
+5/-5     
Configuration changes
1 files
test.yml
Expand Go versions and update GitHub Actions versions       
+15/-15 
Documentation
7 files
README.md
Restructure documentation with new doc files and improve formatting
+65/-71 
api.md
Create comprehensive API reference documentation                 
+112/-0 
comparers.md
Create detailed comparers guide with examples and use cases
+387/-0 
examples.md
Create practical examples and patterns for trial usage     
+364/-0 
helpers.md
Create helpers documentation with all utility functions   
+184/-0 
go.mod
Add comment explaining go-cmp version compatibility           
+4/-0     
test_case.md
Remove obsolete test case documentation file                         
+0/-158 

@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

🔴
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing type validation: IgnoreFieldsOf accepts any structType without validation and may panic at runtime if a
non-struct (or wrong shape) value is passed into cmpopts.IgnoreFields.

Referred Code
func IgnoreFieldsOf(structType interface{}, fields ...string) func(interface{}) cmp.Option {
	return func(_ interface{}) cmp.Option {
		return cmpopts.IgnoreFields(structType, fields...)
	}
}

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Unvalidated external input: IgnoreFieldsOf takes an unvalidated caller-provided structType which can trigger
panics/unsafe behavior in reflection-based comparison options if misused, rather than
failing fast with a clear validation error.

Referred Code
func IgnoreFieldsOf(structType interface{}, fields ...string) func(interface{}) cmp.Option {
	return func(_ interface{}) cmp.Option {
		return cmpopts.IgnoreFields(structType, fields...)
	}
}

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix panic with slice of pointers

Refactor the IgnoreFields function to correctly handle slices of pointers by
properly dereferencing the element type, thus preventing a panic.

functions.go [180-192]

 func IgnoreFields(f ...string) func(interface{}) cmp.Option {
 	return func(i interface{}) cmp.Option {
 		t := reflect.TypeOf(i)
-		if t.Kind() == reflect.Ptr { // dereference pointers
-			i = reflect.New(t.Elem()).Elem().Interface()
+		if t == nil {
+			return cmp.Options{}
 		}
-		// get the type of element of a slice/array
-		if t.Kind() == reflect.Slice || t.Kind() == reflect.Array {
-			i = reflect.New(t.Elem()).Elem().Interface()
+
+		switch t.Kind() {
+		case reflect.Slice, reflect.Array:
+			t = t.Elem()
 		}
+
+		if t.Kind() == reflect.Ptr {
+			t = t.Elem()
+		}
+
+		i = reflect.New(t).Elem().Interface()
 		return cmpopts.IgnoreFields(i, f...)
 	}
 }

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 8

__

Why: This suggestion correctly identifies a bug in the existing IgnoreFields function that causes a panic when used with a slice of pointers. The proposed fix is accurate and makes the function more robust by correctly handling pointer types within slices.

Medium
Prevent panic on nil struct type

Add a nil check to the IgnoreFieldsOf function to prevent a panic when a nil
pointer is passed as the structType, returning a no-op option instead.

functions.go [194-203]

 // IgnoreFieldsOf ignores specific fields on a given struct type.
 // Use this when ignoring fields in embedded structs where IgnoreFields
 // cannot infer the correct type.
 //
 //	trial.EqualOpt(trial.IgnoreFieldsOf(Metadata{}, "CreatedAt", "UpdatedAt"))
 func IgnoreFieldsOf(structType interface{}, fields ...string) func(interface{}) cmp.Option {
 	return func(_ interface{}) cmp.Option {
+		if v := reflect.ValueOf(structType); v.Kind() == reflect.Ptr && v.IsNil() {
+			return cmp.Options{}
+		}
 		return cmpopts.IgnoreFields(structType, fields...)
 	}
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential panic in the new IgnoreFieldsOf function when a nil pointer to a struct is passed. Adding a nil check improves the function's robustness and prevents unexpected test failures.

Medium
  • More

@jbsmith7741 jbsmith7741 merged commit 9bde5ab into main Jan 23, 2026
16 checks passed
@jbsmith7741 jbsmith7741 deleted the update branch January 23, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant