ruff icon indicating copy to clipboard operation
ruff copied to clipboard

[feature-request] Config inheritance

Open smackesey opened this issue 2 years ago • 3 comments

In monorepos, it can easily happen that some section of the codebase needs to maintain consistency with the rest of the code but vary in one dimension. For example, in Dagster we use a line length of 100, but shorten it to 88 for our docs-snippets package, which includes code snippets that are incorporated into built docs. The shorter length is to ensure readers don't need to scroll horizontally when reading a code block in the browser.

We're currently maintaining a separate pyproject.toml file in docs-snippets where we duplicate most of the configuration in our root pyproject.toml for black and isort, just so that we can change the line length. This is because neither of these tools offers any mechanism I'm aware of for config inheritance, which would allow only overriding specific settings.

But it would be great to have-- for ruff, it might look something like this:

# pyproject.toml (root)

[tool.ruff]

line-length = 100
# ... rest of ruff config

# examples/docs-snippets/pyproject.toml

[tool.ruff]

extends = "../../pyproject.toml"  # reads settings from root pyproject.toml
line-length = 88

That's just a suggestion, I haven't thought about how best to implement this-- but some generic extension/inheritance mechanism for config would be useful. Eslint might be a good place to gain inspiration.

smackesey avatar Dec 05 '22 12:12 smackesey

Yeah, agree with the issue summary. (The discussion around presets would also be relevant here: #809.)

I'd like it to be explicit and opt-in, like ESLint's extends, rather than doing anything implicit based on the filesystem hierarchy.

The trickiest part is that we'd then have to use different settings for different files within a single ruff execution (at least, I think that's how ESLint works). Right now, we resolve the single project root, resolve the settings, then lint all files with those settings; but if we support configuration inheritance, we may have to resolve different settings for different subtrees of the filesystem.

charliermarsh avatar Dec 05 '22 14:12 charliermarsh

By the way: thanks for all the thoughtful and well-written issues. I also realized this morning that you wrote the Dagster article on type migrations, which I enjoyed a lot. Great to have you hanging around the Ruff repo.

charliermarsh avatar Dec 05 '22 14:12 charliermarsh

Thanks-- yeah I've done a lot over the past 24 hours assessing ruff and trying to port Dagster OSS. Almost at the finish line. Your selling point of extreme speed is 100% accurate, I'm pretty excited to get linter editor feedback as instantly (even faster really) as the type-checking feedback provided by pyright/pylance. Also very nice to have something so actively developed-- that aliased import config option you added 1 hour after I requestedi it last night would've probably taken a year to get implemented in isort. Thanks for your hard work here!

smackesey avatar Dec 05 '22 15:12 smackesey

This is going out in v0.0.178. For now, at least, it's explicit via extends.

charliermarsh avatar Dec 13 '22 03:12 charliermarsh