-
Notifications
You must be signed in to change notification settings - Fork 72
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
Fix Go Report Card Issues #131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said in #134 (comment) you fixed #134 issue.
But I would recommend considering simplifying your code like this
// Group the output if the user specified a group by option
// Length is equal to one when empty as it contains an empty string
if len(GroupOutput) == 1 && GroupOutput[0] != "" {
// Check reporter type to determine how to print
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
return reporter.PrintSingleGroupJson(reportGroup.(map[string][]reporter.Report))
}
return reporter.PrintSingleGroupStdout(reportGroup.(map[string][]reporter.Report))
} else if len(GroupOutput) == 2 {
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
return reporter.PrintDoubleGroupJson(reportGroup.(map[string]map[string][]reporter.Report))
}
return reporter.PrintDoubleGroupStdout(reportGroup.(map[string]map[string][]reporter.Report))
} else if len(GroupOutput) == 3 {
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
return reporter.PrintTripleGroupJson(reportGroup.(map[string]map[string]map[string][]reporter.Report))
}
return reporter.PrintTripleGroupStdout(reportGroup.(map[string]map[string]map[string][]reporter.Report))
}
return c.Reporter.Print(reports)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these refactorings to the PR thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because you are now returning different type result, you are using interface{}
here
It leads you to play with type assertion when calling the reporters.
I would suggest you to write something like this
// printReports prints the reports based on the specified grouping and reporter type.
// It returns any error encountered during the printing process.
func (c CLI) printReports(reports []reporter.Report) error {
if Quiet {
return nil
}
switch len(GroupOutput) {
case 1:
return printGroupSingle(reports)
case 2:
return printGroupDouble(reports)
case 3:
return printGroupTriple(reports)
default:
return nil, fmt.Errorf("Invalid number of group outputs: %d", len(GroupOutput))
}
}
func (c CLI) printGroupSingle(reports []reporter.Report) error {
if GroupOutput[0] == "" {
return c.Reporter.Print(reports)
}
reportGroup, err := c.GroupBySingle(reports, GroupOutput[0])
if err != nil {
return err
}
// Check reporter type to determine how to print
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
return reporter.PrintSingleGroupJson(reportGroup)
}
return reporter.PrintSingleGroupStdout(reportGroup)
}
func (c CLI) printGroupDouble(reports []reporter.Report) error {
reportGroup, err := c.GroupByDouble(reports, GroupOutput)
if err != nil {
return err
}
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
return reporter.PrintDoubleGroupJson(reportGroup)
}
return reporter.PrintDoubleGroupStdout(reportGroup)
}
func (c CLI) printGroupTriple(reports []reporter.Report) error {
reportGroup, err := c.GroupByTriple(reports, GroupOutput)
if err != nil {
return err
}
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
return reporter.PrintTripleGroupJson(reportGroup)
}
return reporter.PrintTripleGroupStdout(reportGroup)
}
This is mostly pseudocode made in a web browser, it may need some adjustments
May I ask a Mine would be something like
|
Co-authored-by: ccoVeille <[email protected]>
Is this right? First time doing this. :) |
I think you should have a new line between the commit message and the |
did you see this @HakanVardarr BTW? what are your thoughts about it ? |
Oh I didn't see these, I'm looking right now |
I think that looks good. I'll add it and co-auther you. |
> > Co-authored-by: ccoVeille <[email protected]>
I added the co-authered-by part @ccoVeille is it right? |
Co-authored-by: ccoVeille <[email protected]>
It's ok 305ebba You can also see it here The right pattern to use is:
And if you have to add a description it would be
|
Thanks for following my suggestion. I think we are good. The code is now clearer and easier to maintain. |
You just have to check if all tests are good. I'm a bit worried that your version will report nothing in json mode if quiet is enabled. So maybe, you will have to remove the if quiet and return nil in each print single/double/triple when quiet is true and it's not about dumping json |
I think this commit solves the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @HakanVardarr ! Looks like some good improvements. Can you take a look at the failing unit tests?
I hope they are right I got midterm tomorrow I don't have much time to debug :) @kehoecj |
Unit tests are passing but coverage is not. :( |
No rush! Midterm is more important 😀 |
I handled the unit tests but coverage is stuck at 94.9% 😄 |
This may help you go test -coverprofile=cover.out ./... ; go tool cover -html=cover.out -o cover.html You will see you can improve coverage in if *reportTypePtr == "junit" && *groupOutputPtr != "" {
fmt.Println("Wrong parameter value for reporter, groupby is not supported for JUnit reports")
flag.Usage()
return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is not supported for JUnit reports")
} and if _, ok := seenValues[groupBy]; ok {
fmt.Println("Wrong parameter value for groupby, duplicate values are not allowed")
flag.Usage()
return validatorConfig{}, errors.New("Wrong parameter value for groupby, duplicate values are not allowed")
} |
Co-authored-by: ccoVeille <[email protected]>
Yep they worked perfect. Thanks, I Co-Authered you to the commit. |
I would say the number of commits could be reduced by grouping them with an interactive rebase. But I will let maintainers tell what they want. |
I don't know much about git stuffs. I am new to this that is why commit number is high. |
It's OK. Let's wait for the maintainers point of view. Have fun with your midterms. That's more important to worry about. |
I'll try to have fun. 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks @HakanVardarr fixing the report card issues and general cleanup
Great @HakanVardarr, I can rebase mine now. I hope you enjoyed my help on your PR. |
I enjoyed your help. Thanks <3 |
* Fix ineffassign * Fix ineffassign * Fix misspell * Fix gocyclo * Return error * @ccoVeille s suggestion * Returning error Co-authored-by: ccoVeille <[email protected]> * Removed interface{} to solve type problems. > > Co-authored-by: ccoVeille <[email protected]> * Comment Co-authored-by: ccoVeille <[email protected]> * Fix file output on quiet flag * Delete test/result.json * Changed 1 test * Test fix * remove test.txt * Coverage test Co-authored-by: ccoVeille <[email protected]> --------- Co-authored-by: ccoVeille <[email protected]>
* Fix ineffassign * Fix ineffassign * Fix misspell * Fix gocyclo * Return error * @ccoVeille s suggestion * Returning error Co-authored-by: ccoVeille <[email protected]> * Removed interface{} to solve type problems. > > Co-authored-by: ccoVeille <[email protected]> * Comment Co-authored-by: ccoVeille <[email protected]> * Fix file output on quiet flag * Delete test/result.json * Changed 1 test * Test fix * remove test.txt * Coverage test Co-authored-by: ccoVeille <[email protected]> --------- Co-authored-by: ccoVeille <[email protected]>
I fixed all of the issues listed on goreportcard.