-
Notifications
You must be signed in to change notification settings - Fork 581
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
Add DocGrammarBear for docstrings #1980
Conversation
test_bad1 = test('bad_file.py.test', 'bad_file.py.test.correct') | ||
test_good1 = test('good_file.py.test', 'good_file.py.test') | ||
test_good2 = test('good_file2.py.test', 'good_file2.py.test', { | ||
'languagetool_disable_rules': 'UPPERCASE_SENTENCE_START'}) |
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.
Line is longer than allowed. (80 > 79)
LineLengthBear, severity NORMAL, section linelength
.
test_bad1 = test('bad_file.py.test', 'bad_file.py.test.correct') | ||
test_good1 = test('good_file.py.test', 'good_file.py.test') | ||
test_good2 = test('good_file2.py.test', 'good_file2.py.test', { | ||
'languagetool_disable_rules': 'UPPERCASE_SENTENCE_START'}) |
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.
E501 line too long (80 > 79 characters)'
PycodestyleBear (E501), severity NORMAL, section autopep8
.
Comment on ae7a1d9. No newline found between shortlog and body at HEAD commit. Please add one. GitCommitBear, severity NORMAL, section |
b59185e
to
05f9d01
Compare
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.
Please do not read test data from files, it's very hard to read the tests this way. Rather define the file content inside the test file. You can do that using string literals or even more conveniently, by building DocComment objects and assembling them
natural_language, | ||
languagetool_disable_rules): | ||
""" | ||
This fixes the parsed documentation comment. |
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.
How?
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.
grammatically/spell correcting. need to add this 👍
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.
also please mention the tool, and its links
|
||
:param parsed: | ||
Contains parsed documentation comment. | ||
:param natural_language: |
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 not call the parameter locale
?
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.
Because we need to specify language with locale en-US
. These settings similar to the ones in LanguageToolBear.
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.
Hm, yeah I see that it's take from there. But I'd still the parameter locale
, that way users immediately know what input we expect.
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.
cool then lets have locale
👍
languagetool_disable_rules: typed_list(str)=()): | ||
""" | ||
Checks the main description and comments description of documentation | ||
with LanguageTool. |
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'd like a little summary of what language tool can fix plus a link to the documentation.
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Documentation', 'Spelling', 'Grammar'} | ||
CAN_FIX = {'Documentation', 'Spelling', 'Grammar'} |
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.
can we have a cool asciinema?
natural_language, | ||
languagetool_disable_rules): | ||
""" | ||
This fixes the parsed documentation comment. |
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.
also please mention the tool, and its links
test_good1 = test('good_file.py.test', 'good_file.py.test') | ||
test_good2 = test( | ||
'good_file2.py.test', 'good_file2.py.test', | ||
{'languagetool_disable_rules': 'UPPERCASE_SENTENCE_START'}) |
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.
Add example: Fix spelling
|
||
try: | ||
import language_check | ||
language_check |
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 line needed?
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.
also can you use this decorator instead? http://github.com/coala/coala/blob/master/coalib/testing/BearTestHelper.py#L4
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 line needed?
Yes as the same is followed in LanguageToolBear.
language_check |
05f9d01
to
a44c32d
Compare
@@ -0,0 +1,108 @@ | |||
from queue import Queue | |||
import os.path |
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 file contains unused source code.
PyUnusedCodeBear, severity NORMAL, section flakes
.
The issue can be fixed by applying the following patch:
--- a/tests/documentation/DocGrammarBearTest.py
+++ b/tests/documentation/DocGrammarBearTest.py
@@ -1,7 +1,5 @@
from queue import Queue
-import os.path
import unittest
-import shutil
from coalib.results.Diff import Diff
from coalib.settings.Section import Section
a74c55b
to
f42423d
Compare
LanguageTool | ||
correct | ||
return True | ||
except ImportError: # pragma: no cover |
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.
E261 at least two spaces before inline comment'
PycodestyleBear (E261), severity NORMAL, section autopep8
.
LanguageTool | ||
correct | ||
return True | ||
except ImportError: # pragma: no cover |
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.
The code does not comply to PEP8.
PEP8Bear, severity NORMAL, section autopep8
.
The issue can be fixed by applying the following patch:
--- a/bears/documentation/DocGrammarBear.py
+++ b/bears/documentation/DocGrammarBear.py
@@ -33,7 +33,7 @@
LanguageTool
correct
return True
- except ImportError: # pragma: no cover
+ except ImportError: # pragma: no cover
return 'Please install the `language-check` pip package.'
def process_documentation(self,
861c8fb
to
4983264
Compare
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} | ||
LICENSE = 'AGPL-3.0' | ||
ASCIINEMA_URL = 'https://asciinema.org/a/132564' | ||
CAN_DETECT = {'Documentation', 'Spelling', 'Grammar'} |
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.
We don't need a CAN_DETECT
if we're already mentioning a CAN_FIX
😉
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.
is it? I see....
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.
Yeah, because if we can fix something, we have already detected that thing. 😄
from coalib.testing.LocalBearTestHelper import execute_bear | ||
from coalib.testing.BearTestHelper import generate_skip_decorator | ||
from bears.documentation.DocGrammarBear import DocGrammarBear | ||
from string import Template |
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.
Maybe we should leave a line and then do the DocGrammarBear
import.
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.
yup looks good that way...
also Template
import should be at top I feel.
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.
We have an unofficial imports style (absent in most bears) in which we do the bear imports at the bottom. You can have a glance over the PEP8 import style. 😉
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.
yeah move it to the top
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, small changes needed
from coalib.testing.LocalBearTestHelper import execute_bear | ||
from coalib.testing.BearTestHelper import generate_skip_decorator | ||
from bears.documentation.DocGrammarBear import DocGrammarBear | ||
from string import Template |
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.
yeah move it to the top
import language_check | ||
language_check | ||
except ImportError as err: | ||
raise SkipTest(str(err)) |
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 gave review comments on this on using a decorator
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.
Oh you used it, then no need for this.
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.
Yes, this is never importet and breaks my test suite :P
'\n' + | ||
':param xyz: $param_description' + | ||
':return: $return_description' + | ||
'"""\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.
Now I am not so sure about using Template, .format()
does this job easly
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.
yeah let's just go with format https://pyformat.info/
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.
Agree, also please use a multi line string with dedent
. It's much easiert to read.
raise SkipTest(str(err)) | ||
|
||
|
||
def make_docstring(main_desc: str='', |
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.
we need to explain this function, add some docs
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, the test suite looks much nicer now. I still recommend you use pytest's parametrize to get rid of more boilerplate code.
Things I'm missing in the testsuite:
- Tests for a programming language that isn't Python
- Tests for a natural language that isn't English
and grammatic rules via LanguageTool. | ||
|
||
:param parsed: | ||
Contains parsed documentation comment. |
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.
Is this a DocComment object? If so, why not mention it?
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.
no this is DocComment.parse()
parsed documentation comment.
'\n' + | ||
':param xyz: $param_description' + | ||
':return: $return_description' + | ||
'"""\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.
Agree, also please use a multi line string with dedent
. It's much easiert to read.
return_desc='Nothing.\n'), | ||
{'languagetool_disable_rules': 'UPPERCASE_SENTENCE_START'}) | ||
|
||
test_explicit = test([ |
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.
Please add a comment explainting what the test does.
).splitlines(True) | ||
|
||
|
||
def test(test_file, expected_file, optional_setting=None): |
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 seems to be the core function of your test suite, why not give it a docstring?
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.
we are giving a docstring/file
data(explicit tests).
Maybe I should rename them to test_data
, expected_data
make_docstring(main_desc='This sentence doesn\'t have an ' | ||
'apostrophe\n')) | ||
|
||
test_correct_grammar = test( |
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.
Instead of making the same docstring twice, make it once and pass it to the function twice. This make it immediately clear, that nothing changes.
import language_check | ||
language_check | ||
except ImportError as err: | ||
raise SkipTest(str(err)) |
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.
Yes, this is never importet and breaks my test suite :P
4983264
to
f78e22d
Compare
make_docstring(main_desc='Il monte s’il veut.\n'), | ||
{'locale': 'fr', | ||
'languagetool_disable_rules': 'FRENCH_WHITESPACE'}) | ||
|
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 has been taken from
https://github.com/myint/language-check/blob/14bae49f6357c2bc592a11972c457665f7b30c28/test.py#L60
a4a1066
to
94f6f1b
Compare
# which was breaking this test case. | ||
test_language_french = unittest.skipIf( | ||
platform.system() == 'Windows', | ||
"language-check fails this test on windows")( |
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.
You do not use the preferred quotation marks.
QuotesBear, severity NORMAL, section python
.
The issue can be fixed by applying the following patch:
--- a/tests/documentation/DocGrammarBearTest.py
+++ b/tests/documentation/DocGrammarBearTest.py
@@ -119,7 +119,7 @@
# which was breaking this test case.
test_language_french = unittest.skipIf(
platform.system() == 'Windows',
- "language-check fails this test on windows")(
+ 'language-check fails this test on windows')(
test(
make_docstring(main_desc='il monte en haut si il veut.\n'),
make_docstring(main_desc='Il monte s’il veut.\n'),
51c80c1
to
3918169
Compare
3918169
to
b2f13c6
Compare
369d4f8
to
b86b53b
Compare
This bear checks for spellings and grammatical mistakes on the descriptions of documentation comments.
b86b53b
to
112fa7d
Compare
ack 112fa7d |
@rultor merge |
This bear checks for spellings and grammatical mistakes
on the descriptions of documentation comments.
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Checklist
them.
individually. It is not sufficient to have "fixup commits" on your PR,
our bot will still report the issues for the previous commit.) You will
likely receive a lot of bot comments and build failures if coala does not
pass on every single commit!
After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.
Please consider helping us by reviewing other peoples pull requests as well:
cobot mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!