-
Notifications
You must be signed in to change notification settings - Fork 117
Add ruff rules for flake8-simplify #1113
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
base: main
Are you sure you want to change the base?
Conversation
|
Any reason in particular you want these in? In my experience the SIM rules are quite opinionated, so I wasn't very inclined to turn them on. |
|
SIM rules are primarily designed to simplify readability when transitioning from one project to another. If they do not correspond to this project's needs, then this PR can be closed. |
alexfikl
left a comment
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'm not against it, so if you want to work on it some more, we can add them. I left some comments from a quick look. Let me know what you think!
| picked_documents = documents | ||
| else: | ||
| picked_documents = list(papis.api.pick_doc(documents)) | ||
| picked_documents = documents if all_ else list(papis.api.pick_doc(documents)) |
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.
Can you disable SIM108? This might be personal preference, but I've never liked putting the condition in the middle (likely because of all the normal ifs).
| elif key == "files": | ||
| if not check_files(document): | ||
| result.append({"doc": document, "key": key, "msg": "Missing files"}) |
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.
Can you disable SIM102? This was most written as a "switch on each [KEY] type and do [THING]", so combing the ifs is a bit confusing.
| ) | ||
|
|
||
| if not len(troubled_docs) == 0: | ||
| if len(troubled_docs) != 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.
Isn't the pythonic way to do with if not troubled_docs?
| with t.button(cls="btn btn-success", | ||
| type="submit"): | ||
| wh.icon_span("cloud-bolt", "Fetch citations") | ||
| if "doi" in doc: | ||
| quoted_doi = urllib.parse.quote(doc["doi"], safe="") | ||
| with t.a(cls="btn btn-primary", | ||
| target="_blank", | ||
| href=ads_fmt.format(doi=quoted_doi)): | ||
| wh.icon_span("globe", "ads") |
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 the reasoning here (to abuse the nesting) was to match the HTML tags better. I'm not sure it's an improvement to group them?
https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
%
ruff check --select=SIM --ignore=SIM102,SIM117 --statistics