Skip to content

Commit

Permalink
Fix long lines being wrapped with a trailing space (#4282)
Browse files Browse the repository at this point in the history
  • Loading branch information
cavcrosby committed Aug 10, 2024
1 parent 2dd2336 commit ca945d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 888
PYTEST_REQPASS: 889
steps:
- uses: actions/checkout@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,10 @@ def _post_process_yaml(
lines[index] = spaces + comment
full_line_comments.clear()

if line.rpartition(" ")[2] == "\n":
# drop any trailing spaces
lines[i] = line.rstrip() + "\n"

cleaned = line.strip()
if not cleaned.startswith("#") and cleaned.endswith("-"):
# got an empty list item. drop any trailing spaces.
Expand Down
6 changes: 6 additions & 0 deletions test/test_yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def load_yaml_formatting_fixtures(fixture_filename: str) -> tuple[str, str, str]
None,
id="12",
),
pytest.param(
"---\nWSLENV: HOSTNAME:CI:FORCE_COLOR:GITHUB_ACTION:GITHUB_ACTION_PATH/p:GITHUB_ACTION_REPOSITORY:GITHUB_WORKFLOW:GITHUB_WORKSPACE/p:GITHUB_PATH/p:GITHUB_ENV/p:VIRTUAL_ENV/p:SKIP_PODMAN:SKIP_DOCKER\n",
"---\nWSLENV:\n HOSTNAME:CI:FORCE_COLOR:GITHUB_ACTION:GITHUB_ACTION_PATH/p:GITHUB_ACTION_REPOSITORY:GITHUB_WORKFLOW:GITHUB_WORKSPACE/p:GITHUB_PATH/p:GITHUB_ENV/p:VIRTUAL_ENV/p:SKIP_PODMAN:SKIP_DOCKER\n",
None,
id="13",
),
),
)
def test_fmt(before: str, after: str, version: tuple[int, int] | None) -> None:
Expand Down

0 comments on commit ca945d7

Please sign in to comment.