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

Fixes #5843 Changes _check_comment to check for spaces and capitals #5852

Merged
merged 10 commits into from Nov 15, 2018

Conversation

ctao5660
Copy link
Contributor

@ctao5660 ctao5660 commented Nov 10, 2018

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

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR follows the style guide.
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue.

@seanlip
Copy link
Member

seanlip commented Nov 11, 2018

@ctao5660 please could you update the PR title? It should include a summary of what the PR is about.

The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)

@ctao5660 ctao5660 changed the title Fix #5843 Fixes #5843 Changes _check_comment to check for spaces and capitals Nov 11, 2018
Copy link
Contributor

@lilithxxx lilithxxx left a 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 Show resolved Hide resolved
@@ -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] != ' ':
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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].*$'

Copy link
Contributor Author

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-io
Copy link

codecov-io commented Nov 11, 2018

Codecov Report

Merging #5852 into develop will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
...v/head/pages/creator_dashboard/CreatorDashboard.js 18.59% <0%> (-0.47%) ⬇️
..._editor/feedback_tab/ThreadStatusDisplayService.js 100% <0%> (ø) ⬆️
...head/pages/collection_player/CollectionLocalNav.js 50% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7588f62...26ea262. Read the comment docs.

Copy link
Contributor

@lilithxxx lilithxxx left a 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.

print '%s --> Line %s: %s' % (
filename, line_num + 1, message)

if not line.startswith('# coding:') and not (
Copy link
Contributor

Choose a reason for hiding this comment

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

There can be cases like here and here where the comments should begin with a small letter. Look for similar cases and try to find a solution.

Copy link
Contributor

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)?

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

Copy link
Contributor Author

@ctao5660 ctao5660 Nov 14, 2018

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?

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 sounds fine as well!

Copy link
Contributor Author

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.

Copy link
Member

@seanlip seanlip left a 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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -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.
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -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.
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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.
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -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.
Copy link
Member

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.

Copy link
Contributor Author

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

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!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done I think, TAL

Copy link
Member

@seanlip seanlip left a 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!

@seanlip
Copy link
Member

seanlip commented Nov 15, 2018

@lilithxxx, could you please take a final look at this?

Copy link
Contributor

@lilithxxx lilithxxx left a comment

Choose a reason for hiding this comment

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

Thanks @ctao5660, LGTM!

@seanlip seanlip merged commit 0804599 into oppia:develop Nov 15, 2018
ctao5660 added a commit to ctao5660/oppia that referenced this pull request Nov 23, 2018
…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
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.

Checks to enforce a single space after '#' in a comment and to capitalise it
5 participants