3

I want to assign certain ruff rulesets as suggestion/warning rather than hard failures.

Context

I am currently defining the ruff linter on a public open-source project.

In addition to the normal select and ignore of certain rulesets, I would be interested in ruff extending a "suggestion" to the user for certain rulesets. So we can include these into pre-commit hooks and CI pipelines, where these suggestions can inform code reviews and be a learning opportunity, but not block development (or worse, cause devs to commit with the -n flag).

Usecases

Here are two practical examples:

TCH - Typechecking

The ruleset TCH moves imports for type checking into a designated block. This is a nice-to-have but can get in the way of developing a new feature on the package.

TD - TODO comments

The ruleset TD seems generally useful. But consider work on a pull/merge request that requires open issue links with rule TD003. If I were to enforce this ruleset, I would get a slew of issues opened on a PR that is potentially rejected, for the PR to even comply with the enforced ruleset.

In both cases having a warning of "it'd be nice if you'd consider these changes" instead of a hard fail, would be preferred.

Is there any way to do this or a work-around to implement this behaviour?


So far I have tried the following:

I have worked through the documentation and this does not seem to be covered by select or ignore.

I have also considered other Stackoverflow questions, but this is not about excludess per block or file unfortunately.

I want to set this on a configuration-level as I plan to run ruff in a pre-commit hooks (user) and CI/CD pipelines (automation). These different applications would need varying flags individually which can become cumbersone to maintain, when it is behaviour expected on the "ruff-level".

3
  • run a separate check for your "soft" rules, and take advantage of ruff check's --exit-zero Commented Aug 5, 2024 at 18:16
  • That's a good idea as a backup for pre-commit hooks I think. Thanks! Commented Aug 6, 2024 at 12:45
  • i haven't tried, but i don't see why you couldn't do two ruff checks in pre-commit. For your "hard" rules configure ruff via say pyproject.toml, and your "soft" rules as a second check configure ruff via command line arguments. don't forget ruff check --isolated to ignore your pyproject.toml in that case. Commented Aug 6, 2024 at 15:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.