Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
Contributing the Scame project
==============================

Check the Makefile for available helpers.

Check the Makefile for tips.

make deps

Run the test::

make test

Code style
----------
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ env:


deps: env
@build/bin/pip install -Ue '.[dev]'
@build/bin/pip install bandit scame nose
@build/bin/python -m pip install -Ue '.[dev]'


Expand All @@ -23,7 +25,7 @@ check:
@echo "========= bandit =================="
#@build/bin/bandit -n 0 -f txt -r scame/
@echo "========= pylint ============="
@build/bin/pylint scame/
#@build/bin/pylint scame/

test: run
@build/bin/nosetests scame/
test: run check
@build/bin/nosetests --with-id scame/
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ It has the following goals:

* Support checking different source parts using different configurations.

* Use soft dependencies on the checker.
Only import it when enabled.

* Use soft dependencies on the checker. Only import it when enabled.

* You can ignore a single line for all reports using ` # noqa` marker.
Expand Down
9 changes: 7 additions & 2 deletions release-notes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
scame-0.4.2 - 2017/11/01
========================

* Add a semantic newline checker.

scame-0.4.1 - 2017/10/29
========================

Expand Down Expand Up @@ -68,8 +73,8 @@ Fixed rules to ensure Zope zcml and pt are recongnised as XML.
pocket-lint-0.1: The first release
==================================

Pocket-lint a composite linter and style checker. It has several notable
features:
Pocket-lint a composite linter and style checker.
It has several notable features:

* Provides a consistent report of issues raised by the subordinate
checkers.
Expand Down
7 changes: 6 additions & 1 deletion scame/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parse_command_line(args):
version=VERSION,
)
parser.add_option(
"-q", "--quiet", action="store_false", dest="verbose",
"-q", "--quiet", action="store_true", dest="quiet",
help="Show errors only.")
parser.add_option(
"--progress", action="store_true", dest="progress",
Expand Down Expand Up @@ -87,6 +87,9 @@ def parse_command_line(args):
exclude.append(part)

options.scope['include'] = sources
options.verbose = not command_options.quiet

options.pycodestyle['enabled'] = True
options.scope['exclude'] = exclude

return options
Expand Down Expand Up @@ -253,6 +256,8 @@ def main(args=None):
args = sys.argv[1:]

options = parse_command_line(args=args)
if len(options.scope['include']) == 0:
sys.stderr.write("Expected file paths.\n")

if not options.scope['include'] and not options.diff_branch:
sys.stderr.write("Expected file paths or branch diff reference.\n")
Expand Down
1 change: 1 addition & 0 deletions scame/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Keeps the version of the project.
"""

VERSION = '0.4.1'
20 changes: 17 additions & 3 deletions scame/formatcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,14 @@ def _isExceptedLine(self, line, category, code):
A category can be ignored using MARKER:CATEGORY
A code from a category can be ignored using MARKER:CATEGORY=ID1,ID
"""
if line.find(' # ' + self._IGNORE_MARKER) == -1:
if self._IGNORE_MARKER not in line:
# Not an excepted line.
return False

comment = line

if comment.find(':' + self._IGNORE_MARKER) == -1:
if comment.find(self._IGNORE_MARKER + ':') == -1:
# We have a generic exception.
return True
Expand All @@ -400,6 +402,7 @@ def _isExceptedLine(self, line, category, code):
# a category.
return False

if comment.find('%s:%s' % (category, self._IGNORE_MARKER)) == -1:
if comment.find('%s:%s' % (self._IGNORE_MARKER, category)) == -1:
# Not this category.
return False
Expand Down Expand Up @@ -1037,7 +1040,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',
)

Expand Down Expand Up @@ -1177,6 +1180,7 @@ def check_lines(self):
self.check_tab(line_no, line)
self.check_conflicts(line_no, line)
self.check_regex_line(line_no, line)
self.check_semantic_newline(line_no, line)

if self.isTransition(line_no - 1):
self.check_transition(line_no - 1)
Expand All @@ -1185,6 +1189,16 @@ def check_lines(self):
else:
pass

def check_semantic_newline(self, line_no, line):
"""
All lines should have semantic newlines.
"""
# Any ., ?, or ! with a space following after is a bad line,
# as it signals the end of a sentence and anything after that
# should start on a separate line.
if '. ' in line:
self.message(line_no, 'Sentence without a new line.', icon='info')

def isTransition(self, line_number):
'''Return True if the current line is a line transition.'''
line = self.lines[line_number]
Expand Down Expand Up @@ -1245,14 +1259,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
Expand Down
17 changes: 5 additions & 12 deletions scame/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
unicode_literals,
)

from scame.formatcheck import IS_PY3, JSONChecker
from scame.formatcheck import JSONChecker
from scame.tests import CheckerTestCase


Expand Down Expand Up @@ -93,17 +93,10 @@ def test_compile_error_with_line(self):
content = '{\n1: "something"}\n'
checker = JSONChecker('bogus', content, self.reporter)
checker.check()

if IS_PY3:
self.assertEqual(
[(2, 'Expecting property name enclosed in double quotes: '
'line 2 column 1 (char 2)')],
self.reporter.messages)
else:
self.assertEqual(
[(2, 'Expecting property name: line 2 column 1 (char 2)')],
self.reporter.messages)

self.assertEqual(
[(2, 'Expecting property name enclosed in double quotes: '
'line 2 column 1 (char 2)')],
self.reporter.messages)
self.assertEqual(1, self.reporter.call_count)

def test_compile_error_on_multiple_line(self):
Expand Down
Loading