Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the maximum block depth #3602

Merged
merged 6 commits into from
Aug 21, 2023
Merged

Limit the maximum block depth #3602

merged 6 commits into from
Aug 21, 2023

Conversation

Ruchip16
Copy link
Member

@Ruchip16 Ruchip16 commented Jul 4, 2023

Since inside tasks there can be nested blocks so this PR limits the depth of the block by a certain limit which helps to maintain the readability of the playbooks.

fixes: #2173

@Ruchip16 Ruchip16 added the skip-changelog Can be missed from the changelog. label Jul 4, 2023
@Ruchip16 Ruchip16 self-assigned this Jul 4, 2023
@Ruchip16 Ruchip16 requested a review from a team as a code owner July 4, 2023 11:01
@Ruchip16
Copy link
Member Author

Ruchip16 commented Jul 6, 2023

hey @ssbarnea @ajinkyau can you review this please?

examples/playbooks/rule-complexity-fail.yml Outdated Show resolved Hide resolved
@audgirka audgirka marked this pull request as draft July 11, 2023 10:21
@Ruchip16 Ruchip16 marked this pull request as ready for review August 21, 2023 10:57
@ssbarnea ssbarnea added enhancement and removed skip-changelog Can be missed from the changelog. labels Aug 21, 2023
- fix counting of depth
- rename rule id to 'complexity[nesting]'
- add missing documentation
- add missing configuration schema
- include configurable example in sample config file
@ssbarnea
Copy link
Member

hey @ssbarnea @ajinkyau can you review this please?

Please check the last commit and see all the extra changes I had to do there. The original code was not really working and the tests were failing to check for the behavior. Still, it was not too hard to fix.

@ssbarnea ssbarnea dismissed audgirka’s stale review August 21, 2023 17:39

Outdated, please check again

@Ruchip16
Copy link
Member Author

hey @ssbarnea @ajinkyau can you review this please?

Please check the last commit and see all the extra changes I had to do there. The original code was not really working and the tests were failing to check for the behavior. Still, it was not too hard to fix.

the main thing i got wrong and really confused was with the example of the block, i although discussed that once with ajinkya, but nevertheless, apologies for the extra work and would contribute more to get a good hang of it!

@ssbarnea ssbarnea merged commit 385ad82 into ansible:main Aug 21, 2023
19 checks passed
nrdufour added a commit to nrdufour/home-ops that referenced this pull request Aug 22, 2023
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ansible-lint](https://github.com/ansible/ansible-lint) ([changelog](https://github.com/ansible/ansible-lint/releases)) | minor | `==6.17.2` -> `==6.18.0` |

---

### Release Notes

<details>
<summary>ansible/ansible-lint (ansible-lint)</summary>

### [`v6.18.0`](https://github.com/ansible/ansible-lint/releases/tag/v6.18.0)

[Compare Source](ansible/ansible-lint@v6.17.2...v6.18.0)

#### Minor Changes

-   Limit the maximum block depth ([#&#8203;3602](ansible/ansible-lint#3602)) [@&#8203;Ruchip16](https://github.com/Ruchip16)
-   Transform functionality for command_instead_of_shell  ([#&#8203;3675](ansible/ansible-lint#3675)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Add rule to check the number of tasks ([#&#8203;3156](ansible/ansible-lint#3156)) [@&#8203;Ruchip16](https://github.com/Ruchip16)

#### Bugfixes

-   Clarify loop-var-prefix rule and code snippet ([#&#8203;3642](ansible/ansible-lint#3642)) [@&#8203;schwarmco](https://github.com/schwarmco)
-   Update `version_added` for complexity rule ([#&#8203;3623](ansible/ansible-lint#3623)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Ensure that single space between tasks is preserved when using --write ([#&#8203;3641](ansible/ansible-lint#3641)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Update ansible-compat used for testing ([#&#8203;3664](ansible/ansible-lint#3664)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Document `yaml[line-length]` rule ([#&#8203;3653](ansible/ansible-lint#3653)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Prevent use of spdx-tools 0.8.0 due to breaking changes ([#&#8203;3649](ansible/ansible-lint#3649)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   fixes dead marketplace link ([#&#8203;3631](ansible/ansible-lint#3631)) [@&#8203;wookietreiber](https://github.com/wookietreiber)
-   Improve profile information on summary line ([#&#8203;3637](ansible/ansible-lint#3637)) [@&#8203;ziegenberg](https://github.com/ziegenberg)
-   command-instead-of-module: allow `git rev-parse` ([#&#8203;3610](ansible/ansible-lint#3610)) [@&#8203;JohnVillalovos](https://github.com/JohnVillalovos)
-   Include filepaths starting from $HOME in lintables ([#&#8203;3621](ansible/ansible-lint#3621)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Update \_mockings.py to fix bug created in [#&#8203;3390](ansible/ansible-lint#3390) ([#&#8203;3614](ansible/ansible-lint#3614)) [@&#8203;karcaw](https://github.com/karcaw)
-   Allow to set gather_facts as templated boolean ([#&#8203;3606](ansible/ansible-lint#3606)) [@&#8203;noonedeadpunk](https://github.com/noonedeadpunk)
-   Add dependency version check for collection metadata ([#&#8203;3601](ansible/ansible-lint#3601)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Fix installation of dependencies when run as an action ([#&#8203;3592](ansible/ansible-lint#3592)) [@&#8203;ssbarnea](https://github.com/ssbarnea)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yMy4yIiwidXBkYXRlZEluVmVyIjoiMzYuMjMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Reviewed-on: https://git.home/nrdufour/home-ops/pulls/49
Co-authored-by: Renovate <[email protected]>
Co-committed-by: Renovate <[email protected]>
@bluikko
Copy link
Contributor

bluikko commented Aug 28, 2023

Does this PR really limit maximum block depth, or tasks inside a block?

There seems to be a conflict between the PR name and the help files contained in the PR diff:

  • PR name talks about "block depth", i.e. nested blocks.
  • PR diff contains 2 new rule description items which only talk about number of tasks inside block.

Please clarify which one it is, something is wrong here.

More precisely:

`complexity[nesting]` will appear when a block contains too many tasks, by
default that number is 20 but it can be changed inside the configuration file by
defining `max_block_depth` value.

This rule description already has a conflict as well. It talks about number of tasks inside a block, but the rule name talks about "nesting" and the config param name includes "depth", contrary to the description text. It just adds to the confusion around what does this actually do. This is even listed in release notes talking about "maximum block depth", i.e. how many layers in nesting. But this does not match the rule descriptions at all.

@Ruchip16
Copy link
Member Author

Ruchip16 commented Aug 28, 2023

limit maximum block depth means that it limits the depth of any block (nested or not) up to a certain number which is currently 20 by default, if the tasks inside a block are > 20 it would raise a warning message, so maximum block depth refers to the depth of the block and nesting is a scenario inside that, hope that clears your confusion, but yes we need to do something if it is creating a confusion

@bluikko
Copy link
Contributor

bluikko commented Aug 28, 2023

limit maximum block depth means that it limits the depth of any block

It does not, at all. It strengthens my opinion that the words are misused here.
"Depth" refers to how many nested layers there are in my opinion.

More suitable terms would include: "length", "size", etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

size[block]: Limit the maximum block depth
5 participants