Replies: 1 comment
-
Thanks for starting this discussion I'm a bit hesitant to add content-based filtering because it requires running through the entire file content to make a decision whether it should be included or not (the not can probably exit earlier). The filter configuration would have to be its own field to that projects pay this overhead when they aren't using the functionality. Either way, I'm worried about the performance impact
What I understand is that you don't have specific formatting needs. Have you considered excluding those files from formatting altogether or using different formatting settings for them? |
Beta Was this translation helpful? Give feedback.
-
We're considering using
ruff
for Spack, where we currently useblack
.Spack is a package manager. It has core Python code, which we don't have many special formatting needs for. It also has 8,000 or so
package.py
recipe files, and the recipes have some special functions that implement a DSL.So, for a package with lots of versions, we might write:
Idea
I would like to exclude
version()
and other directives containing asha256
from formatting and line length checks. e.g., I'd like to be able to write something like this inruff
's config:This seems like it might be complicated, as the regex would need to apply to a statement that might span multiple lines. For our purposes you could simplify it, since we really only need to match on the
version(
call, which is always first and never spread over multiple lines:I am curious whether something like this would be possible to implement in
ruff
, and whetherruff
devs would be open to it.Motivation
With long hashes, small argument changes can result in big formatting changes, e.g. if we deprecate those versions we might write:
Or:
Unfortunately, both of these now exceed the max line length for our
black
configuration, which we've set at99
characters. So, these end up looking like:or, worse:
This gets to be hard to read and causes headaches for devs when updating packages. It also adds more churn to the repo than we'd really like. We'd like the rest of the
package.py
file to be formatted with our regular code formatting rules, but directives like this (which really just provide metadata) should ideally be left untouched. We used to get this effect by pre-filtering our files and adding# noqa
to lines that met certain criteria, but that got to be quite slow (copying thousands of files, modifying them, formatting them, copying them back). We simplified by choosing a slightly longer line length and standardizing onblack
, but a number of us still miss the exceptions.Beta Was this translation helpful? Give feedback.
All reactions