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

Fix docs and add overlap test for negated per-file-ignores #10863

Merged
merged 4 commits into from
Apr 12, 2024
Merged

Conversation

carljm
Copy link
Contributor

@carljm carljm commented Apr 10, 2024

Refs #3172

Summary

Fix a typo in the docs example, and add a test for the case where a negative pattern and a positive pattern overlap.

The behavior here is simple: patterns (positive or negative) are always additive if they hit (i.e. match for a positive pattern, don't match for a negated pattern). We never "un-ignore" previously-ignored rules based on a pattern (positive or negative) failing to hit.

It's simple enough that I don't really see other cases we need to add tests for (the tests we have cover all branches in the ignores_from_path function that implements the core logic), but open to reviewer feedback.

I also didn't end up changing the docs to explain this more, because I think they are accurate as written and don't wrongly imply any more complex behavior. Open to reviewer feedback on this as well!

After some discussion, I think allowing negative patterns to un-ignore rules is too confusing and easy to get wrong; if we need that, we should add per-file-selects instead.

Test Plan

Test/docs only change; tests pass, docs render and look right.

@carljm carljm added the internal An internal refactor or improvement label Apr 10, 2024
@carljm carljm requested a review from BurntSushi April 10, 2024 18:23
Copy link
Contributor

github-actions bot commented Apr 10, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@carljm carljm mentioned this pull request Apr 10, 2024
@carljm carljm changed the title Add test and fix doc for negated per-file-ignores Allow negated per-file-ignore patterns to un-ignore rules Apr 11, 2024
@carljm carljm changed the title Allow negated per-file-ignore patterns to un-ignore rules Fix docs and add overlap test for negated per-file-ignores Apr 11, 2024
@carljm
Copy link
Contributor Author

carljm commented Apr 12, 2024

Going to go ahead and merge this without further review; we should get the doc fix out, and this is just a minor doc fix and a test that passes.

This doesn't preclude revisiting the behavior of negated patterns, but that can be another PR.

@carljm carljm merged commit 563daa8 into main Apr 12, 2024
17 checks passed
@carljm carljm deleted the cjm/select2 branch April 12, 2024 01:30
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.

👍 Good call, sorry for the delay.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

LGTM

Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 12, 2024
…#10863)

Refs astral-sh#3172 

## Summary

Fix a typo in the docs example, and add a test for the case where a
negative pattern and a positive pattern overlap.

The behavior here is simple: patterns (positive or negative) are always
additive if they hit (i.e. match for a positive pattern, don't match for
a negated pattern). We never "un-ignore" previously-ignored rules based
on a pattern (positive or negative) failing to hit.

It's simple enough that I don't really see other cases we need to add
tests for (the tests we have cover all branches in the ignores_from_path
function that implements the core logic), but open to reviewer feedback.

I also didn't end up changing the docs to explain this more, because I
think they are accurate as written and don't wrongly imply any more
complex behavior. Open to reviewer feedback on this as well!

After some discussion, I think allowing negative patterns to un-ignore
rules is too confusing and easy to get wrong; if we need that, we should
add `per-file-selects` instead.

## Test Plan

Test/docs only change; tests pass, docs render and look right.

---------

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants