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

Allow overriding pydocstyle convention rules #8586

Merged
merged 8 commits into from
Nov 10, 2023

Conversation

alanhdu
Copy link
Contributor

@alanhdu alanhdu commented Nov 9, 2023

Summary

This fixes #2606 by moving where we apply the convention ignores -- instead of applying that at the very end, e track, we now track which rules have been specifically enabled (via Specificity::Rule). If they have, then we do not apply the docstring overrides at the end.

Test Plan

Added unit tests to ruff_workspace and an integration test to ruff_cli

Copy link
Contributor

github-actions bot commented Nov 9, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh
Copy link
Member

This looks good to me, thanks for putting it together! I'd suggest adding a test or two to crates/ruff_cli/tests/integration_test.rs which can roughly mirror the way you tested it on the CLI, but with snapshot testing.

@charliermarsh charliermarsh self-requested a review November 10, 2023 01:38
@charliermarsh charliermarsh added bug Something isn't working docstring Related to docstring linting or formatting labels Nov 10, 2023
@charliermarsh
Copy link
Member

(I think the implementation is fine. We already special-case conventions here, so I don't mind tracking a bit of extra state for it.)

@@ -780,6 +791,8 @@ impl LintConfiguration {
{
carryover_ignores = Some(&selection.ignore);
}

docstring_overrides = docstring_override_updates;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be fine to omit docstring_override_updates and just add to docstring_overrides whenever we see a direct selector. In other words, I don't know if this "reset" behavior is important for the purpose of these overrides. I'm trying to think of a case where this would matter.

As an example of why this exists (to the best of my memory): imagine you have select=D and ignore=D401 in your configuration file. If you then pass --select D4, we want to ignore the ignore. So we treat a --select as resetting the selection chain.

Eh, thinking about it further, what you have here is probably right. Imagine you have select=D415 in your configuration file, and then you run with --select=D. We probably still want to enforce the configuration override for D415 in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I was actually thinking about this in terms of having multiple ruff.tomls (e.g. in a monorepo or something). In that case, I think the intended behavior is that select "clears" the state of the "parent" ruff.tomls, and personally I think it'd be confusing if the docstring conventions were the only counter-example to that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@alanhdu alanhdu marked this pull request as ready for review November 10, 2023 14:24
@alanhdu
Copy link
Contributor Author

alanhdu commented Nov 10, 2023

Alright! Added some unit tests and an integration test, so this should be ready for review!

Copy link

codspeed-hq bot commented Nov 10, 2023

CodSpeed Performance Report

Merging #8586 will not alter performance

Comparing alanhdu:alan/override (e18d884) with main (a7dbe9d)

Summary

✅ 25 untouched benchmarks

success: false
exit_code: 1
----- stdout -----
-:2:5: D417 Missing argument description in the docstring for `log`: `base`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, D417 was the rule I was surprised was disabled in the numpy convention. It looks like there's specific code written to handle some of the quirks (e.g.

// Notably, NumPy lets you put multiple parameters of the same type on the same
), so it seemed odd that it was disabled.

/// As conventions force-disable all rules not included in the convention,
/// enabling _additional_ rules on top of a convention is currently
/// unsupported.
/// If you must, you can enable rules not included in a convention by
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another place I should update the docs, or is this the right place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right place :)

"#;

// If we only select the prefix, then everything passes
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I found some of this to be a bit repetitive -- would you be open to a PR that tries to refactor some of this Command construction into a custom builder struct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm open to the idea!

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great -- thanks for taking it on!

@charliermarsh charliermarsh enabled auto-merge (squash) November 10, 2023 18:42
@charliermarsh
Copy link
Member

Appreciate all the tests, thanks for following up there.

@charliermarsh charliermarsh merged commit 5a1a8be into astral-sh:main Nov 10, 2023
16 checks passed
@alanhdu alanhdu deleted the alan/override branch November 10, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docstring Related to docstring linting or formatting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow explicit select of docstring rule to override configured convention
2 participants