-
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 (happy hacking) #2
Conversation
Initial try. Would be good to know how to run a use test case against this.
@adiroiban How to check if this works? |
This needs to be branched from and merged into the chevah-master branch - To check that it works you first write automated tests . See https://github.com/chevah/pocket-lint/blob/chevah-master/pocketlint/tests/test_restructuredtext.py For manual tests, you can update setup.py to let's say Now... once you have the package you can manually install it into the
Note that Let me know if you need more help Thanks! |
pocketlint/formatcheck.py
Outdated
@@ -939,6 +945,7 @@ def check_lines(self): | |||
for line_no, line in enumerate(self.lines): | |||
line_no += 1 | |||
self.check_length(line_no, line) | |||
self.check_semantic_newline() |
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.
this is fine, but don't forget to pass the line_no, line
arguments to this check.
line_no is important so that the error report will pin-point the place with the error
pocketlint/formatcheck.py
Outdated
@@ -460,6 +460,12 @@ def check_regex_line(self, line_no, line): | |||
icon='info', | |||
) | |||
|
|||
def check_semantic_newline(self): | |||
"""Check for a sentence with no new line.""" | |||
if self.text.find('. ') and self.text[-1] != '\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.
self.text is the whole file... as commented below you should pass the line_no and line here and do the search only inside that line.
searching only for line.find('. ')
should be enough... no need for line[-1]
we might also want to search for question mark and exclamation mark.
once this is done, do a full check on our full documentation to see for any false positives
@hcs0 you should now have write access to this repo... some time ago, GitHub has updated the permissions model... and we have to manually assign the permissions on all our existing repos this was left without an update... and there might be more. you should now have admin rights to this repo |
Thanks, I will pick this up again next happy hacking day |
- Check for ? and ! - Ignore double stops
@adiroiban Please take a quick look to see if what I have is OK. |
pocketlint/formatcheck.py
Outdated
@@ -460,6 +460,12 @@ def check_regex_line(self, line_no, line): | |||
icon='info', | |||
) | |||
|
|||
def check_semantic_newline(self): |
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.
bad indentation
pocketlint/formatcheck.py
Outdated
def check_semantic_newline(self): | ||
"""Check for a sentence with no new line.""" | ||
if self.line.find(['. ', '? ', '! ']) != (['\n', '..']): | ||
self.message( |
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 don't understand what logic is used here.
It helps to add a comment describing what are you targeting here.
looking forward for the tests, as I hope that they can provide more documentation
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.
This checks for
.
?
!
and excludes new lines and ..
(for the adnotations)
not sure if I did it correctly though so I think tests would be useful
Previously it was only checking for full stop and space .
@adiroiban I added a few tests and created a new paver distro to check lint. But having issues running Now for the code, I'd rather test this using |
needs-review |
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.
Looks good.
Please extend the test to also cover valid use cases, not only the negative tests.
You should have write access to the repo, so feel free to create a branch directly into this repo.. and not into a fork.
also, please merge into master
branch and not trunk
.
Since moving to 'scamewe now use
master` as te main branch.
great work!
@@ -460,6 +460,14 @@ def check_regex_line(self, line_no, line): | |||
icon='info', | |||
) | |||
|
|||
def check_semantic_newline(self): | |||
"""Check for a sentence with a ., ?, or ! with a space. |
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 for the new code we can slowly migrate to our latest styleguide.
for this docstring, i want to read a human readable version of what rules are used to check for semantic newlines
@@ -343,6 +347,39 @@ 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_fullstop(self): | |||
"""Check for a sentence with a . and no new line.""" |
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.
this docstring does not help to much.
see http://styleguide.chevah.com/testing.html#tests-description-docstrings
It should sound something like.
"""
When a full stop is not the last character from the line, it is considered a semantic newline violation and an error is reported.
"""
def test_semantic_newline_fullstop(self): | ||
"""Check for a sentence with a . and no new line.""" | ||
content = ( | ||
'Sentence. New sentence\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.
for this input, it would help to have some valid semantic newlines just to make sure that we don't get false positives
) | ||
checker = ReStructuredTextChecker('bogus', content, self.reporter) | ||
checker.check_semantic_newline() | ||
expect = [('Newline not created after a sentence.')] |
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.
what is the point of these parenthesis here?
I know that existing tests are not a good example, but for new tests please consider using the structure recomended by the styleguide http://styleguide.chevah.com/testing.html#structure-of-a-test
@@ -52,7 +52,7 @@ def run(self): | |||
setup( | |||
name="pocketlint", | |||
description="Pocket-lint a composite linter and style checker.", | |||
version="1.4.4", | |||
version="1.4.4.c13", |
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.
why add .c13 here.
there is a bug here as name
should be scame
and not pocketlint
you might be working on an old fork
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 added .c13 from your comment :)
#2 (comment)
I'll look into moving this into a newer fork / and merging into the correct branch next HH day
@adiroiban Should there also be codecov in scame repo? |
yes.... but to have codecov we need to enable travis-ci ... and to enable travis-ci we first need to fix all our tests :) |
Closing this since the new branch will merge to the master trunk |
Scope
This branch adds a semantic newline checker in scame.
Changes
Add the rule in formatcheck.py
Add tests in test_restructuredtext.py
How to try and test the changes
reviewers: @adiroiban
I followed the rules to do a manual test by running
sdist
and then linking to the new paver dist.I am having trouble validating the code when I run
paver lint --all
in that I can't see what the proper output is.See #5
I am also trying to follow the format with existing test like
def test_multiple_empty_last_lines(self)