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

Add --reporter parameter #10

Merged
merged 7 commits into from Apr 16, 2018
Merged

Add --reporter parameter #10

merged 7 commits into from Apr 16, 2018

Conversation

sunshinejr
Copy link
Contributor

Adds optional reporter parameter with (currently) two options: "raw" and "json". Raw is the current one, while "json" returns a json string (useful to libraries using the output of linters, e.g. Danger).

As there is no doc around contributing to this repo: If this is something you don't want to see, just let me know and I can work on my own fork. Cheers!

@sunshinejr
Copy link
Contributor Author

Hey @ikonst @keith, any answer on this one would be much appreciated.

@ikonst
Copy link
Contributor

ikonst commented Apr 16, 2018

Hey @sunshinejr, sorry for the delay. I've missed your pull request originally, so thanks for tagging me. We also use Danger for the Lyft iOS apps, so your change is very welcome. By the way, the so-called "raw" output was actually designed for ingest by another one of our tools, https://github.com/lyft/linty_fresh.

Let me review your code and hopefully merge it.

"file": self.path,
"line": element.line,
"error": new_error,
"rule": self.rule_name
Copy link
Contributor

@ikonst ikonst Apr 16, 2018

Choose a reason for hiding this comment

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

nit - add trailing comma (should add a linter for this :)

error_dict["file"],
error_dict["line"],
error_dict["error"],
error_dict["rule"]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - trailing comma

for path in config.include_paths:
for root, _, files in os.walk(path):
for file_path in [os.path.join(root, file) for file in files]:
checkers = config.checkers(file_path)
success = process_file(file_path, checkers) and success
errors = errors + process_file(file_path, checkers, reporter)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - errors = errors + —> errors +=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ye, habbit from Swift 😅

parser.parse_args()
parser.add_argument("--reporter", choices=("raw", "json"),
default="raw",
help="custom reporter to use (optional)")
Copy link
Contributor

Choose a reason for hiding this comment

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

argparse arguments are always optional, so perhaps we can omit the "(optional)". The default value "raw" would be indicated as part of the help text anyway.

@@ -3,6 +3,7 @@
import argparse
import os
import sys
import json
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this after argparse. I should add isort as a linter...

default="raw",
help="custom reporter to use (optional)")
args = parser.parse_args()
reporter = args.reporter
Copy link
Contributor

Choose a reason for hiding this comment

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

After you assign this variable, you're never changing it, so perhaps directly using args.reporter will make it clearer that it's coming from the args.


sys.exit(0 if errors.count == 0 else 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean len(errors) == 0? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I couldn't get this one right and was hoping that you could help me with it in a PR but forgot to comment it 🤦‍♂️ thanks 😄

message.format(*args),
self.rule_name,
))
message.format(*args)
Copy link
Contributor

@ikonst ikonst Apr 16, 2018

Choose a reason for hiding this comment

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

add trailing comma

@sunshinejr
Copy link
Contributor Author

sunshinejr commented Apr 16, 2018

@ikonst thanks for the review! I've added a commit with suggested fixes and tested it locally - it still works 😄


sys.exit(len(errors) == 0)
Copy link
Contributor

@ikonst ikonst Apr 16, 2018

Choose a reason for hiding this comment

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

That looks incorrect. You want to exit with zero for success and non-zero for failure. You can also simply say:

sys.exit(1 if errors else 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, my mistake. Was so ashamed of this line that I quickly copied/pasted this one and wanted to forget about it 😓 Now tested the statement using the python interpreter and it works for an empty array as well 🤔 Didn't know that it worked that way ;-)

@ikonst ikonst merged commit 8405d84 into lyft:master Apr 16, 2018
@ikonst
Copy link
Contributor

ikonst commented Apr 16, 2018

Thanks again @sunshinejr. Excited to see this is useful outside of our company!

@sunshinejr sunshinejr deleted the feature/reporter branch April 16, 2018 20:44
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.

None yet

2 participants