Repository navigation
ci(lint): Ruff PLR1702 caps nesting at 4 blocks and replaces the hook - #2602
Merged
Merged
Conversation
…licit lint preview `pyproject.toml` selects PLR1702 with `max-nested-blocks = 4`. PLR1702 is a preview rule in Ruff 0.16, so `[tool.ruff.lint]` sets `preview = true` with `explicit-preview-rules = true`; the formatter keeps its stable style. At 4, Ruff fails five nested `if`, `for`, `while`, `with` or `except` blocks, as the `structural-invariants` hook did, and it also counts a `try` body. The 12 functions with five blocks once a `try` body counts each move one block into a helper, with the same behavior. `tests/test_ruff_complexity_cap.py` holds the cap, the preview settings and the formatter's style, and five nested `if` blocks fail while four pass.
…e that PLR1702 replaces The pre-commit `structural-invariants` hook, the nesting leg of the whole-tree test, and `nesting_depth`, `breaches`, `main` and the `max_nesting_depth` field of `core/code_metrics.py` are deleted, with `DEFAULT_MAX_NESTING_DEPTH`. Ruff gives no nesting figure for each function and is a development dependency, so `devops scan complexity` drops `--max-indent` and its nesting findings, the MCP tool drops `max_indent`, and `devops ai spec` drops the `max_indentation` rule and keeps one forbidden-import rule for each file. The documents name PLR1702 at 4.
…h keeps the rule code under lint preview
Owner
Author
|
Evidence (Ruff 0.16.8; base origin/main Both tools on
Generated samples, Ruff at 4 against the hook at 5:
Tests:
Cap choice: 4, not the 5 of the owner's 2026-10-22 decision, because 5 allows a fifth Follow-up filed: #2600 (the McCabe port, decision 4 of #1876). Pending a person: review the diff in tuicr ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruff's PLR1702 replaces the
structural-invariantspre-commit hook and the nesting metric that the project wrote.pyproject.tomlselects PLR1702 withmax-nested-blocks = 4, through lint preview withexplicit-preview-rules, so no other preview rule runs. The formatter stays out of preview.if,for,while,withorexceptblocks, as the hook did, and it also counts atrybody. The 12 functions with five blocks under that count each move one block into a helper.core/code_metrics.pyare deleted.devops scan complexitydrops--max-indent, anddevops ai specdrops its indentation rule.matchblocks or anassert. No code relies on either gap today.Closes #1876
Change:
openspec/changes/archive/2026-10-29-1876-ruff-nesting-cap/