Skip to content

Commit 5e80a5b

Browse files
Qalthosssbarneapre-commit-ci[bot]
authored
Limit sequence-of-sequence indents to a single space (#3671)
Co-authored-by: Sorin Sbarnea <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 798746c commit 5e80a5b

File tree

8 files changed

+39
-1
lines changed

8 files changed

+39
-1
lines changed

.config/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ hwcksum
160160
idempotency
161161
ignorelist
162162
importlib
163+
indentless
163164
iniconfig
164165
inlinehilite
165166
insertafter

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
7272
# Number of expected test passes, safety measure for accidental skip of
7373
# tests. Update value if you add/remove tests.
74-
PYTEST_REQPASS: 817
74+
PYTEST_REQPASS: 818
7575
steps:
7676
- name: Activate WSL1
7777
if: "contains(matrix.shell, 'wsl')"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ src/ansiblelint/_version.py
5454
test/fixtures/formatting-before/
5555
# prettier should not edit this due to forcibly extra-long lines
5656
examples/playbooks/vars/strings.transformed.yml
57+
# prettier should not edit this due to intentionally spaced nesting
58+
examples/playbooks/vars/transform_nested_data.yml
5759

5860
# other
5961
.cache
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
sequence:
3+
- - - 111
4+
- 112
5+
- 12
6+
- - 21
7+
- - 221
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
sequence:
3+
- - - 111
4+
- 112
5+
- 12
6+
- - 21
7+
- - 221

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ ignore = [
240240
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
241241
"TRY",
242242
"PERF203",
243+
"PD011", # We are not using pandas, any .values attributes are unrelated
243244
]
244245
select = ["ALL"]
245246
target-version = "py39"

src/ansiblelint/yaml_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,17 @@ def choose_scalar_style(self) -> Any:
599599
return "'"
600600
return self.preferred_quote
601601

602+
def increase_indent(
603+
self,
604+
flow: bool = False, # noqa: FBT002
605+
sequence: bool | None = None,
606+
indentless: bool = False, # noqa: FBT002
607+
) -> None:
608+
super().increase_indent(flow, sequence, indentless)
609+
# If our previous node was a sequence and we are still trying to indent, don't
610+
if self.indents.last_seq():
611+
self.indent = self.column + 1
612+
602613
def write_indicator(
603614
self,
604615
indicator: str, # ruamel.yaml typehint is wrong. This is a string.
@@ -621,6 +632,9 @@ def write_indicator(
621632
and not self._in_empty_flow_map
622633
):
623634
indicator = (" " * spaces_inside) + "}"
635+
# Indicator sometimes comes with embedded spaces we need to squish
636+
if indicator == " -" and self.indents.last_seq():
637+
indicator = "-"
624638
super().write_indicator(indicator, need_whitespace, whitespace, indention)
625639
# if it is the start of a flow mapping, and it's not time
626640
# to wrap the lines, insert a space.

test/test_transformer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ def fixture_runner_result(
114114
True,
115115
id="jinja_spacing",
116116
),
117+
pytest.param(
118+
"examples/playbooks/vars/transform_nested_data.yml",
119+
3,
120+
True,
121+
id="nested",
122+
),
117123
),
118124
)
119125
def test_transformer( # pylint: disable=too-many-arguments, too-many-locals

0 commit comments

Comments
 (0)