-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fixes #5843 Changes _check_comment to check for spaces and capitals #5852
Conversation
@ctao5660 please could you update the PR title? It should include a summary of what the PR is about.
|
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.
Left some initial comments, PTAL
scripts/pre_commit_linter.py
Outdated
@@ -979,6 +982,26 @@ def _check_comments(all_files): | |||
print '%s --> Line %s: %s' % ( | |||
filename, line_num + 1, message) | |||
|
|||
# Check that comment starts with a space. | |||
if line.startswith('#') and len(line) > 1 and line[1] != ' ': |
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.
A regex expression might be more suited here.
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.
Done, but if the goal was to reduce length of the conditional statement we haven't saved much length because it still needs to check if the line starts with # and the length is > 1 before it can match the regex because of comments like "#" where the line is only 1 character.
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.
Hi @ctao5660 you can reduce the length of conditional statement by checking all the three conditions with a single regex pattern something like this->'^#[^\s].*$'
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.
Ah, I didn't even think about that. I did that and added another regex for the capital checker as well.
Codecov Report
@@ Coverage Diff @@
## develop #5852 +/- ##
===========================================
- Coverage 45.74% 45.73% -0.01%
===========================================
Files 515 516 +1
Lines 30136 30147 +11
Branches 4533 4535 +2
===========================================
+ Hits 13785 13788 +3
- Misses 16351 16359 +8
Continue to review full report at Codecov.
|
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.
Made a comment and also look at the checks which are failing. You need to enforce this check to other files in the codebase too.
scripts/pre_commit_linter.py
Outdated
print '%s --> Line %s: %s' % ( | ||
filename, line_num + 1, message) | ||
|
||
if not line.startswith('# coding:') and not ( |
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.
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.
Hi @seanlip, some comments can begin with small letter like on the above examples, they are especially keywords. Should those keywords be enclosed between something(maybe?) to avoid confusion and distinguish them and comments can begin with capital or a quote(or whatever we are enclosing it between)?
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 these are manually fixable. For the first one we can replace oppia_tools/ with "The oppia_tools/ folder". For the second, we can remove the typeinfo from the inline comments; it's out of line with other similar classes.
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.
@seanlip In my capital checking regex it's only checking for full words, so things like function names with "_" and "." in them are excluded. Would this be a viable strategy or should I go ahead and manually change all these commented function names like you asked?
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 sounds fine as well!
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.
Fixed ALL pylint capitalization errors in our codebase that failed Travis CI by hand.
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.
It's looking good, thanks @ctao5660! Left a couple of comments.
@@ -238,7 +238,7 @@ def convert_to_textangular(html_data): | |||
elif tag.name == 'td' and tag.next_sibling: | |||
tag.insert_after(' ') | |||
tag.unwrap() | |||
# div and table rows both are replaced with p tag | |||
# Rows div and table both are replaced with p tag |
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.
Perhaps: "Divs and table rows are both replaced with ..."
(I don't think "div rows" is a thing.)
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.
Done
core/domain/stats_jobs_one_off.py
Outdated
@@ -161,7 +161,7 @@ def map(exploration_model): | |||
old_state_name = ( | |||
exp_versions_diff.new_to_old_state_names[ | |||
state_name]) | |||
# pssm is previous state stats mapping. | |||
# pssm: previous state stats mapping. |
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.
'pssm' means 'previous state stats mapping'.
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.
Done.
scripts/build_test.py
Outdated
@@ -61,15 +61,15 @@ def test_minify(self): | |||
"""Tests _minify with an invalid filepath.""" | |||
with self.assertRaises(subprocess.CalledProcessError) as called_process: | |||
build._minify(INVALID_INPUT_FILEPATH, INVALID_OUTPUT_FILEPATH) | |||
# returncode is the exit status of the child process. | |||
# .returncode is the exit status of the child process. |
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 you use backquotes? E.g.:
`returncode` is the exit status of the child process.
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.
Done.
scripts/build_test.py
Outdated
self.assertEqual(called_process.exception.returncode, 1) | ||
|
||
def test_minify_and_create_sourcemap(self): | ||
"""Tests _minify_and_create_sourcemap with an invalid filepath.""" | ||
with self.assertRaises(subprocess.CalledProcessError) as called_process: | ||
build._minify_and_create_sourcemap( | ||
INVALID_INPUT_FILEPATH, INVALID_OUTPUT_FILEPATH) | ||
# returncode is the exit status of the child process. | ||
# .returncode is the exit status of the child process. |
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.
Ditto.
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.
Done.
scripts/pre_commit_linter.py
Outdated
@@ -979,6 +984,24 @@ def _check_comments(all_files): | |||
print '%s --> Line %s: %s' % ( | |||
filename, line_num + 1, message) | |||
|
|||
# Check that comment starts 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.
Perhaps explain the significance of #!
, too.
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.
Done.
@@ -238,7 +238,7 @@ def convert_to_textangular(html_data): | |||
elif tag.name == 'td' and tag.next_sibling: | |||
tag.insert_after(' ') | |||
tag.unwrap() | |||
# Rows div and table both are replaced with p tag | |||
# Divs and table rows both are replaced with p tag |
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.
both are --> are both
(Also, if you don't mind, could you please correct the spelling of "apperance" in the line below? I know this was there before, but we might as well fix it. Thanks!)
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.
Done.
scripts/pre_commit_linter.py
Outdated
@@ -984,7 +984,8 @@ def _check_comments(all_files): | |||
print '%s --> Line %s: %s' % ( | |||
filename, line_num + 1, message) | |||
|
|||
# Check that comment starts with a space. | |||
# Check that comment starts with a space | |||
# and is not a shebang, which doesn't work 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.
This is still just repeating what a "#!" is. In general, though, when writing comments, try to explain the significance, or "why", of the decisions that are being made in the code.
For example, in this case, you can say something like: "Check that the comment starts with a space, unless it is part of the shebang expression at the start of a bash script." That explains to the reader why that particular case is excluded.
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.
Done I think, TAL
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.
All good. Thanks @ctao5660!
@lilithxxx, could you please take a final look at 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.
Thanks @ctao5660, LGTM!
…als (oppia#5852) * added space check and capital check * replaced space checker with regex matche * replaced both space checker and capital checker with regex expressions * fixed capital checker regex to allow special cases * fixed space regex to not catch shebang as error * Fixed pylint errors for comments in entire codebase * code review fixes * added quotes * various spellcheck and clarifications * various spellcheck and clarifications
Explanation
Fixes #5843 , Added two if statements to enforce spaces at beginning of comment and to enforce capital letter at beginning of comment, also updated docstring to reflect the new functionality.
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.