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

Include support for multiple reporter output types, solves #109 #181

Merged
merged 24 commits into from
Oct 30, 2024

Conversation

xanish
Copy link
Contributor

@xanish xanish commented Oct 14, 2024

Hey,

I was learning Go and thought I'd try contributing to this repo. This merge solves the issue #109.

I have kept the input param as comma separated string since that was used on existing params like exclude-file-types.

I wasn't sure if we would need validation to prevent running in case reporters were passed as JSON and Standard but no output file was specified. Maybe we should add a validation to force output to be present so that it can write JSON to the file and still output to Stdout.

Do let me know in case I've missed something or any change is needed.

@kehoecj kehoecj added hacktoberfest-accepted Valid PR Hacktoberfest PR hacktoberfest 🎃 Hacktoberfest 2024 waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Oct 14, 2024
cmd/validator/validator.go Outdated Show resolved Hide resolved
cmd/validator/validator.go Outdated Show resolved Hide resolved
cmd/validator/validator.go Outdated Show resolved Hide resolved
pkg/cli/cli.go Show resolved Hide resolved
@xanish
Copy link
Contributor Author

xanish commented Oct 20, 2024

hey @ccoVeille is it good to merge?

@ccoVeille
Copy link
Contributor

Yes, that's why I approved 😁

cmd/validator/validator.go Outdated Show resolved Hide resolved
cmd/validator/validator.go Outdated Show resolved Hide resolved
@kehoecj
Copy link
Collaborator

kehoecj commented Oct 21, 2024

@xanish Combining multiple reporters with --output results in confusing behavior as it's not clear as a user what will be produced in the output file. With multiple reporters we need to rethink how we handle outputting the reporters to a file. I like the way chef inspec handles multiple reporters where an output file is declared with the reporter type.

@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 Oct 21, 2024
@xanish
Copy link
Contributor Author

xanish commented Oct 21, 2024

@kehoecj i can implement it like chef inspec. Do you also want me to get rid of the file flag and then include file in the reporter flag separated by ":".

Will have to use flag.Var to get multiple --reporter as an array then process it.

Flags would be as follows --reporter json:some_file_path --reporter junit:another_file_path

@kehoecj
Copy link
Collaborator

kehoecj commented Oct 21, 2024

@kehoecj i can implement it like chef inspec. Do you also want me to get rid of the file flag and then include file in the reporter flag separated by ":".

Will have to use flag.Var to get multiple --reporter as an array then process it.

Flags would be as follows --reporter json:some_file_path --reporter junit:another_file_path

Yes, that sounds great. So to summarize:

  1. Remove --output flag
  2. Allowed multiple reporters to be specified by multiple --reporter flags
  3. Optionally allow users to specify a file for each reporter by adding the file path and name after the reporter type
  4. Document this on the README

@xanish
Copy link
Contributor Author

xanish commented Oct 21, 2024

Done, lemme know if it is as expected 😄

@kehoecj
Copy link
Collaborator

kehoecj commented Oct 21, 2024

Done, lemme know if it is as expected 😄

Very nice! One last thing, I'm not sure the report should display to stdout if an output file is specified. What do you think?

@xanish
Copy link
Contributor Author

xanish commented Oct 22, 2024

Hey @kehoecj so i was working on making standard reporter output to file as well since that would make things "standard" across all reporters. But I had one doubt currently all reporters when passed an output file print to stdout as well as output to file do we want to make sure it only does either of it? Like if output is specified then only write to file otherwise write to stdout.

@kehoecj
Copy link
Collaborator

kehoecj commented Oct 22, 2024

Hey @kehoecj so i was working on making standard reporter output to file as well since that would make things "standard" across all reporters. But I had one doubt currently all reporters when passed an output file print to stdout as well as output to file do we want to make sure it only does either of it? Like if output is specified then only write to file otherwise write to stdout.

Yes, let's go ahead and standardize it:

  • If an output file is passed it will always send the results to the output file
  • If they just want stdout they just pass the reporter name, i.e. --reporter json
  • If they want to do both they'd pass two reporters: --reporter json --reporter json:/path/to/file.json

@xanish What do you think?

@xanish
Copy link
Contributor Author

xanish commented Oct 22, 2024

