Skip to content

fix: make newlines consistent and fix default value for format flag#548

Merged
ecPablo merged 3 commits into
mainfrom
ecpablo/fixes-analyzer
Oct 28, 2025
Merged

fix: make newlines consistent and fix default value for format flag#548
ecPablo merged 3 commits into
mainfrom
ecpablo/fixes-analyzer

Conversation

@ecPablo

@ecPablo ecPablo commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Some small fixes as a followup from the proposal analyzer refactor:

  • Standarize newlines in template files:
    Tried using:
{{.Value -}}

But If .tpml ends with a newline (added by IDE), this still won’t trim it because Go parses the template before evaluating it, and the newline is part of the literal text.

  • Throw error when invalid formater flag value is passed in.

@changeset-bot

changeset-bot Bot commented Oct 28, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5b053b4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ecPablo ecPablo marked this pull request as ready for review October 28, 2025 17:51
@ecPablo ecPablo requested review from a team as code owners October 28, 2025 17:51
Copilot AI review requested due to automatic review settings October 28, 2025 17:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR standardizes newline handling in template rendering and improves format flag validation. The changes ensure consistent output formatting by removing trailing newlines from template outputs (except when double newlines indicate intentional spacing) and add proper error handling for invalid format flag values.

Key changes:

  • Removes trailing newlines from template files and updates corresponding test expectations
  • Adds trimming logic to renderer methods to handle newlines consistently
  • Changes createRendererFromFormat to return an error for invalid format values instead of silently defaulting

Reviewed Changes

Copilot reviewed 7 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
experimental/analyzer/templates/text/named_field.tmpl Removes trailing newline from template file
experimental/analyzer/renderer_text_test.go Updates test assertion to match new output without trailing newline
experimental/analyzer/renderer_text.go Adds newline trimming logic to rendering methods and imports strings package
experimental/analyzer/renderer_markdown.go Adds newline trimming logic to template rendering helper
experimental/analyzer/describe_test.go Updates test expectations to reflect newline handling changes
experimental/analyzer/decoded_call_test.go Removes blank line from expected output in test
engine/cld/legacy/cli/mcmsv2/mcms_v2.go Updates format flag handling to return errors for invalid values and handle empty string case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1621 to +1627
// Default to markdown if format is not specified or invalid
return analyzer.NewMarkdownRenderer()
return nil, fmt.Errorf("unknown format '%s'", format)

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is now inaccurate. Since the function returns an error for unknown formats instead of defaulting to markdown, the comment should be updated to reflect this behavior. Consider: '// Return error for unknown formats'.

Copilot uses AI. Check for mistakes.
@ecPablo ecPablo enabled auto-merge October 28, 2025 18:09
@cl-sonarqube-production

Copy link
Copy Markdown

}

return buf.String()
out := buf.String()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/noaction: I still think you could avoid the undesired new line characters by inserting the appropriate dashes to the templates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me just use one example. I find the suggested patch more readable and more maintainable:

index 32037d2..e9fafa9 100644
--- i/experimental/analyzer/templates/text/decoded_call.tmpl
+++ w/experimental/analyzer/templates/text/decoded_call.tmpl
@@ -1,9 +1,14 @@
 Address: {{.Address}}
 Method: {{.Method}}
-{{if .Inputs}}
+{{- if .Inputs}}
 Inputs:
-{{range .Inputs}}  {{.Name}}: {{.Summary}}{{if .Details}} {{.Details}}{{end}}
-{{end}}{{end}}{{if .Outputs}}{{if .Inputs}}
-{{end}}Outputs:
-{{range .Outputs}}  {{.Name}}: {{.Summary}}{{if .Details}} {{.Details}}{{end}}
-{{end}}{{end}}
+{{- range .Inputs}}
+  {{.Name}}: {{.Summary}}{{if .Details}} {{.Details}}{{end}}
+{{- end}}
+{{- end}}
+{{- if .Outputs}}
+  Outputs:
+{{- range .Outputs}}
+  {{.Name}}: {{.Summary}}{{if .Details}} {{.Details}}{{end}}
+{{- end}}
+{{- end}}

@ecPablo ecPablo added this pull request to the merge queue Oct 28, 2025
Merged via the queue into main with commit b05e2e0 Oct 28, 2025
15 checks passed
@ecPablo ecPablo deleted the ecpablo/fixes-analyzer branch October 28, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants