Enabling presets for streamlined configuration #3363
Replies: 9 comments 13 replies
-
A different philosophy would be to say that we want Ruff to feel more like Clippy, with most rules enabled by default (apart from the "pedantic" and experimental rules) and coarser categorizations -- so Ruff becomes easier to configure by way of having fewer knobs and more opinions. I'll admit that I don't know whether this is possible in Python, where there's so much more heterogeneity in projects and project needs: docstrings, type annotations, language versions, etc. All of these things lead to different needs that tend towards different linter configurations. |
Beta Was this translation helpful? Give feedback.
-
EDIT (extension to q3): just checked out the linked issues again and it seems like eslint does the thing where packages can be released on npm, which is basically what I desired. I'm not too fond of the idea of just direct URLs though, as the idea of ruff making arbitrary network requests doesn't sit that well with me, but it might just be me being paranoid. Something like an environment variable or global config for ruff to prompt the user before making network requests would be sufficient for me, though (these wouldn't be present in CI servers, of course, so it would still work fine there). |
Beta Was this translation helpful? Give feedback.
-
I want to take one step back from technical discussion to understand better the users' needs. I want to bring this up because it needs to be clarified if this discussion also touches on the categorization of rules: per tooling vs. per lint category (correctness, style, ...) The following is how I think about linters, and I would love to hear your perspectives. Ruff UsersOur users want to craft excellent products quickly, and Ruffs helps them achieve that by giving immediate feedback about potential errors and teaching best practices. Our users don't want to be linter experts, know all rules by heart, nor spend hours configuring their tooling. We should be the experts and give them access to our knowledge with minimal effort. When I think about presets, the following user groups come to my mind (there are probably more):
Ideal PropertiesAgain, these are the ideal properties that I deduce from the user groups above. Some of these properties touch on fundamental principles we haven't yet defined for Ruff.
QuestionsThere are a few things that are unclear to me about what users want:
|
Beta Was this translation helpful? Give feedback.
-
How is everyone currently sharing their configs? My organization is starting to feel the pain of having multiple configs floating out in the wild and it would be great to centralize them. I was thinking of packaging it into a PyPi package similar to how ESLint Configs are distributed on NPM. Then the config could be referenced by file path if it's a package dependency. Which, is easy in our case because our virtual environments happen to be saved to the local git repository. It doesn't feel very ergonomic though. |
Beta Was this translation helpful? Give feedback.
-
The next release of Hatch will introduce a I aim to maintain a selection of rules that would be desirable by most code bases, without caring about transition costs. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, Is there a way you can categorize the linter rules into buckets such as "critical", "important", "useful", "style", "pedantic". I don't know the actual names you would chose, just that I have this sentiment that some checks are validating syntax (critical), others are like undefined-name is very important if it fails, but can have false positives due to things like "from xxx import *", some bing useful insights but are not necessary, others only care about whitespace and some checks are actually just opinons where you may want to avoid. The reason for this is that I could have something like this on my config file for everyday use:
But then I could also have a command line on my code validation step for pull requests saying code is rejected regarding critical checks only
|
Beta Was this translation helpful? Give feedback.
-
FYI Hatch now maintains an extensive set of default settings that are desirable for the majority of users https://hatch.pypa.io/latest/blog/2023/12/11/hatch-v180/#static-analysis In all of my repos I am now wiping out most of my config in favor of these defaults! |
Beta Was this translation helpful? Give feedback.
-
I would just like to know what the default actually are... > ruff -v some_file.py
[2024-02-02][10:40:25][ruff::resolve][DEBUG] Using Ruff default settings
[2024-02-02][10:40:25][ruff::commands::check][DEBUG] Identified files to lint in: 2.783833ms
[2024-02-02][10:40:25][ruff::commands::check][DEBUG] Checked 1 files in: 405µs Looks like it's happy... but my file has some weird stuff in it, so 🤷🏻 ? |
Beta Was this translation helpful? Give feedback.
-
My use-case is that I have multiple open-source projects: I want to have a shared base config. [ruff]
preset = "https://link.to/my_config.toml" Then, I want to change some settings locally:
This would also be the same for companies using ruff. They can define one config in one source of truth and the use it in all of their projects. |
Beta Was this translation helpful? Give feedback.
-
Background
Ruff is relatively un-opinionated when it comes to configuration -- Ruff's default configuration is fairly minimal, and the expectation today is that user's will explicitly opt-in to the rule sets that they want to enable for their projects.
In response, we often hear that users want more streamlined and standardized configuration (#3356, #809, Twitter).
The goal of this Discussion is to debate the various options we could pursue to make Ruff easier to configure.
presets
To open the Discussion: one concrete option is to add a
presets
concept to Ruff, in which apreset
would represent an opinionated set of defaults that the user could opt into. Semantically, enabling apreset
would be equivalent to the currentextends
behavior (which lets Ruff extend another local configuration file), and also equivalent to changing Ruff's default settings.For now,
presets
would ship with Ruff.For example, we could allow users to express a configuration like:
...which might, in theory, be equivalent to something like (exact rules TBD):
Users could modify the preset by adding additional options to their configuration. For example:
...would in theory be equivalent to:
Alongside
ruff:recommended
, we would ship something likeruff:strict
, and so on.In the future, we could allow users to publish and share presets, just as in ESLint.
Questions
Some unanswered questions in this design, and in the proposal more broadly:
preset
andextends
interact? Are users allowed to both enable a preset and extend another configuration?On that last question: I suspect that adding presets would help with users migrating to Ruff from a no-linter configuration, or from Pylint, and would help with the "There are too many rules, how do I configure this thing?" problem.
But users that are coming from the Flake8 ecosystem tend to have specific plugins enabled that they want to replicate, and those users tend to look for a 1:1 migration, so moving to a preset would typically mean turning off rules, which (in my experience) users tend to dislike. At the same time, perhaps users coming from the Flake8 ecosystem don't have this problem anyway, since they're typically mirroring their existing configuration?
Beta Was this translation helpful? Give feedback.
All reactions