summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Berendt <berendt@b1-systems.de>2014-09-30 21:18:50 +0200
committerChristian Berendt <berendt@b1-systems.de>2014-09-30 21:44:59 +0200
commit5a4341727ef0440f5c1575263a38e6b44a7dedea (patch)
tree3927590ca300d8ec3df8cb75bbe7857555a4ffb7
parent8b8f22329bb8456df870616a8c8e6601f4e70755 (diff)
Add check D005 - no newline at end of file
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Joshua Harlow <harlowja@yahoo-inc.com> Workflow+1: Joshua Harlow <harlowja@yahoo-inc.com> Submitted-by: Jenkins Submitted-at: Fri, 10 Oct 2014 06:24:49 +0000 Reviewed-on: https://review.openstack.org/125172 Project: stackforge/doc8 Branch: refs/heads/master
-rw-r--r--CONTRIBUTING.rst2
-rw-r--r--HACKING.rst2
-rw-r--r--README.rst1
-rw-r--r--doc8/checks.py11
-rw-r--r--doc8/main.py2
-rw-r--r--doc8/parser.py5
-rw-r--r--doc8/tests/test_checks.py17
7 files changed, 38 insertions, 2 deletions
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index e505e3b..0664e26 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -10,4 +10,4 @@ the workflow documented at:
10 10
11 http://wiki.openstack.org/GerritWorkflow 11 http://wiki.openstack.org/GerritWorkflow
12 12
13Pull requests submitted through GitHub will be ignored. \ No newline at end of file 13Pull requests submitted through GitHub will be ignored.
diff --git a/HACKING.rst b/HACKING.rst
index 97c6879..b889622 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -1,4 +1,4 @@
1doc8 Style Commandments 1doc8 Style Commandments
2=============================================== 2===============================================
3 3
4Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/ \ No newline at end of file 4Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
diff --git a/README.rst b/README.rst
index 3df598e..8b71665 100644
--- a/README.rst
+++ b/README.rst
@@ -43,6 +43,7 @@ Command line usage
43 - no trailing whitespace - D002 43 - no trailing whitespace - D002
44 - no tabulation for indentation - D003 44 - no tabulation for indentation - D003
45 - no carriage returns (use unix newlines) - D004 45 - no carriage returns (use unix newlines) - D004
46 - no newline at end of file - D005
46 47
47 positional arguments: 48 positional arguments:
48 path path to scan for doc files (default: os.getcwd()) 49 path path to scan for doc files (default: os.getcwd())
diff --git a/doc8/checks.py b/doc8/checks.py
index fc2e911..4637e9e 100644
--- a/doc8/checks.py
+++ b/doc8/checks.py
@@ -73,6 +73,17 @@ class CheckCarriageReturn(LineCheck):
73 yield ('D004', 'Found literal carriage return') 73 yield ('D004', 'Found literal carriage return')
74 74
75 75
76class CheckNewlineEndOfFile(ContentCheck):
77 REPORTS = frozenset(["D005"])
78
79 def __init__(self, cfg):
80 super(CheckNewlineEndOfFile, self).__init__(cfg)
81
82 def report_iter(self, parsed_file):
83 if parsed_file.lines and not parsed_file.lines[-1].endswith('\n'):
84 yield (len(parsed_file.lines), 'D005', 'No newline at end of file')
85
86
76class CheckValidity(ContentCheck): 87class CheckValidity(ContentCheck):
77 REPORTS = frozenset(["D000"]) 88 REPORTS = frozenset(["D000"])
78 EXT_MATCHER = re.compile(r"(.*)[.]rst", re.I) 89 EXT_MATCHER = re.compile(r"(.*)[.]rst", re.I)
diff --git a/doc8/main.py b/doc8/main.py
index 85228d8..7de933a 100644
--- a/doc8/main.py
+++ b/doc8/main.py
@@ -27,6 +27,7 @@ What is checked:
27 - no trailing whitespace - D002 27 - no trailing whitespace - D002
28 - no tabulation for indentation - D003 28 - no tabulation for indentation - D003
29 - no carriage returns (use unix newlines) - D004 29 - no carriage returns (use unix newlines) - D004
30 - no newline at end of file - D005
30""" 31"""
31 32
32import argparse 33import argparse
@@ -131,6 +132,7 @@ def fetch_checks(cfg):
131 checks.CheckIndentationNoTab(cfg), 132 checks.CheckIndentationNoTab(cfg),
132 checks.CheckCarriageReturn(cfg), 133 checks.CheckCarriageReturn(cfg),
133 checks.CheckMaxLineLength(cfg), 134 checks.CheckMaxLineLength(cfg),
135 checks.CheckNewlineEndOfFile(cfg),
134 ] 136 ]
135 mgr = extension.ExtensionManager( 137 mgr = extension.ExtensionManager(
136 namespace='doc8.extension.check', 138 namespace='doc8.extension.check',
diff --git a/doc8/parser.py b/doc8/parser.py
index 2778af0..0c1c575 100644
--- a/doc8/parser.py
+++ b/doc8/parser.py
@@ -97,6 +97,11 @@ class ParsedFile(object):
97 yield line 97 yield line
98 98
99 @property 99 @property
100 def lines(self):
101 self._read()
102 return self._lines
103
104 @property
100 def extension(self): 105 def extension(self):
101 return self._extension 106 return self._extension
102 107
diff --git a/doc8/tests/test_checks.py b/doc8/tests/test_checks.py
index 1530fc5..0a88794 100644
--- a/doc8/tests/test_checks.py
+++ b/doc8/tests/test_checks.py
@@ -120,3 +120,20 @@ test
120 check = checks.CheckMaxLineLength(conf) 120 check = checks.CheckMaxLineLength(conf)
121 errors = list(check.report_iter(parsed_file)) 121 errors = list(check.report_iter(parsed_file))
122 self.assertEqual(expected_errors, len(errors)) 122 self.assertEqual(expected_errors, len(errors))
123
124
125class TestNewlineEndOfFile(testtools.TestCase):
126 def test_newline(self):
127 tests = [(1, "testing"),
128 (1, "testing\ntesting"),
129 (0, "testing\n"),
130 (0, "testing\ntesting\n")]
131
132 for expected_errors, line in tests:
133 with tempfile.NamedTemporaryFile() as fh:
134 fh.write(line)
135 fh.flush()
136 parsed_file = parser.ParsedFile(fh.name)
137 check = checks.CheckNewlineEndOfFile({})
138 errors = list(check.report_iter(parsed_file))
139 self.assertEqual(expected_errors, len(errors))