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

use ruff for linting #1364

Merged
merged 22 commits into from
Dec 17, 2024
Merged

use ruff for linting #1364

merged 22 commits into from
Dec 17, 2024

Conversation

c0rydoras
Copy link
Contributor

@c0rydoras c0rydoras commented Nov 22, 2024

right now the CI should fail because some rules can't safely be fixed automatically

before I start fixing/ignoring things to make the CI pass, I'd like to know if linting like this is even something you (the maintainers) would want

(if this were ever to land it would make sense to add the commits to a .git-blame-ignore-revs; see https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view)

@@ -794,7 +789,7 @@
fd, self._name = tempfile.mkstemp(
suffix=".vol3", prefix="tmp_", dir=output_dir
)
self._file = io.open(fd, mode="w+b")
self._file = open(fd, mode="w+b")

Check warning

Code scanning / CodeQL

File is not always closed Warning

File is opened but is not closed.
@c0rydoras c0rydoras force-pushed the linting branch 6 times, most recently from e89eacd to b789f53 Compare November 22, 2024 13:11
@c0rydoras c0rydoras marked this pull request as ready for review November 22, 2024 13:17
@ikelos
Copy link
Member

ikelos commented Nov 22, 2024

Can you explain the pros (and cons) of using ruff over black please?

@c0rydoras
Copy link
Contributor Author

ruff is more than black, it has a formatter but it started as a linter, it (the formatter) is faster than black and more configurable, it can also format docstrings

its linter is not only faster than other linting tools (e.g. flake8, pylint etc.) but it also supports a lot of those linters (e.g. https://docs.astral.sh/ruff/rules/#flake8-builtins-a, https://docs.astral.sh/ruff/rules/#pylint-pl) (and a lot more rules in general)

the only real change here is that there's faster formatting (it might deviate a bit from black, see https://docs.astral.sh/ruff/formatter/black/) and just one dependency (ruff) for linting and formatting instead of 2 (ruff for linting and black for formatting)

@ikelos
Copy link
Member

ikelos commented Nov 22, 2024

Thanks, I'm a little suspicious that there weren't any downsides to using ruff, that's why I asked for pros and cons. I've run some tests and there's 9 files that black and ruff can't agree on how to format. I also kinda liked black in that it wasn't configurable, and so you wouldn't get bickering about people wanting the formatting done a particular way. Would it be possible to add in ruff just as a linter initially, get those issues fixed up if possible (I prefer to fix rather than ignore, because it's either a bad rule that can be ignored anywhere, or it's a good rule that should always be followed) and then consider shifting the formatter over to ruff from black once the dust has cleared?

@c0rydoras c0rydoras force-pushed the linting branch 4 times, most recently from 8c8e05a to d9b786b Compare November 22, 2024 15:47
@c0rydoras c0rydoras changed the title use ruff for linting and formatting use ruff for linting Nov 22, 2024
@c0rydoras
Copy link
Contributor Author

ruff is now only used for linting

@ikelos
Copy link
Member

ikelos commented Nov 22, 2024

Thanks very much, I'm generally happy with the changes it's made. There's a couple places where it's decided not including defaults is better than being explicit, which I can get used to. Would it be possible to make the suggested changes so get rid of the errors that ruff is reporting in the code base, or would that need to be done in a second commit (just worried this'll be importing a new test that then immediately fails, and I'd prefer we knew it wouldn't impede new commits).

Deciding on the ignore list will be tricky...

I think the module imports can move up, and I understand the reasoning behind not using f-strings in argparse, so I think we could manually make the necessary change without breaking anything. Would you be up for making those please?

@c0rydoras
Copy link
Contributor Author

Deciding on the ignore list will be tricky...

right now its configured to only use a few rules, there might be other ones we want to enable: https://docs.astral.sh/ruff/rules/

Copy link
Member

@ikelos ikelos left a comment

Choose a reason for hiding this comment

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

Thanks very much for making those recent changes, there's a few bits I'd prefer to tweak before we introduce them though (sorry to be picky, but this will set the way we're picky for all future commits, so best to get it right now if possible)... 5:)

development/schema_validate.py Outdated Show resolved Hide resolved
doc/source/conf.py Show resolved Hide resolved
volatility3/framework/__init__.py Outdated Show resolved Hide resolved
volatility3/framework/configuration/__init__.py Outdated Show resolved Hide resolved
volatility3/framework/constants/__init__.py Outdated Show resolved Hide resolved
volatility3/framework/interfaces/__init__.py Outdated Show resolved Hide resolved
volatility3/framework/layers/resources.py Fixed Show resolved Hide resolved
volatility3/framework/plugins/mac/kauth_scopes.py Outdated Show resolved Hide resolved
volatility3/framework/plugins/windows/netscan.py Outdated Show resolved Hide resolved
@ikelos
Copy link
Member

ikelos commented Nov 22, 2024

Yeah, I'd prefer as few exceptions as possible. I'd even be ok with the lambda assignment one coming back in (assuming it wasn't difficult to fix the places it was complaining about)? Just trying to ensure we don't get time wasted on tweak or fixing than we do on agreeing and writing code that adheres to our standard...

@c0rydoras
Copy link
Contributor Author

ruff can fix the lambda one by itself, I just thought it looked uglier in the diff

@c0rydoras c0rydoras force-pushed the linting branch 3 times, most recently from 05cc386 to 383fdc9 Compare November 22, 2024 16:56
the import is not needed, was previously used for type annotations
@ikelos ikelos merged commit 32383a3 into volatilityfoundation:develop Dec 17, 2024
13 checks passed
@c0rydoras c0rydoras deleted the linting branch December 18, 2024 09:30
dgmcdona added a commit to dgmcdona/volatility3 that referenced this pull request Dec 18, 2024
When volatilityfoundation#1364 was merged, it may not have been rebased onto the changes
introduced in volatilityfoundation#1422, and they ended up overwritten to the old version.
This reverts those changes.
dgmcdona added a commit to dgmcdona/volatility3 that referenced this pull request Dec 18, 2024
When volatilityfoundation#1364 was merged, it may not have been rebased onto the changes
introduced in volatilityfoundation#1422, and they ended up overwritten to the old version.
This reverts those changes.
@ikelos
Copy link
Member

ikelos commented Dec 20, 2024

@c0rydoras Any idea why this didn't fail the ruff test we put in place? Just want to make sure it's operating as expected...

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.

3 participants