Ok so i made the changes and also merged main from upstream. I have a doubt regarding how the reporter flag will work with ENV, while testing i noticed that passing something like

CFV_REPORTER=standard:output.txt go run cmd/validator/validator.go --reporter=junit:op.xml test/fixtures/good.csv

uses both the env value and cli value

EDIT:

Ignore figured out the issue, flag.Parse() should happen before the env check and set logic

@kehoecj
Copy link
Collaborator

kehoecj commented Oct 23, 2024

Hey @kehoecj can you help me out with this, I'm not seeing what the exact error is from the linter.

  Running [/home/runner/golangci-lint-1.57.2-linux-amd64/golangci-lint run --out-format=github-actions --timeout=10m] in [] ...
  Error: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/Boeing/config-file-validator) (gci)
  Error: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/Boeing/config-file-validator) (gci)
  
  Error: issues found
  Ran golangci-lint in 7903ms

Did you try golangci-lint run --fix?

cmd/validator/validator.go Outdated Show resolved Hide resolved
@xanish
Copy link
Contributor Author

xanish commented Oct 23, 2024

Im kindof getting conflicting error with my local machine saying

danee@TOASTER:~/Code/open-source/config-file-validator> golangci-lint run --fix
pkg/reporter/reporter_test.go:507:3: comment-spacings: no space between comment delimiter and comment text (revive)
		//nolint: testifylint // in this use case it's ok to use assert.Error

and github action saying that it does not need space 😅

  Running [/home/runner/golangci-lint-1.57.2-linux-amd64/golangci-lint run --out-format=github-actions --timeout=10m] in [] ...
  Error: directive `// nolint: testifylint // in this use case it's ok to use assert.Error` should be written without leading space as `//nolint: testifylint // in this use case it's ok to use assert.Error` (nolintlint)

@kehoecj
Copy link
Collaborator

kehoecj commented Oct 23, 2024

Im kindof getting conflicting error with my local machine saying

danee@TOASTER:~/Code/open-source/config-file-validator> golangci-lint run --fix
pkg/reporter/reporter_test.go:507:3: comment-spacings: no space between comment delimiter and comment text (revive)
		//nolint: testifylint // in this use case it's ok to use assert.Error

and github action saying that it does not need space 😅

  Running [/home/runner/golangci-lint-1.57.2-linux-amd64/golangci-lint run --out-format=github-actions --timeout=10m] in [] ...
  Error: directive `// nolint: testifylint // in this use case it's ok to use assert.Error` should be written without leading space as `//nolint: testifylint // in this use case it's ok to use assert.Error` (nolintlint)

@ccoVeille Any ideas/suggestions?

@ccoVeille
Copy link
Contributor

Im kindof getting conflicting error with my local machine saying

danee@TOASTER:~/Code/open-source/config-file-validator> golangci-lint run --fix
pkg/reporter/reporter_test.go:507:3: comment-spacings: no space between comment delimiter and comment text (revive)
		//nolint: testifylint // in this use case it's ok to use assert.Error

and github action saying that it does not need space 😅

  Running [/home/runner/golangci-lint-1.57.2-linux-amd64/golangci-lint run --out-format=github-actions --timeout=10m] in [] ...
  Error: directive `// nolint: testifylint // in this use case it's ok to use assert.Error` should be written without leading space as `//nolint: testifylint // in this use case it's ok to use assert.Error` (nolintlint)

Here is what is expected I think

#181 (comment)

cc @kehoecj

cmd/validator/validator.go Outdated Show resolved Hide resolved
cmd/validator/validator.go Outdated Show resolved Hide resolved
cmd/validator/validator.go Outdated Show resolved Hide resolved
cmd/validator/validator.go Show resolved Hide resolved
pkg/cli/group_output_test.go Outdated Show resolved Hide resolved
pkg/reporter/junit_reporter.go Show resolved Hide resolved
README.md Show resolved Hide resolved
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.

