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

Ruff runs all pydocstyle rules when the convention is specified in the config toml files #3684

Closed
felix-cw opened this issue Mar 23, 2023 · 8 comments · Fixed by #3685
Closed
Assignees
Labels
bug Something isn't working

Comments

@felix-cw
Copy link
Contributor

This behaviour is new in 0.0.258

When running ruff with the --select option in a folder with a pyproject.toml or ruff.toml which specifies the pydocstyle convention,
ruff always runs all the pydocstyle rules.

Example:

# I want to check for unsorted imports
ruff check ruff_doc.py --select=I

ruff_doc.py

"""Useful mathematical functions."""


def add_numbers(number1, number2):
    """Add 2 numbers.

    Args:
        number1 (Number): first number
        number2 (Number): second number

    Returns:
        Number: result of addition
    """
    return number1 + number2

pyproject.toml

[tool.ruff.pydocstyle]
convention = "google"

The result is

ruff_doc.py:5:5: D213 [*] Multi-line docstring summary should start at the second line
ruff_doc.py:5:5: D407 [*] Missing dashed underline after section ("Args")
ruff_doc.py:5:5: D407 [*] Missing dashed underline after section ("Returns")

I do not expect any output, as I didn't select D in my command, and these error codes should be turned off in the google convention.

This behaviour is particularly bad in e.g. VSCode with the organize imports functionality, as it also tries to fix all docstring issues in all the conventions, which results in more errors.

@JonathanPlasse
Copy link
Contributor

convention enables the D rules corresponding to it implicitly. You should not set conventionif you do not want to check the D rules.

For vscode, you should check you are not using fix all in your configuration.

@felix-cw
Copy link
Contributor Author

I am getting errors for rules D213 and D407, which are not included in the google convention per http://www.pydocstyle.org/en/stable/error_codes.html#default-conventions

Furthermore I am using --select=I but the 'D' rules are getting enabled as well. If I set convention, does that mean there is no way to prevent 'D' rules from being checked?

@charliermarsh
Copy link
Member

This seems like a bug.

@charliermarsh charliermarsh self-assigned this Mar 23, 2023
@charliermarsh
Copy link
Member

Lemme look into it.

@charliermarsh charliermarsh added the bug Something isn't working label Mar 23, 2023
@charliermarsh
Copy link
Member

@MichaReiser - In case the bug here is obvious to you, it looks like this diff prevents us from accidentally enabling the pydocstyle rules:

diff --git a/crates/ruff/src/settings/mod.rs b/crates/ruff/src/settings/mod.rs
index 1fb944959..df3d11765 100644
--- a/crates/ruff/src/settings/mod.rs
+++ b/crates/ruff/src/settings/mod.rs
@@ -386,7 +386,9 @@ impl From<&Configuration> for RuleTable {
             .and_then(|pydocstyle| pydocstyle.convention)
         {
             for rule in convention.rules_to_be_ignored() {
-                rules.disable(*rule);
+                if rules.enabled(*rule) {
+                    rules.disable(*rule);
+                }
             }
         }

@charliermarsh
Copy link
Member

(In other words, calling disable on a rule that's not currently enabled seems to enable it.)

@janosh
Copy link

janosh commented Mar 23, 2023

This is definitely a bug since setting pydocstyle.convention in pyproject.toml even overrides CLI flags.

ruff --version                 
    ruff 0.0.257
ruff check . --ignore D | wc -l
       0

pip install ruff==0.0.258 && ruff check . --ignore D | wc -l
    19446

@charliermarsh
Copy link
Member

Yeah I've confirmed that it's a regression. I'll ship a fix today.

@MichaReiser MichaReiser linked a pull request Mar 23, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants