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
Conversation
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. |
xiblint/xibcontext.py
Outdated
"file": self.path, | ||
"line": element.line, | ||
"error": new_error, | ||
"rule": self.rule_name |
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.
nit - add trailing comma (should add a linter for this :)
xiblint/__main__.py
Outdated
error_dict["file"], | ||
error_dict["line"], | ||
error_dict["error"], | ||
error_dict["rule"] |
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.
nit - trailing comma
xiblint/__main__.py
Outdated
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) |
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.
nit - errors = errors +
—> errors +=
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.
ye, habbit from Swift 😅
xiblint/__main__.py
Outdated
parser.parse_args() | ||
parser.add_argument("--reporter", choices=("raw", "json"), | ||
default="raw", | ||
help="custom reporter to use (optional)") |
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.
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.
xiblint/__main__.py
Outdated
@@ -3,6 +3,7 @@ | |||
import argparse | |||
import os | |||
import sys | |||
import json |
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.
let's move this after argparse
. I should add isort
as a linter...
xiblint/__main__.py
Outdated
default="raw", | ||
help="custom reporter to use (optional)") | ||
args = parser.parse_args() | ||
reporter = args.reporter |
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.
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.
xiblint/__main__.py
Outdated
|
||
sys.exit(0 if errors.count == 0 else 1) |
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.
Did you mean len(errors) == 0
? ;)
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 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 😄
xiblint/xibcontext.py
Outdated
message.format(*args), | ||
self.rule_name, | ||
)) | ||
message.format(*args) |
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.
add trailing comma
@ikonst thanks for the review! I've added a commit with suggested fixes and tested it locally - it still works 😄 |
xiblint/__main__.py
Outdated
|
||
sys.exit(len(errors) == 0) |
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.
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)
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.
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 ;-)
Thanks again @sunshinejr. Excited to see this is useful outside of our company! |
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!