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

Fix Go Report Card Issues #131

Merged
merged 15 commits into from
Apr 10, 2024
Merged

Fix Go Report Card Issues #131

merged 15 commits into from
Apr 10, 2024

Conversation

HakanVardarr
Copy link
Contributor

I fixed all of the issues listed on goreportcard.
Screenshot 2024-03-30 at 09 52 41

Copy link
Contributor

@ccoVeille ccoVeille left a 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)

Copy link
Contributor Author

@HakanVardarr HakanVardarr left a 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.

Copy link
Contributor

@ccoVeille ccoVeille left a 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

@ccoVeille
Copy link
Contributor

ccoVeille commented Mar 30, 2024

I added these refactorings to the PR thanks.

May I ask a Co-Authored-By tag in your commit message then ? 😆

https://docs.github.com/articles/creating-a-commit-with-multiple-authors#:~:text=a%20remote%20repository.%22-,Creating%20co%2Dauthored%20commits%20on%20GitHub,address%20for%20each%20co%2Dauthor.

Mine would be something like

Co-authored-by: ccoVeille <[email protected]>

Co-authored-by: ccoVeille <[email protected]>
@HakanVardarr
Copy link
Contributor Author

I added these refactorings to the PR thanks.

May I ask a Co-Authored-By tag in your commit message then ? 😆

https://docs.github.com/articles/creating-a-commit-with-multiple-authors#:~:text=a%20remote%20repository.%22-,Creating%20co%2Dauthored%20commits%20on%20GitHub,address%20for%20each%20co%2Dauthor.

Mine would be something like

Co-authored-by: ccoVeille <[email protected]>

Is this right? First time doing this. :)

@ccoVeille
Copy link
Contributor

I added these refactorings to the PR thanks.

May I ask a Co-Authored-By tag in your commit message then ? 😆
https://docs.github.com/articles/creating-a-commit-with-multiple-authors#:~:text=a%20remote%20repository.%22-,Creating%20co%2Dauthored%20commits%20on%20GitHub,address%20for%20each%20co%2Dauthor.
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 Co-authored-by:

@ccoVeille
Copy link
Contributor

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

did you see this @HakanVardarr BTW? what are your thoughts about it ?

@HakanVardarr
Copy link
Contributor Author

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

did you see this @HakanVardarr BTW? what are your thoughts about it ?

Oh I didn't see these, I'm looking right now

@HakanVardarr
Copy link
Contributor Author

I think that looks good. I'll add it and co-auther you.

@HakanVardarr
Copy link
Contributor Author

I added the co-authered-by part @ccoVeille is it right?

Co-authored-by: ccoVeille <[email protected]>
@ccoVeille
Copy link
Contributor

It's ok 305ebba

You can see here our names in
image

You can also see it here

image

The right pattern to use is:

Commit message

Co-authored-by: ccoVeille <[email protected]>

And if you have to add a description it would be

Commit message

Description line1
Description line2
(...)

Co-authored-by: ccoVeille <[email protected]>

@ccoVeille
Copy link
Contributor

Thanks for following my suggestion. I think we are good.

The code is now clearer and easier to maintain.

@ccoVeille
Copy link
Contributor

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

@HakanVardarr
Copy link
Contributor Author

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.

@kehoecj kehoecj added OSS Community Contribution Contributions from the OSS Community waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Apr 1, 2024
@kehoecj kehoecj self-requested a review April 1, 2024 14:04
Copy link
Collaborator

@kehoecj kehoecj left a 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?

@kehoecj kehoecj added pr-action-requested PR is awaiting feedback from the submitting developer and removed waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Apr 1, 2024
@HakanVardarr
Copy link
Contributor Author

I hope they are right I got midterm tomorrow I don't have much time to debug :) @kehoecj

@HakanVardarr
Copy link
Contributor Author

Unit tests are passing but coverage is not. :(

@kehoecj
Copy link
Collaborator

kehoecj commented Apr 1, 2024

I hope they are right I got midterm tomorrow I don't have much time to debug :) @kehoecj

No rush! Midterm is more important 😀

@HakanVardarr
Copy link
Contributor Author

I hope they are right I got midterm tomorrow I don't have much time to debug :) @kehoecj

No rush! Midterm is more important 😀

I handled the unit tests but coverage is stuck at 94.9% 😄

@ccoVeille
Copy link
Contributor

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]>
@HakanVardarr
Copy link
Contributor Author

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")
                        }

Yep they worked perfect. Thanks, I Co-Authered you to the commit.

@kehoecj kehoecj added waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers and removed pr-action-requested PR is awaiting feedback from the submitting developer labels Apr 1, 2024
@ccoVeille
Copy link
Contributor

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.

@HakanVardarr
Copy link
Contributor Author

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.

@ccoVeille
Copy link
Contributor

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.

@HakanVardarr
Copy link
Contributor Author

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. 😅

Copy link
Collaborator

@kehoecj kehoecj left a 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

@kehoecj kehoecj merged commit 9006fce into Boeing:main Apr 10, 2024
4 checks passed
@ccoVeille
Copy link
Contributor

Great @HakanVardarr, I can rebase mine now.

I hope you enjoyed my help on your PR.

@ccoVeille
Copy link
Contributor

@kehoecj I appreciate you squashed all the changes: 9006fce

I was unsure the Co-Authored-By would be kept, but I'm happy to see it worked

@HakanVardarr
Copy link
Contributor Author

Great @HakanVardarr, I can rebase mine now.

I hope you enjoyed my help on your PR.

I enjoyed your help. Thanks <3

shiina4119 pushed a commit to shiina4119/config-file-validator that referenced this pull request Aug 23, 2024
* 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]>
shiina4119 pushed a commit to shiina4119/config-file-validator that referenced this pull request Oct 4, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OSS Community Contribution Contributions from the OSS Community waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants