Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Our CodeSnips are ugly #293

Closed
wants to merge 1 commit into from

Conversation

AdiAkhileshSingh15
Copy link
Contributor

This pull request addresses issue #241 .
It aims to enhance the readability of codeSnip script in output YAML. After going through the codebase, I found that as we are treating the CodeSnip as a string. Even while marshaling the rulesets using the gopkg.in/yaml.v2 package, the CodeSnip remained a string literal, regardless of multiline or single-line string.

To improve this, I wrote the outputViolations file with the new yaml content that has the CodeSnip as an object that encapsulates the code script, by storing the whole block of codeSnip object along with codeSnip object declaration in a new variable as
x := "codeSnip: |\n" + incidents[j].CodeSnip
codesnip = append(codesnip, x)
The new yaml file was constructed by iteratively inserting codeSnip lines after each message object. But, here as you might have noticed that it will only work if for each message object there is a codeSnip object as well.

I have tried this in a sample code with the same yaml file demo-output.yaml, in that, after each message object it did insert the codeSnip as expected. We just need to add some \t escape sequences before the block of codeSnip.

Although this approach may seem unconventional, it was born out of exhaustive attempts to maintain the desired code output format. Despite various trials, the existing limitations of marshaling to YAML with the CodeSnip as a string persisted.

While the code may need minor adjustments, I'm ready to make those changes. However, I kindly ask for your approval before proceeding with this approach of creating a temporary file and replacing it with our outputViolations file.

@AdiAkhileshSingh15 AdiAkhileshSingh15 changed the title [Fix] Our CodeSnips are ugly ✨ Our CodeSnips are ugly Aug 15, 2023
@AdiAkhileshSingh15 AdiAkhileshSingh15 changed the title ✨ Our CodeSnips are ugly ✨ Our CodeSnips are ugly Aug 15, 2023
@pranavgaikwad
Copy link
Contributor

@AdiAkhileshSingh15 Thank you for you contribution! While your approach solves the issue, I don't think this is the best approach. I would rather fix the issue at the root where it occurs, rather than writing a wrapper that updates an existing output.yaml file.

@pranavgaikwad
Copy link
Contributor

Closing this in favor of #294

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.

2 participants