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

Add missing tool.ruff in configuration documentation. #2643

Closed
wants to merge 1 commit into from

Conversation

Chris-May
Copy link
Contributor

The documentation includes a configuration example that shows one can configure ruff's per-file ignore patterns by adding the following section to pyproject.toml:

# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
[per-file-ignores]
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]

It should be [tool.ruff.per-file-ignores]

This one caused me a few hours of issues, so I decided to contribute a fix.

@charliermarsh
Copy link
Member

Confusingly, this is actually correct, because that section is talking about ruff.toml (see For example, the pyproject.tomldescribed above would be represented via the followingruff.toml...) in the paragraph leading up to it.

If you scroll up in the docs, you'll see that we do include the pyproject.toml version in full:

[tool.ruff]
# Enable flake8-bugbear (`B`) rules.
select = ["E", "F", "B"]

# Never enforce `E501` (line length violations).
ignore = ["E501"]

# Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
[tool.ruff.per-file-ignores]
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]

I'll try to make this clearer. I'm really sorry that you lost time to it.

@Chris-May
Copy link
Contributor Author

Ah! Thanks for the clarity!!!

I remember reading about the ruff.toml file, but when I was scanning the documentation, those sections ran together.

Would you want to make that more explicit? I can think of two options:

  1. Add a subheading
#### Configure via `ruff.toml`

As an alternative to pyproject.toml, Ruff will also respect a ruff.toml file, which implements an equivalent schema (though the [tool.ruff] hierarchy can be omitted). For example, the pyproject.toml described above would be represented via the following ruff.toml:

# Enable flake8-bugbear (`B`) rules.
select = ["E", "F", "B"]

# Never enforce `E501` (line length violations).
ignore = ["E501"]

# Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
[per-file-ignores]
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
  1. Add a comment:

As an alternative to pyproject.toml, Ruff will also respect a ruff.toml file, which implements an equivalent schema (though the [tool.ruff] hierarchy can be omitted). For example, the pyproject.toml described above would be represented via the following ruff.toml:

# In ruff.toml

# Enable flake8-bugbear (`B`) rules.
select = ["E", "F", "B"]

# Never enforce `E501` (line length violations).
ignore = ["E501"]

# Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
[per-file-ignores]
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]

Additionally, the intro paragraph to the section mentions that there are two ways to configure ruff, those being pyproject.toml and the command line. It seems like the ruff.toml would be a third.

If you're open to it, I'd be happy to update this PR with an option. Otherwise, I can happily let you focus on more pressing topics. 😃

@charliermarsh
Copy link
Member

charliermarsh commented Feb 8, 2023

That'd be great! I'd be happy with Option 1 (and adding ruff.toml to the intro paragraph).

charliermarsh pushed a commit that referenced this pull request Feb 14, 2023
This completes the word from the discussion in #2643, adding headers to clarify the `pyproject.toml` and `ruff.toml` sections.
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.

None yet

2 participants