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

Conversation

hcs0
Copy link

@hcs0 hcs0 commented Aug 23, 2017

Scope

This branch adds a semantic newline checker in scame

Changes

Add the rule in formatcheck.py
Add tests in test_restructuredtext.py
Updates from the last feedback provided on #2

How to try and test the changes

reviewers: @adiroiban

@hcs0 hcs0 requested a review from adiroiban August 23, 2017 12:23
@hcs0 hcs0 self-assigned this Aug 23, 2017
@hcs0
Copy link
Author

hcs0 commented Aug 23, 2017

needs-review

@hcs0 hcs0 changed the title [#4044] Semantic Newline Checker [#4044] Add semantic newline checker in lint Aug 23, 2017
@adiroiban
Copy link
Member

look good. thanks!

Please make sure that for python you are using spaces instead of tabs. Your code was a mix of tags and spaces, and this can lead to strange bugs.

just a few minor design related comments.

I have pushed a few cleanups....and will look at fixing the tests.

I will look at enabling travis-ci tests for this project so that we can get a feedback faster.


You can test the change on chevah/server using

$ ./build/bin/scame ../server/chevah/server/static/documentation/

Before merging this we need to clean up the scame project so that all tests are green

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my final comment

@@ -44,6 +44,13 @@
| verse, and adornment-free lists.


Newline test! No newline.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this data is called valid_rst_content but from what I can see here, you are adding invalid elements to it.


but, you have introduced invalid content here, yet no test using this data was updated. Something is not right here.


check_semantic_newline is not actually used.

I think that it should be defined in the RST checker and enabled there

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not really clear to me what this section does.
I assume that this is where you add some tests. However test_semantic_newline_fullstop_true(self): contains some tests.
I don't need to add to this section

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That data is used in test_valid_content. As described in the comment, it is not placed closed to test_valid_content, but rather at the top to make it easier to debug the test

Is ok to update the content of this data. but it should be updated only with valid data.

this is a regression test to check that we don't have false-positives

self.assertEqual(expect, self.reporter.messages)
self.assertEqual(1, self.reporter.call_count)

def test_semantic_newline_exclamationmark_true(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what to say about all these tests. I feel like there is a lot of duplication in these tests.

So maybe just have a single test in which the content is

content = (
    'Sentence! \n'
    'Sentence. \n'
    'Sentence? \n'
    )

'Sentence. New sentence\n'
)
checker = ReStructuredTextChecker('bogus', content, self.reporter)
checker.check_semantic_newline()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code from scame is old and it has a lot of bad habits.
see the comment for valid_rst_content.

The design should be that check_semantic_newline to be renamed _check_semantic_newline and made private member.

The tests should use instead the base check method or only the methods from BaseChecker

@@ -1,4 +1,4 @@
"""
Keeps the version of the project.
"""
VERSION = '0.3.1'
VERSION = '0.3.4'
Copy link
Member

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

@hcs0
Copy link
Author

hcs0 commented Sep 7, 2017

I've built the package and installing it /build-macos1012-x64/bin/python -m pip install -U ~/ProAtria/scame/dist/scame-0.4.0.tar.gz then paver lint --all with a test document, but still not registering the new changes due to this issue #5

Please try on your branch.

needs-review

@@ -461,6 +461,13 @@ def check(self):
class AnyTextMixin:
"""Common checks for many checkers."""

def check_semantic_newline(self):
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check latest commits.

I have fixed all the other tests, so the remaining tests which are failing are the one for this branch.


I don't really understand what your code and your test is trying to do :(

I have replaced it with a basic implementation, which works for one test (test_check_semantic_newline_fullstop)

you can target a single test using

build/bin/nosetests scame.tests.test_restructuredtext:TestReStructuredTextChecker.test_check_semantic_newline_questionmark

def check_semantic_newline(self):
"""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', '..']):
Copy link
Member

Choose a reason for hiding this comment

The 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.line, second how is string.find() used, third what is at right-hand side (why the list, why the parenthesis)

Exclude those with no new line and two full-stops."""
if self.line.find(['. ', '? ', '! ']) != (['\n', '..']):
self.message(
0, 'Line contains a sentence without a new line.', icon='info')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why report at line 0 ?

'Sentence? \n'
)
checker = ReStructuredTextChecker('bogus', content, self.reporter)
checker._check_semantic_newline()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the call with underline?

"""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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is wrong...as it will trigger the "trailing newspaces" checker

)
checker = ReStructuredTextChecker('bogus', content, self.reporter)
checker._check_semantic_newline()
expect = ['Check that a new sentence is created after a full stop, ! or ?.']
Copy link
Member

Choose a reason for hiding this comment

The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants