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

Update examples to format first #66

Closed
wants to merge 1 commit into from

Conversation

nicoddemus
Copy link

@nicoddemus nicoddemus commented Jan 31, 2024

It makes more sense to run ruff formatter fist, as formatting might change the line numbers, which affect the lines reported by the linter.

This is very noticeable when running ruff for the first time on a large number of files, as the formatter will change several lines.

It makes more sense to run `ruff` formatter fist, as formatting might change the line numbers, which affect the lines reported by the linter.

This is very noticeable when running `ruff` for the first time on a large number of files, as the formatter will change several lines.
@charliermarsh
Copy link
Member

That's a good observation! Though the existing order is fairly intentional. Our linter-formatter compatibility contract is such that running the formatter should not introduce new lint errors -- so if you format after linting (and you haven't enabled any conflicting rules), you should be guaranteed that linting again doesn't yield any new violations.

The inverse is not true. If you run the formatter, then linter with --fix, you might need to format again, since the linter can output code changes that don't adhere to the formatter's code style. So, in general, if you switch the order like this, you can run into a situation where the code is formatted, then fixed (with no remaining lint errors), but then needs to be formatted again.

The formatter-linter compatibility docs are here, and the pre-commit setup is documented here.

@nicoddemus
Copy link
Author

I see, thanks for the detailed explanation!

Closing this then. 👍

@nicoddemus nicoddemus closed this Jan 31, 2024
@nicoddemus nicoddemus deleted the patch-1 branch January 31, 2024 23:48
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.

2 participants