-
Notifications
You must be signed in to change notification settings - Fork 1.6k
apply range suppressions to filter diagnostics #21623
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
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add some tests now. check_path is called from our testing framework, meaning we should now be able to write a test similar to
ruff/crates/ruff_linter/src/rules/ruff/mod.rs
Lines 294 to 305 in 850398d
| #[test] | |
| fn noqa() -> Result<()> { | |
| let diagnostics = test_path( | |
| Path::new("ruff/noqa.py"), | |
| &settings::LinterSettings::for_rules(vec![ | |
| Rule::UnusedVariable, | |
| Rule::AmbiguousVariableName, | |
| ]), | |
| )?; | |
| assert_diagnostics!(diagnostics); | |
| Ok(()) | |
| } |
This could also be used as a replacement for some of the tests I asked for in your previous PR.
I also suggest adding some CLI tests verifying that this PR doesn't break in combination with --add-noqa, --remove-noqa --ignore-noqa etc.
850398d to
2ff32de
Compare
ce14617 to
607325e
Compare
Is there an existing set of CLI tests for noqa that I can use as an example here? |
2ff32de to
1586572
Compare
There are some here ruff/crates/ruff/tests/cli/lint.rs Line 1444 in 81f6ec1
I couldn't find any for |
MichaReiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. But we should look into the performance regression before landing this PR (can be fixed as a separate PR but we can't land this until we fixed the regression)
crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py
Outdated
Show resolved
Hide resolved
|
Note: add |
ea5b48d to
288d431
Compare
1586572 to
5ebadd4
Compare
| let test_code = | ||
| fs::read_to_string(fixture.root().join("noqa.py")).expect("should read test file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid reading fixture files in CLI tests as it makes the tests depend on each other and it can also become harder to reason about what we're testing here. Would it be possible to extract the specific case you want to test from noqa.py?
The tests here also don't need to be exhaustive. We can add more exhaustive tests to add_noqa (I think we have some integration tests, right?)
| let suppressions = if is_range_suppressions_enabled(settings) { | ||
| Suppressions::from_tokens(locator.contents(), parsed.tokens()) | ||
| } else { | ||
| Suppressions::default() | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now end up extracting the suppressions twice: Once in check_path and once here. We might need to pass the suppressions as part of check_path
| let exemption = FileExemption::from(&file_directives); | ||
| let directives = NoqaDirectives::from_commented_ranges(comment_ranges, external, path, locator); | ||
| let comments = find_noqa_comments(diagnostics, locator, &exemption, &directives, noqa_line_for); | ||
| // This is called by ruff_server, which already filtered diagnostics via check_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also call this function from our tests. Would it make sense to lift Suppressions out of generate_noqa_edits and instead require the caller to pass the suppressions?
| ]) | ||
| .with_preview_mode(), | ||
| )?; | ||
| assert_diagnostics!(diagnostics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a good case for assert_diagnostics_diff which snapshots the difference between two settings: E.g. between preview on and off
Builds on range suppressions from #21441
Filters diagnostics based on parsed valid range suppressions.
Issue: #3711