The output for the standard reporter no longer colorizes the output or formats it properly:

    ✓ /tests/fixtures/exclude-file-types/excluded.json    ✓ /tests/fixtures/exclude-file-types/not-excluded.toml    ✓ /tests/fixtures/good.csv    ✓ /tests/fixtures/good.editorconfig    ✓ /tests/fixtures/good.env    ✓ /tests/fixtures/good.hcl    ✓ /tests/fixtures/good.hocon    ✓ /tests/fixtures/good.ini    ✓ /tests/fixtures/good.json    ✓ /tests/fixtures/good.plist    ✓ /tests/fixtures/good.properties    ✓ /tests/fixtures/good.toml    ✓ /tests/fixtures/good.yaml    ✓ /tests/fixtures/mixedcase-extension/good.CSv    ✓ /tests/fixtures/mixedcase-extension/good.HCl    ✓ /tests/fixtures/mixedcase-extension/good.INi    ✓ /tests/fixtures/mixedcase-extension/good.JSon    ✓ /tests/fixtures/mixedcase-extension/good.PList    ✓ /tests/fixtures/mixedcase-extension/good.PRoperties    ✓ /tests/fixtures/mixedcase-extension/good.TOml    ✓ /tests/fixtures/mixedcase-extension/good.YAml    × /tests/fixtures/subdir/bad.json
        error: Error at line 3 column 14: invalid character ':' after array element
    × /tests/fixtures/subdir/bad.toml
        error: Error at line 6 column 6: toml: expected character =
    × /tests/fixtures/subdir/bad.yml
        error: yaml: line 3: did not find expected '-' indicator
    ✓ /tests/fixtures/subdir/good.json    × /tests/fixtures/subdir2/bad.csv
        error: parse error on line 1, column 20: bare " in non-quoted-field
    × /tests/fixtures/subdir2/bad.editorconfig
        error: cannot load ini file: unclosed section: [*.md
    × /tests/fixtures/subdir2/bad.env
        error: Error at line 2: invalid escape sequence: "a"
    × /tests/fixtures/subdir2/bad.hcl
        error: error at line 1 column 1: :1,1-2: Invalid argument name; Argument names must not be quoted.
    × /tests/fixtures/subdir2/bad.hocon
        error: two adjacent commas at: 3:16, adjacent commas in arrays and objects are invalid!
    × /tests/fixtures/subdir2/bad.ini
        error: key-value delimiter not found: name value
    × /tests/fixtures/subdir2/bad.json
        error: Error at line 1 column 3: invalid character '}' looking for beginning of value
    × /tests/fixtures/subdir2/bad.plist
        error: plist: error parsing XML property list: missing value in dictionary
    × /tests/fixtures/subdir2/bad.properties
        error: circular reference in:
               key=${key}
    ✓ /tests/fixtures/subdir2/good.ini    ✓ /tests/fixtures/subdir2/good.json    ✓ /tests/fixtures/uppercase-extension/good.CSV    ✓ /tests/fixtures/uppercase-extension/good.HCL    ✓ /tests/fixtures/uppercase-extension/good.INI    ✓ /tests/fixtures/uppercase-extension/good.JSON    ✓ /tests/fixtures/uppercase-extension/good.PLIST    ✓ /tests/fixtures/uppercase-extension/good.PROPERTIES    ✓ /tests/fixtures/uppercase-extension/good.TOML    ✓ /tests/fixtures/uppercase-extension/good.YAML    ✓ /tests/fixtures/with-depth/additional-depth/sample.json    ✓ /tests/fixtures/with-depth/sample.json    ✓ /tests/output/example/good.json    ✓ /tests/output/example/result.json    ✓ /tests/output/example/result.xml    ✓ /tests/report.json    ✓ /tests/report.xml    ✓ /tests/scan.json    ✓ /tests/scan.xml%   

@xanish
Copy link
Contributor Author

xanish commented Oct 28, 2024

weird it works for me locally, did you merge main? i guess something must've broken.

@xanish
Copy link
Contributor Author

xanish commented Oct 28, 2024

@kehoecj can you check now

Also lemme know how do you want me to resolve the indentation thing

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.

Final checks passed this morning. Thank you for the PR @xanish !

@kehoecj kehoecj merged commit decfab8 into Boeing:main Oct 30, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest 🎃 Hacktoberfest 2024 hacktoberfest-accepted Valid PR Hacktoberfest PR pr-action-requested PR is awaiting feedback from the submitting developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants