Add check D005 - no newline at end of file
Change-Id: I160bb7e9b3c904655567caee999ac91366668109
This commit is contained in:
parent
8b8f22329b
commit
5a4341727e
@ -10,4 +10,4 @@ the workflow documented at:
|
|||||||
|
|
||||||
http://wiki.openstack.org/GerritWorkflow
|
http://wiki.openstack.org/GerritWorkflow
|
||||||
|
|
||||||
Pull requests submitted through GitHub will be ignored.
|
Pull requests submitted through GitHub will be ignored.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
doc8 Style Commandments
|
doc8 Style Commandments
|
||||||
===============================================
|
===============================================
|
||||||
|
|
||||||
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
|
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
|
||||||
|
@ -43,6 +43,7 @@ Command line usage
|
|||||||
- no trailing whitespace - D002
|
- no trailing whitespace - D002
|
||||||
- no tabulation for indentation - D003
|
- no tabulation for indentation - D003
|
||||||
- no carriage returns (use unix newlines) - D004
|
- no carriage returns (use unix newlines) - D004
|
||||||
|
- no newline at end of file - D005
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
path path to scan for doc files (default: os.getcwd())
|
path path to scan for doc files (default: os.getcwd())
|
||||||
|
@ -73,6 +73,17 @@ class CheckCarriageReturn(LineCheck):
|
|||||||
yield ('D004', 'Found literal carriage return')
|
yield ('D004', 'Found literal carriage return')
|
||||||
|
|
||||||
|
|
||||||
|
class CheckNewlineEndOfFile(ContentCheck):
|
||||||
|
REPORTS = frozenset(["D005"])
|
||||||
|
|
||||||
|
def __init__(self, cfg):
|
||||||
|
super(CheckNewlineEndOfFile, self).__init__(cfg)
|
||||||
|
|
||||||
|
def report_iter(self, parsed_file):
|
||||||
|
if parsed_file.lines and not parsed_file.lines[-1].endswith('\n'):
|
||||||
|
yield (len(parsed_file.lines), 'D005', 'No newline at end of file')
|
||||||
|
|
||||||
|
|
||||||
class CheckValidity(ContentCheck):
|
class CheckValidity(ContentCheck):
|
||||||
REPORTS = frozenset(["D000"])
|
REPORTS = frozenset(["D000"])
|
||||||
EXT_MATCHER = re.compile(r"(.*)[.]rst", re.I)
|
EXT_MATCHER = re.compile(r"(.*)[.]rst", re.I)
|
||||||
|
@ -27,6 +27,7 @@ What is checked:
|
|||||||
- no trailing whitespace - D002
|
- no trailing whitespace - D002
|
||||||
- no tabulation for indentation - D003
|
- no tabulation for indentation - D003
|
||||||
- no carriage returns (use unix newlines) - D004
|
- no carriage returns (use unix newlines) - D004
|
||||||
|
- no newline at end of file - D005
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@ -131,6 +132,7 @@ def fetch_checks(cfg):
|
|||||||
checks.CheckIndentationNoTab(cfg),
|
checks.CheckIndentationNoTab(cfg),
|
||||||
checks.CheckCarriageReturn(cfg),
|
checks.CheckCarriageReturn(cfg),
|
||||||
checks.CheckMaxLineLength(cfg),
|
checks.CheckMaxLineLength(cfg),
|
||||||
|
checks.CheckNewlineEndOfFile(cfg),
|
||||||
]
|
]
|
||||||
mgr = extension.ExtensionManager(
|
mgr = extension.ExtensionManager(
|
||||||
namespace='doc8.extension.check',
|
namespace='doc8.extension.check',
|
||||||
|
@ -96,6 +96,11 @@ class ParsedFile(object):
|
|||||||
line = line[0:-1]
|
line = line[0:-1]
|
||||||
yield line
|
yield line
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lines(self):
|
||||||
|
self._read()
|
||||||
|
return self._lines
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extension(self):
|
def extension(self):
|
||||||
return self._extension
|
return self._extension
|
||||||
|
@ -120,3 +120,20 @@ test
|
|||||||
check = checks.CheckMaxLineLength(conf)
|
check = checks.CheckMaxLineLength(conf)
|
||||||
errors = list(check.report_iter(parsed_file))
|
errors = list(check.report_iter(parsed_file))
|
||||||
self.assertEqual(expected_errors, len(errors))
|
self.assertEqual(expected_errors, len(errors))
|
||||||
|
|
||||||
|
|
||||||
|
class TestNewlineEndOfFile(testtools.TestCase):
|
||||||
|
def test_newline(self):
|
||||||
|
tests = [(1, "testing"),
|
||||||
|
(1, "testing\ntesting"),
|
||||||
|
(0, "testing\n"),
|
||||||
|
(0, "testing\ntesting\n")]
|
||||||
|
|
||||||
|
for expected_errors, line in tests:
|
||||||
|
with tempfile.NamedTemporaryFile() as fh:
|
||||||
|
fh.write(line)
|
||||||
|
fh.flush()
|
||||||
|
parsed_file = parser.ParsedFile(fh.name)
|
||||||
|
check = checks.CheckNewlineEndOfFile({})
|
||||||
|
errors = list(check.report_iter(parsed_file))
|
||||||
|
self.assertEqual(expected_errors, len(errors))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user