-
Notifications
You must be signed in to change notification settings - Fork 303
Description
When running yamllint (v1.37.1) on Python 3.11, I encountered a TypeError in the indentation rule when processing a specific YAML file used in my unit tests.
The file is intentionally invalid YAML (garbage content).
workflow-invalid.yml
THI IS:
}¬} invlid"
>YAMLUnfortunately, I have not been able to create a minimal reproducible example from scratch — the crash only happens with this particular file in my project.
When I add this file to the ignore section in .yamllint, the error disappears and yamllint runs normally again.
Traceback (most recent call last):
File "/home/user/.local/bin/yamllint", line 8, in <module>
sys.exit(run())
File "/home/user/.local/lib/python3.11/site-packages/yamllint/cli.py", line 227, in run
prob_level = show_problems(problems, file, args_format=args.format,
File "/home/user/.local/lib/python3.11/site-packages/yamllint/cli.py", line 102, in show_problems
for problem in problems:
File "/home/user/.local/lib/python3.11/site-packages/yamllint/linter.py", line 201, in _run
for problem in get_cosmetic_problems(buffer, conf, filepath):
File "/home/user/.local/lib/python3.11/site-packages/yamllint/linter.py", line 136, in get_cosmetic_problems
for problem in rule.check(rule_conf,
File "/home/user/.local/lib/python3.11/site-packages/yamllint/rules/indentation.py", line 582, in check
yield from _check(conf, token, prev, next, nextnext, context)
File "/home/user/.local/lib/python3.11/site-packages/yamllint/rules/indentation.py", line 343, in _check
if expected < 0:
TypeError: '<' not supported between instances of 'NoneType' and 'int'Expected behavior:
Invalid YAML should result in a parsing error message, not a crash.
Workaround:
Adding the file to .yamllint’s ignore list resolves the problem.
Environment:
yamllint: 1.37.1
Python: 3.11
OS: Ubuntu 24.04.3 LTS
Maybe just make sure expected is never NoneType?
Greetings from austria