Fix new-lines rule on Python 3
Use io.open() when reading files in cli which has the same behaviour in Python 2 and Python 3, and supply the newline='' parameter which handles but does not translate line endings. Add dos.yml test file with windows newlines. Also add to file finding test expected output. Add test for new-lines rule through the cli. Validates files are read with the correct universal newlines setting. Fixes adrienverge/yamllint#228
This commit is contained in:
committed by
Adrien Vergé
parent
5b049e4229
commit
91763f5476
@@ -17,6 +17,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import io
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
@@ -176,7 +177,7 @@ def run(argv=None):
|
||||
for file in find_files_recursively(args.files, conf):
|
||||
filepath = file[2:] if file.startswith('./') else file
|
||||
try:
|
||||
with open(file) as f:
|
||||
with io.open(file, newline='') as f:
|
||||
problems = linter.run(f, conf, filepath)
|
||||
except EnvironmentError as e:
|
||||
print(e, file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user