-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#4044] Add semantic newline checker in lint #7
base: master
Are you sure you want to change the base?
Changes from 5 commits
797ac80
24c7424
fd6e712
133044a
a903fe4
031b4ad
75252ec
cd9554a
4a3f949
3fad50a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
Keeps the version of the project. | ||
""" | ||
VERSION = '0.3.1' | ||
VERSION = '0.3.4' | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
absolute_import, | ||
unicode_literals, | ||
with_statement, | ||
) | ||
) | ||
|
||
__version__ = '0.1.1' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,7 +189,6 @@ class Language(object): | |
mimetypes.add_type('text/plain', '.txt') | ||
mimetypes.add_type('application/x-zope-configuation', '.zcml') | ||
|
||
|
||
# Sorted after content type. | ||
mime_type_language = { | ||
'application/javascript': JAVASCRIPT, | ||
|
@@ -248,6 +247,8 @@ class ScameOptions(object): | |
def __init__(self): | ||
self._max_line_length = 0 | ||
|
||
self.verbose = True | ||
|
||
self.regex_line = [] | ||
|
||
self.scope = { | ||
|
@@ -306,7 +307,6 @@ def __init__(self): | |
'disable': [], | ||
} | ||
|
||
|
||
def get(self, option, path=None): | ||
""" | ||
Return the value of "option" configuration. | ||
|
@@ -399,7 +399,7 @@ def _isExceptedLine(self, line, category, code): | |
# a category. | ||
return False | ||
|
||
if commentn.find('%s:%s' % (category, self._IGNORE_MARKER)) == -1: | ||
if comment.find('%s:%s' % (category, self._IGNORE_MARKER)) == -1: | ||
return False | ||
else: | ||
# We have a tagged exception | ||
|
@@ -461,6 +461,13 @@ def check(self): | |
class AnyTextMixin: | ||
"""Common checks for many checkers.""" | ||
|
||
def check_semantic_newline(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is defined here, but is not 'enabled' in any checkers. also, since for now we plan to use it only for RST it should be moved into the RST checker. |
||
"""Check that there are ., ?, or ! with a space following after. | ||
Exclude those with no new line and two full-stops.""" | ||
if self.line.find(['. ', '? ', '! ']) != (['\n', '..']): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea how and why this code works... but I guess that it does not work first, who is |
||
self.message( | ||
0, 'Line contains a sentence without a new line.', icon='info') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why report at line 0 ? |
||
|
||
def check_conflicts(self, line_no, line): | ||
"""Check that there are no merge conflict markers.""" | ||
if line.startswith('<' * 7) or line.startswith('>' * 7): | ||
|
@@ -1035,7 +1042,7 @@ def check_ascii(self, line_no, line): | |
line.encode('ascii') | ||
except UnicodeEncodeError as error: | ||
self.message( | ||
line_no, 'Non-ascii characer at position %s.' % error.end, | ||
line_no, 'Non-ascii character at position %s.' % error.end, | ||
icon='error', | ||
) | ||
|
||
|
@@ -1243,14 +1250,14 @@ def isSectionDelimiter(self, line_number): | |
def check_section_delimiter(self, line_number): | ||
"""Checks for section delimiter. | ||
|
||
These checkes are designed for sections delimited by top and bottom | ||
These checks are designed for sections delimited by top and bottom | ||
markers. | ||
|
||
======= <- top marker | ||
Section <- text_line | ||
======= <- bottom marker | ||
|
||
If the section is delimted only by bottom marker, the section text | ||
If the section is delimited only by bottom marker, the section text | ||
is considered the top marker. | ||
|
||
Section <- top marker, text_line | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
absolute_import, | ||
print_function, | ||
unicode_literals, | ||
) | ||
) | ||
|
||
import sys | ||
import unittest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
absolute_import, | ||
print_function, | ||
unicode_literals, | ||
) | ||
) | ||
|
||
from scame.tests import CheckerTestCase | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
absolute_import, | ||
print_function, | ||
unicode_literals, | ||
) | ||
) | ||
|
||
from scame.formatcheck import ReStructuredTextChecker | ||
from scame.tests import CheckerTestCase | ||
|
@@ -23,14 +23,14 @@ | |
|
||
|
||
-------------------- | ||
Second emtpy section | ||
Second empty section | ||
-------------------- | ||
|
||
|
||
Third section | ||
^^^^^^^^^^^^^ | ||
|
||
Paragrhap for | ||
Paragraph for | ||
third section `with link<http://my.home>`_. | ||
|
||
:: | ||
|
@@ -44,6 +44,10 @@ | |
| verse, and adornment-free lists. | ||
|
||
|
||
Newline test has newline. | ||
Indeed. | ||
|
||
|
||
.. _section-permalink: | ||
|
||
Another Section with predefined link | ||
|
@@ -141,7 +145,7 @@ def test_no_empty_last_line(self): | |
self.reporter.call_count = 0 | ||
content = ( | ||
'Some first line\n' | ||
'the second and last line witout newline') | ||
'the second and last line without newline') | ||
checker = ReStructuredTextChecker('bogus', content, self.reporter) | ||
checker.check_empty_last_line(2) | ||
expected = [( | ||
|
@@ -343,6 +347,56 @@ def test_check_section_delimiter_bad_marker_length(self): | |
self.assertEqual(expect, self.reporter.messages) | ||
self.assertEqual(1, self.reporter.call_count) | ||
|
||
def test_semantic_newline_alltests_true(self): | ||
"""When a ., ?, or ! is not the last character of the line, it is | ||
considered a semantic newline violation and an error is reported.""" | ||
content = ( | ||
'Sentence. \n' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test is wrong...as it will trigger the "trailing newspaces" checker |
||
'Sentence! \n' | ||
'Sentence? \n' | ||
) | ||
checker = ReStructuredTextChecker('bogus', content, self.reporter) | ||
checker._check_semantic_newline() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the call with underline? |
||
expect = ['Check that a new sentence is created after a full stop, ! or ?.'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the expected value is wrong. it should repot a tuple of line number and error message |
||
self.assertEqual(expect, self.reporter.messages) | ||
self.assertEqual(1, self.reporter.call_count) | ||
|
||
def test_semantic_newline_fullstop(self): | ||
"""When a full stop is not the last character of the line, it is | ||
considered a semantic newline violation and an error is reported.""" | ||
content = ( | ||
'Sentence. New sentence\n' | ||
) | ||
checker = ReStructuredTextChecker('bogus', content, self.reporter) | ||
checker._check_semantic_newline() | ||
expect = ['Newline not created after a sentence.'] | ||
self.assertEqual(expect, self.reporter.messages) | ||
self.assertEqual(1, self.reporter.call_count) | ||
|
||
def test_semantic_newline_questionmark(self): | ||
"""When a question mark is not the last character of the line, it is | ||
considered a semantic newline violation and an error is reported.""" | ||
content = ( | ||
'Sentence? New sentence\n' | ||
) | ||
checker = ReStructuredTextChecker('bogus', content, self.reporter) | ||
checker._check_semantic_newline() | ||
expect = [('Newline not created after a ? sentence.')] | ||
self.assertEqual(expect, self.reporter.messages) | ||
self.assertEqual(1, self.reporter.call_count) | ||
|
||
def test_semantic_newline_exclamationmark(self): | ||
"""When an exclamation mark is not the last character of the line, it | ||
is considered a semantic newline violation and an error is reported.""" | ||
content = ( | ||
'Sentence! New sentence\n' | ||
) | ||
checker = ReStructuredTextChecker('bogus', content, self.reporter) | ||
checker._check_semantic_newline() | ||
expect = [('Newline not created after a ! sentence.')] | ||
self.assertEqual(expect, self.reporter.messages) | ||
self.assertEqual(1, self.reporter.call_count) | ||
|
||
def test_check_section_delimiter_bad_length_both_markers(self): | ||
content = ( | ||
'---------\n' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this should be 0.4.0 as is add a new feature... 0.3.X is for bugfixes