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

Avoid invalid combination of force-sort-within-types and lines-between-types #9041

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

charliermarsh
Copy link
Member

Closes #8792.

@charliermarsh charliermarsh added bug Something isn't working isort Related to import sorting labels Dec 7, 2023
@charliermarsh charliermarsh marked this pull request as ready for review December 7, 2023 03:57
Copy link
Contributor

github-actions bot commented Dec 7, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@@ -2109,6 +2109,21 @@ impl IsortOptions {
warn_user_once!("`sections` is ignored when `no-sections` is set to `true`");
}

// Verify that if `force_sort_within_sections` is `True`, then `lines_between_types` is set to `0`.
let force_sort_within_sections = self.force_sort_within_sections.unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we warn in the settings instead? Invalid configurations are otherwise still possible when using extend.

It may also be worth to aborting in that case to prevent that we change a large set of files because we ignored the setting.

Copy link
Member Author

Choose a reason for hiding this comment

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

We already ignore this in the underlying implementation, and warning here is consistent with the other validation in this method. If we want to warn on Settings, I think that would be a separate change.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, the formatter validations are done inside of settings to avoid these inconsistencies.

I think validating in settings only is sufficient. Only validating in options has the downside that we might ignore the option without a warning if one isort options comes from the extended configuration

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, the formatter validations are done inside of settings to avoid these inconsistencies.

I think validating in settings only is sufficient. Only validating in options has the downside that we might ignore the option without a warning if one isort options comes from the extended configuration

@charliermarsh charliermarsh merged commit ebc7ac3 into main Dec 7, 2023
17 checks passed
@charliermarsh charliermarsh deleted the charlie/force-sort branch December 7, 2023 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working isort Related to import sorting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[isort] force-sort-within-sections and lines-between-types should probably be incompatible
2 participants