acidjunk / acidjunk/pyang

Line length calculation is dependent on line endings

未關閉
#122 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
auto-migrated Priority-Medium Type-Defect
主要語言
Python
星號
0
分支
0
PR 合併指標
30 天內沒有已合併 PR

描述

```
What steps will reproduce the problem?
1. Run pyang --ietf on the attached testLF.yang:

% pyang --ietf testLF.yang
testLF.yang:1: warning: IETF rule (RFC formatting): line length 71 exceeds 70
characters
testLF.yang:2: warning: IETF rule (RFC formatting): line length 72 exceeds 70
characters
testLF.yang:3: warning: IETF rule (RFC formatting): line length 73 exceeds 70
characters
...

(note that testLF.yang has "Unix" LF line endings)

2. Run pyang --ietf on the attached testCRLF.yang:

% pyang --ietf testCRLF.yang
testCRLF.yang:1: warning: IETF rule (RFC formatting): line length 72 exceeds 70
characters
testCRLF.yang:2: warning: IETF rule (RFC formatting): line length 73 exceeds 70
characters
testCRLF.yang:3: warning: IETF rule (RFC formatting): line length 74 exceeds 70
characters
...

(note that testCRLF.yang has "DOS" CR LF line endings)

What is the expected output? What do you see instead?

By my calculation, these lines are of length 70, 71 and 72, so I would expect
to see the following for both of them:

testCRLF.yang:2: warning: IETF rule (RFC formatting): line length 71 exceeds 70
characters
testCRLF.yang:3: warning: IETF rule (RFC formatting): line length 72 exceeds 70
characters

What version of the product are you using? On what operating system?

Latest SVN version on OS X Yosemite.

Please provide any additional information below.

It looks to me as though this behaviour stems from text.splitlines(True) in
yang_parser.py below:

class YangTokenizer(object):
def __init__(self, text, pos, errors,
max_line_len=None, keep_comments=False):
self.lines = collections.deque(text.splitlines(True))

This is retaining line endings, which will be either LF (adding 1 to the line
length) or CR LF (adding 2 to the line length).

So the fix might be as simple as changing the above to text.splitlines(False)?
```

Original issue reported on code.google.com by `william....@gmail.com` on 20 Jan 2015 at 10:12

Attachments:
- [test.zip](https://storage.googleapis.com/google-code-attachments/pyang/issue-122/comment-0/test.zip)

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。