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

Bug report #217

Open
af-now-it opened this issue Jan 15, 2024 · 1 comment
Open

Bug report #217

af-now-it opened this issue Jan 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@af-now-it
Copy link

af-now-it commented Jan 15, 2024

1️⃣ Description

yamllint (1.33.0) output for a file
****.yml

  1:1       warning  missing document start "---"  (document-start)
  2:1       error    wrong indentation: expected at least 1  (indentation)
  10:3      error    wrong indentation: expected 4 but found 2  (indentation)

yamlfixer --nochange --summary --recurse -1 ###/

Traceback (most recent call last):
  File "/###/.local/bin/yamlfixer", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/###/.local/lib/python3.11/site-packages/yamlfixer/__main__.py", line 151, in run
    return yfixer.fix()
           ^^^^^^^^^^^^
  File "/###/.local/lib/python3.11/site-packages/yamlfixer/yamlfixer.py", line 167, in fix
    (status, unidiff) = filetofix.fix()
                        ^^^^^^^^^^^^^^^
  File "/###/.local/lib/python3.11/site-packages/yamlfixer/filefixer.py", line 211, in fix
    handled = ProblemFixer(self, linenumber, colnumber, problem)()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/###/.local/lib/python3.11/site-packages/yamlfixer/problemfixer.py", line 55, in __call__
    getattr(self, methodname)(left, right)
  File "###/.local/lib/python3.11/site-packages/yamlfixer/problemfixer.py", line 256, in fix_wrong_indentation
    expected = int(parts[3])

            ^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'at'

📑 Steps to Reproduce

Build a yml file with wrong indentation: expected at least 1 (indentation)
so that the output from yamllint (1.33.0)

cat test.yml

---
test:
- eins
- zwei

yamllint test.yml

test.yml
  3:1       error    wrong indentation: expected at least 1  (indentation)

ℹ️ Environment details

  • OS: RedHat 8.8
  • Python 3.6.8
  • Python 3.11.2
  • yamllint 1.33.0
  • bash, Version 4.4.20(1)-release

Additional context

HotFix for This Problem

if I change line 256 & 257 in problemfixer.py to

256 if parts[3] == 'at' and isinstance(parts[5], int) :
257 expected = 0
258 found = int(parts[5])
259 elif isinstance(parts[3], int) and isinstance(parts[5], int):
260 expected = int(parts[3])
261 found = int(parts[6])
262 else
263 exit(1)
264 offset = expected - found

it works for this

so that fix_wrong_indentation looks like this

    def fix_wrong_indentation(self, left, right):
        """Fix:
             - wrong indentation: expected
        """  # noqa: D205, D208, D400
        # TODO: yamllint only reports the first faulty line in a block :-(
        # TODO: see https://github.com/adrienverge/yamllint/issues/427
        # TODO: we fix anyway, knowing that we may need to launch the command
        # TODO: several times to finally fix the problem.
        parts = self.problem.split()
        if parts[3] == 'at' and isinstance(int(parts[5]), int):
            expected = 0
            found = int(parts[5])
        elif isinstance(int(parts[3]), int) and isinstance(int(parts[6]), int):
            expected = int(parts[3])
            found = int(parts[6])
        else:
            exit(1)
        offset = expected - found

        if expected > found:
            self.ffixer.lines[self.linenum] = (' ' * offset) + left + right
        else:
            # expected < found because we woudln't be there otherwise anyway
            self.ffixer.lines[self.linenum] = (left + right)[-offset:]
        self.ffixer.coffset += offset
@af-now-it af-now-it added the bug Something isn't working label Jan 15, 2024
@tamere-allo-peter
Copy link
Member

Thanks for your feedback. I haven't had the time to work on yamlfixer which currently lags way behind yamllint. Unfortunately I don't know when I'll be able to work on it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants