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

[tool.ruff.lint.flake8-tidy-imports] rules in pyproject.toml parent are ignore pyproject.toml child file #14822

Open
FrancoisMasson1990 opened this issue Dec 6, 2024 · 5 comments
Labels
configuration Related to settings and configuration

Comments

@FrancoisMasson1990
Copy link

Rules present in pyproject.toml parent file are ignored in the child file one.

Example given

./pyproject.toml

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"typing.List".msg = "Use list instead of typing.List"
"typing.Dict".msg = "Use dict instead of typing.Dict"

./folder_a/pyproject.toml

[tool.ruff]
# Extend the `pyproject.toml` file in the parent directory.
extend = "../pyproject.toml"

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"B".msg = "Don't import B in A"

Typing check are not considered when running poetry ruff check . in the folder_a

@MichaReiser
Copy link
Member

Typing check are not considered when running poetry ruff check . in the folder_a

Can you expand on what you mean and maybe share an example python file? That would help me reproduce the issue and, in turn, help you.

@MichaReiser MichaReiser added question Asking for support or clarification needs-mre Needs more information for reproduction labels Dec 6, 2024
@FrancoisMasson1990
Copy link
Author

Typing check are not considered when running poetry ruff check . in the folder_a

Can you expand on what you mean and maybe share an example python file? That would help me reproduce the issue and, in turn, help you.

Sure.

in the following folder structure

|
|
pyproject.toml
folder-a
    |-folder_a
        |--- __init__.py
        |--- test.py
   |-pyproject.toml

test.py

from typing import List

Using the following configuration

./pyproject.toml

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"typing.List".msg = "Use list instead of typing.List"
"typing.Dict".msg = "Use dict instead of typing.Dict"

And

./folder_a/pyproject.toml

[tool.ruff]
# Extend the `pyproject.toml` file in the parent directory.
extend = "../pyproject.toml"

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"B".msg = "Don't import B in A"

The error on importing List is ignored.

Note that if [tool.ruff.lint.flake8-tidy-imports.banned-api] rules are missing in ./folder_a/pyproject.toml. (No "B".msg = "Don't import B in A" for example) The error is flagged.

Let me know if it's clearer with the following explanation.

@dhruvmanila
Copy link
Member

I think this is an expected behavior because the banned-api value in the nested pyproject.toml will override the one in the parent pyproject.toml. The extend option is to merge the properties from different configuration files.

@FrancoisMasson1990
Copy link
Author

I think this is an expected behavior because the banned-api value in the nested pyproject.toml will override the one in the parent pyproject.toml. The extend option is to merge the properties from different configuration files.

Ok but is there a way in that case to merge the banned-api from different configuration file ?

We want to avoid duplicated rules accross different configuration files.
Example given:
"typing.List".msg = "Use list instead of typing.List"

Should be present in only config file and spread accross various sub_folder

@MichaReiser MichaReiser added configuration Related to settings and configuration and removed question Asking for support or clarification needs-mre Needs more information for reproduction labels Dec 9, 2024
@MichaReiser
Copy link
Member

MichaReiser commented Dec 9, 2024

Ok but is there a way in that case to merge the banned-api from different configuration file ?

I don't think that's currently possible, and we're aware of this limitation in Ruff's current configuration schema. The problem is that merging the options now makes it impossible to override the banned-apis if there's a need for it.

The solution to this is that we introduce a new sentinel value: "unset" or add a "level" setting to it that can be "ignore", "warn" or "error" so that a sub-configuration can remove (disable) a previous banned api override

This is related to #9872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration
Projects
None yet
Development

No branches or pull requests

3 participants