Skip to content

Rule new-lines incorrect on Python 3 #228

@bz2

Description

@bz2

When the yamllint command is run using Python 3, the new-lines rule will always pass when set to 'unix' and always fail when set to 'dos'. This is because the builtin open() for Python 3 includes universal newline handling, so translates the line endings at file read time.

Steps to reproduce

$ echo ---^M > test.yaml
$ echo "---                 
rules:
 new-lines:
  type: dos
" > typedos.yaml
$ echo "---
rules:
 new-lines:
  type: unix
" > typeunix.yaml
$ python2 -m yamllint -c typeunix.yaml test.yaml
test.yaml
  1:4       error    wrong new line character: expected \n  (new-lines)

$ python2 -m yamllint -c typedos.yaml test.yaml
$ python3 -m yamllint -c typeunix.yaml test.yaml
$ python3 -m yamllint -c typedos.yaml test.yaml
test.yaml
  1:4       error    wrong new line character: expected \r\n  (new-lines)

Note behaviour is as expected on Python 2 but incorrect on Python 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions