Open github-actions[bot] opened 4 months ago
Linting and formatting are related yet different tasks. I found it hard to explain the difference, so asked ChatGPT, and it gave a great answer:
In Python (and other programming languages), formatting and linting are related to code quality and style, but they serve different purposes:
Formatting refers to the process of arranging and styling code according to specific rules or conventions. This includes things like indentation, spacing, line length, and other stylistic choices that make code easier to read and maintain. Formatting tools automatically adjust your code to meet these conventions.
Examples of formatting tasks:
Popular formatting tools in Python:
Linting refers to the process of analyzing code to identify potential errors, bugs, stylistic errors, or other problematic patterns. Linters provide feedback on code quality, adherence to best practices, and can catch potential bugs before the code is run.
Examples of linting tasks:
Popular linting tools in Python:
Both formatting and linting are essential for maintaining high-quality, readable, and reliable code.
It is helpful for reviewers/contributors if you adhere to a standard python style guide. There is a package called ruff that can help you fix up your code to adhere to these.
Install ruff using
pip install ruff
and then you can runruff format
to automatically format your files against their (black standards, which is aligned with the the most common formatting standards (called black).You can also run
ruff check
to help you lint the files.