-
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
Feature request: Support a "warning" level for linting #1256
Comments
Yeah, this would be nice to have. It would also be helpful for editor integrations, since the LSP can differentiate between warnings and errors. |
Any thoughts on what the API should look like? ESLint lets you map from rule name to level, like:
Which makes sense, though they also use that system to turn errors on and off -- and we instead have the Flake8-like The most basic thing would be a map from check code prefix to level, like: [tool.ruff.severity]
"F401" = "warning"
"F481" = "error"
# Probably also want to support prefixes.
"E" = "warning" |
Not really sure... Naively, it appears to me that the most consistent way to configure it would be to have This file contains what I'm doing currently for the project that inspired this request. I enabled more linting than we previously had (everything I viewed as potentially appropriate for this app), but I put everything that raised an error into the ignore field. With this feature, lines 78-102 would've been in a |
fwiw |
I would recommend against the implementation of warning (or severity levels). I wrote about why in this blog post (and also in a In my opinion, it's one of those features (along with disable comments) that gets copied over and over mostly because other linters have them. The fact that no linter docs ever recommend when to use these features is a sign of that in my opinion. I can potentially see a benefit for this while seeing the errors in an editor, but it shouldn't IMO impact the behavior of the linter. In
This is exactly the kind of problem that the proposal in #1149 aims to solve, and is a much better solution. |
How would the editor show the proper type of diagnostic to the user if the linter doesn't provide that information? |
If by "type of diagnostic" you mean warning or error, it wouldn't be able to. I meant to say that this feature request could be useful for editors for that purpose. But that otherwise severity levels is not useful or recommended. |
@jfmengels while what you mention would be ideal, I don't believe it's practical for ruff. Disable commentsLet's take for example a project that has its own With disable comments, this is straightforward. Simply write a comment like Without disable comments, a developer is left with a host of options, none of them good. Do we disable the rule? That seems drastic, especially since it's a rule that's widely accepted, so we may well want to apply it to the rest of our code. Even with fine-grained rule configuration, we're left with only the inferior choice of having to disable it for the whole file. Now, it's quite a reasonable response to say that the linter should handle this case. And sure, I agree in principle. It would be a better outcome if the linter understood that I'm overriding a parent method and didn't yell at me about it. Of course, it's not like this is the only example of a rule that might need changing - or indeed of one that we might want to disable or modify in specific cases. Perhaps we need to Perhaps elm as a language doesn't have this. I'm not familiar enough with it to say. But that's a fact of life in the Python world, and a linting tool isn't going to have a way around it in all cases. In the end, that's something we have to deal with. Severity levels
Thank youThat's not to say that your post wasn't without inspiration for me. To start, I think having certain rules ignore noqa commets is a great idea, and this could be implemented with only a small tweak to my feature request. A "critical" level would be great for allowing a project maintainer to prevent certain rules from being disabled. I'd imagine rules like F401 (unused import), F631/631 (assert/if is always true) and E999 (syntax error) could even be made critical by default. With that, explanations for noqa comments and the already-extant |
@not-my-profile - I'm considering adding this, but since you've been working on the violation API a lot, I wanted to get your feedback first. Here's a proposal.
This wouldn't include making it possible to run Ruff and only show warnings, or only show errors (e.g., |
Thanks for consulting with me :) I would hold off on adding any such constants to the
LSP also supports other levels:
I think it might make more sense to support all of them via a configuration like: [tool.ruff.severities]
B = "information"
I don't think we should overload rule selectors for this. I think I'd prefer a dedicated CLI option like |
Of course! You're driving a lot of the work on the violations API. Definitely want your help figuring these parts out :)
Yeah I've considered this... I wasn't sure if they would really be relevant to us. Like Clippy only has allow, warn, deny, and none. I'm not sold either way.
Makes sense -- just an example to articulate what I wasn't planning to do on the first pass. I agree that the API you're suggesting is better. |
I am not sure either. I still think a config like: [tool.ruff.severities]
B = "warning" is better than [tool.ruff]
warning = ["B"] because the former is more expressive, e.g. [tool.ruff.severities]
B = "warning"
B007 = "error"
These are not defined by clippy ... these are the rustc lint levels:
But what you're saying makes sense ... I think it makes sense to start out with just supporting "warning" & "error". Actually I think we probably should rather model this after clippy since I think it would probably make sense for us to also support "force-warn" and "forbid" (which basically is "force-deny"). So we could have: [tool.ruff.levels]
B = "warn"
B007 = "deny" We could actually also deprecate our [tool.ruff.levels]
E501 = "allow" The nice thing about the Rust terminology is that "allow" and "deny" are semantic opposites (while "ignore" and "error" aren't). |
Yeah I generally agree. My only hesitation around modeling this after Clippy is that the API will be new to most users, whereas But... it'd be nice to have a unified API for turning errors "on" and "off", and for setting their severities, as with Clippy. (E.g., if we add |
I have two main uses for setting a linter rule as warning:
|
I'd really like this to support more than just "error" and "warning". While discussion in this issue is mostly about editor, ruff is also used in CI and CI apps also use severities. Gitlab defines 5 and none of them is Approach proposed by @not-my-profile would make it possible to handle - if severity list is extended or free form supported. Why such granularity may be useful in CI? |
https://beta.ruff.rs/docs/ https://github.com/charliermarsh/ruff Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too. Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later. Existing related Ruff requests (nothing here is a blocker, just future improvements): - astral-sh/ruff#1256 - astral-sh/ruff#3011 - astral-sh/ruff#3072 - astral-sh/ruff#3910 - astral-sh/ruff#2419 - astral-sh/ruff#3115 - astral-sh/ruff#1904
https://beta.ruff.rs/docs/ https://github.com/charliermarsh/ruff Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too. Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later. Existing related Ruff requests (nothing here is a blocker, just future improvements): - astral-sh/ruff#1256 - astral-sh/ruff#3011 - astral-sh/ruff#3072 - astral-sh/ruff#3910 - astral-sh/ruff#2419 - astral-sh/ruff#3115 - astral-sh/ruff#1904
https://beta.ruff.rs/docs/ https://github.com/charliermarsh/ruff Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too. Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later. Existing related Ruff requests (nothing here is a blocker, just future improvements): - astral-sh/ruff#1256 - astral-sh/ruff#3011 - astral-sh/ruff#3072 - astral-sh/ruff#3910 - astral-sh/ruff#2419 - astral-sh/ruff#3115 - astral-sh/ruff#1904
Any progress here or when we think this will go into a version? |
If user configuration of lint levels is desired, I think it could be reasonable to follow the design specified in Rust's select = ["E", "F", "B"]
[lints]
E123 = "warn"
F456 = { level = "error", priority = 100 } (priority probably isn't really required). Naming the table something like [lints.E123]
option-a = "syrup"
ignore = "**/pancakes.py"
# would fix https://github.com/astral-sh/ruff/issues/1992#issuecomment-1405497643
autofix = "never" |
ruff doesn't really implement severities by itself [1], and one could argue it doesn't make any sense that all diagnostics are warnings. The official lsp implmentation for ruff, ruff-lsp implements a basic mapping from codes to severity [2], so at the very least we should feel comfortable migrating that mapping for our use. 1. astral-sh/ruff#1256 2. https://github.com/astral-sh/ruff-lsp/blob/6a1a7b18711cf65b058492d5800e606f14556861/ruff_lsp/server.py#L346-L354
ruff doesn't really implement severities by itself [1], and one could argue it doesn't make any sense that all diagnostics are warnings. The official lsp implmentation for ruff, ruff-lsp implements a basic mapping from codes to severity [2], so at the very least we should feel comfortable migrating that mapping for our use. 1. astral-sh/ruff#1256 2. https://github.com/astral-sh/ruff-lsp/blob/6a1a7b18711cf65b058492d5800e606f14556861/ruff_lsp/server.py#L346-L354
ruff doesn't really implement severities by itself [1], and one could argue it doesn't make any sense that all diagnostics are warnings. The official lsp implmentation for ruff, ruff-lsp implements a basic mapping from codes to severity [2], so at the very least we should feel comfortable migrating that mapping for our use. 1. astral-sh/ruff#1256 2. https://github.com/astral-sh/ruff-lsp/blob/6a1a7b18711cf65b058492d5800e606f14556861/ruff_lsp/server.py#L346-L354
ruff doesn't really implement severities by itself [1], and one could argue it doesn't make any sense that all diagnostics are warnings. The official lsp implmentation for ruff, ruff-lsp implements a basic mapping from codes to severity [2], so at the very least we should feel comfortable migrating that mapping for our use. 1. astral-sh/ruff#1256 2. https://github.com/astral-sh/ruff-lsp/blob/6a1a7b18711cf65b058492d5800e606f14556861/ruff_lsp/server.py#L346-L354
Jenkins CI has a plugin called warnings-ng for reporting issues from various tools. see https://github.com/jenkinsci/warnings-ng-plugin/blob/main/doc/Documentation.md#issues-history-new-fixed-and-outstanding-issues Unfortunately ruff format is not supported yet. If we could have that it might be able to detect which warnings are new and which are old. This would make it easier to start using ruff in a repo with a lot of warnings by using a baseline. see https://github.com/jenkinsci/warnings-ng-plugin/blob/main/SUPPORTED-FORMATS.md |
I think having a "info" level in addition to "warning" and "error" could be nice for some lints like PTH ( |
Personally, I use Maybe having customisability of --add-noqa would be a solution to this use case? So for example you can specify a rule(set) e.g.: |
This is possible by just combining it with
This should only add |
Since it hasn't been explicitly mentioned yet, I'd also like to point one use case of autofixing. For some eslint project, I have turned the most common autofixable lint errors into warnings so that I am aware of them while editing. Since I personally am auto-formatting on save (and fixing all these autofixables at once) I don't need them to be marked as warnings, but not everyone else on the team might be, I still want these to cause the CI lint pass to fail. Thus, perhaps a way of specifying the level/severity of all autofixable rules at once on a machine-by-machine basis, e.g. by a parameter to the language server, would make sense here. |
pls do this. I just want to put a warning on unused imports, nothing else |
Junit support was actually added in #968 |
It would be really nice if, like
ignore
, we could select specific issues to turn into warnings rather than errors. That is, it would still output a warning tostdout
, (perhaps separating errors and warnings), but it would still return with exit status 0.Use case:
A large, older codebase that contains a lot of linting issues regarding specific rules. (For example, a codebase that predates type annotations.) By allowing warnings, we can make these issues visible to developers for fixing as they lint their changes, but we don't have to have a separate configuration for our pre-commit hooks, CI tools, etc. to ensure they ignore these issues.
The text was updated successfully, but these errors were encountered: