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

Find better linting tool #409

Open
malthe opened this issue Jan 17, 2024 · 7 comments
Open

Find better linting tool #409

malthe opened this issue Jan 17, 2024 · 7 comments

Comments

@malthe
Copy link
Owner

malthe commented Jan 17, 2024

We should move away from pycodestyle (used by Flake8) which has some inherent design limitations such as not being able to qualify an analysis outside of the current syntax unit, see for example PyCQA/pycodestyle#703.

@malthe
Copy link
Owner Author

malthe commented Jan 17, 2024

@icemac do you know about an alternative?

@Daverball
Copy link
Contributor

@malthe Have you had a look at flake8-bugbear and some of the other flake8 plugins out there? I find flake8 with some plugins + static analysis through a type checker is usually sufficient to catch most of the things you'd want to be able to catch.

I found that pylint usually goes too much in the other direction. But you could also check out ruff, which re-implements most of the rules from a variety of popular linters in Rust (as well as with the extended ability to auto-fix some of them), which would let you hand pick from a greater variety of rules without having to install dozens of different tools/plugins.

Can you give some examples of rules you're missing or where the rate of false positive/negatives is too high, besides the bare except case?

@Daverball
Copy link
Contributor

On the note of tooling, have you considered adding pre-commit? I use it pretty much in all my projects now and it's saved me a lot of headaches. It's really easy to forget to run one of the tox environments, such as type checking or linting, because you were focused on fixing a test or vice versa, so pre-commit helps to save you from yourself.

@malthe
Copy link
Owner Author

malthe commented Jan 18, 2024

A rule that I'm missing is that bare except is okay on re-raise. Flake8 can't do that because it can't look ahead!

@Daverball
Copy link
Contributor

@malthe flake8-bugbear is an AST plugin, so you probably could implement that exception to the rule fairly easily and contribute it.

Generally you can achieve a lot with plugins, the reason why pycodestyle isn't as powerful is because it just looks at the source code directly, rather than the AST, but flake8 plugins are free to either use AST or source code lines, so it's not a limitation with flake8 in general.

@icemac
Copy link
Contributor

icemac commented Jan 19, 2024

I'd also suggest ruff, even though I've only used it once.
But I tried the bare-except issue and it does not complain in contrast to flake8.

I did:

try:
    1/0
except:
    print('error')
    raise
  • ruff does not return anything, meaning all good
  • flake8says: E722 do not use bare 'except'

@fschulze
Copy link
Contributor

I would also suggest ruff. I use --select=ALL and then a bunch of ignores for things I don't like or care about. See https://github.com/fschulze/devpi/blob/server612/ruff-strict.toml. I also have ignored a bunch of existing errors, but use match-diff-lines to error when changes are made: https://github.com/fschulze/devpi/blob/server612/.ci/lint-strict.sh

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

No branches or pull requests

4 participants