-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add rules
table to configuration
#15645
Conversation
@@ -128,6 +150,23 @@ impl Project { | |||
Arc::into_inner(result).unwrap().into_inner().unwrap() | |||
} | |||
|
|||
pub(crate) fn check_file(self, db: &dyn Db, file: File) -> Vec<Box<dyn Diagnostic>> { |
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 included the rule diagnostics in check_file
because an API consumer (e.g., the LSP) can decide only to call check_file
but never project.check
and would never see the diagnostics.
The counter-argument is that these diagnostics aren't related to file
so they shouldn't be shown.
I'm not sure what the right answer is, but I defaulted to including them for now.
|
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.
Sweet!
54ca21c
to
af3bbde
Compare
0bf7453
to
3a4b7f0
Compare
* main: [red-knot] MDTests: Do not depend on precise public-symbol type inference (#15691) [red-knot] Make `infer.rs` unit tests independent of public symbol inference (#15690) Tidy knot CLI tests (#15685) [red-knot] Port comprehension tests to Markdown (#15688) Create Unknown rule diagnostics with a source range (#15648) [red-knot] Port 'deferred annotations' unit tests to Markdown (#15686) [red-knot] Support custom typeshed Markdown tests (#15683) Don't run the linter ecosystem check on PRs that only touch red-knot crates (#15687) Add `rules` table to configuration (#15645) [red-knot] Make `Diagnostic::file` optional (#15640) [red-knot] Add test for nested attribute access (#15684) [red-knot] Anchor relative paths in configurations (#15634) [`pyupgrade`] Handle multiple base classes for PEP 695 generics (`UP046`) (#15659) [`pyflakes`] Treat arguments passed to the `default=` parameter of `TypeVar` as type expressions (`F821`) (#15679) Upgrade zizmor to the latest version in CI (#15649) [`pyupgrade`] Add rules to use PEP 695 generics in classes and functions (`UP046`, `UP047`) (#15565) [red-knot] Ensure a gradual type can always be assigned to itself (#15675)
Summary
This PR adds support for enabling or disabling a rule or change its severity to warning by using a configuration file.
This PR doesn't yet add support for the
rule = { severity="level" }
format simply because we don't support any per-rule configurations other thanseverity
just yet (like fixability). We should add support once for a sub-table once we add support for it. This PR also does not yet add support for configuring rules over the CLI.The "hardest" part of this PR was to make the diagnostics propagate. The approach
I've taken for now is to simply collect them when calling
project.check
orproject.check_file
.I don't love this approach because it's somewhat easy to get wrong and we have to repeat it in
every entry function that may return diagnostics (e.g.
format
?). However,we currently only exactly have two, so it sort of feels okay?
I considered using salsa accumulators but doing so wouldn't solve
the problem that we have to remember collecting the diagnostics
in the
project.check
call, but we could use them if we want,performance isn't as much of a concern here.
Overall I felt like defering the ideal design until we have
more settings that require validation to get a better sense of
how awkward (or good) the current design is.
The diagnostics for unknown rules currently lack any source information. I plan on adding proper spans in a follow-up PR because it requires some machinery to funnel the spans through serde.
CC @BurntSushi: I don't consider the "how we funnel diagnostics through red knot" as the main focus of your diagnostics work but I thought this might still be interesting to you.
Part of #15491
Test Plan
Added CLI tests.