Programmers often leave comments to themselves and others such as:
# TODO: Use a faster algorithm?
The keywords used to prefix such comments are just a convention and vary
from project to project. Other common keywords include FIXME and HACK.
The keywords in use for the codebase are of interest to ruff because
ruff does also lint comments. For example the ERA lint detects
commented-out code but ignores comments starting with such a keyword.
Previously the ERA lint simply hardcoded the regular expression
TODO|FIXME|XXX to achieve that. This commit introduces a new `task-tags`
setting to make this configurable (and to allow other comment lints to
recognize the same set of keywords).
The term "task tags" has probably been popularized by the Eclipse
IDE.[1] For Python there has been the proposal PEP 350[2], which
referred to such keywords as "codetags". That proposal however has been
rejected. We are choosing the term "task tags" over "code tags" because
the former is more descriptive: a task tag describes a task.
While according to the PEP 350 such keywords are also sometimes used for
non-tasks e.g. NOBUG to describe a well-known problem that will never be
addressed due to design problems or domain limitations, such keywords
are so rare that we are neglecting them here in favor of more
descriptive terminology. The vast majority of such keywords does
describe tasks, so naming the setting "task-tags" is apt.
[1]: https://www.eclipse.org/pdt/help/html/task_tags.htm
[2]: https://peps.python.org/pep-0350/
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
flake8-to-ruff
Convert existing Flake8 configuration files (setup.cfg, tox.ini, or .flake8) for use with
Ruff.
Generates a Ruff-compatible pyproject.toml section.
Installation and Usage
Installation
Available as flake8-to-ruff on PyPI:
pip install flake8-to-ruff
Usage
To run flake8-to-ruff:
flake8-to-ruff path/to/setup.cfg
flake8-to-ruff path/to/tox.ini
flake8-to-ruff path/to/.flake8
flake8-to-ruff will print the relevant pyproject.toml sections to standard output, like so:
[tool.ruff]
exclude = [
'.svn',
'CVS',
'.bzr',
'.hg',
'.git',
'__pycache__',
'.tox',
'.idea',
'.mypy_cache',
'.venv',
'node_modules',
'_state_machine.py',
'test_fstring.py',
'bad_coding2.py',
'badsyntax_*.py',
]
select = [
'A',
'E',
'F',
'Q',
]
ignore = []
[tool.ruff.flake8-quotes]
inline-quotes = 'single'
[tool.ruff.pep8-naming]
ignore-names = [
'foo',
'bar',
]
Plugins
flake8-to-ruff will attempt to infer any activated plugins based on the settings provided in your
configuration file.
For example, if your .flake8 file includes a docstring-convention property, flake8-to-ruff
will enable the appropriate flake8-docstrings
checks.
Alternatively, you can manually specify plugins on the command-line:
flake8-to-ruff path/to/.flake8 --plugin flake8-builtins --plugin flake8-quotes
Limitations
- Ruff only supports a subset of the Flake configuration options.
flake8-to-ruffwill warn on and ignore unsupported options in the.flake8file (or equivalent). (Similarly, Ruff has a few configuration options that don't exist in Flake8.) - Ruff will omit any error codes that are unimplemented or unsupported by Ruff, including error codes from unsupported plugins. (See the Ruff README for the complete list of supported plugins.)
License
MIT
Contributing
Contributions are welcome and hugely appreciated. To get started, check out the contributing guidelines.