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 #7010: Adds a linting check that ensures all TODO comments have a username with them #7114

Merged
merged 30 commits into from
Jul 23, 2019

Conversation

teddymarchildon
Copy link
Contributor

@teddymarchildon teddymarchildon commented Jul 8, 2019

Fixes #7010: Adds a linting check that ensures all TODO comments have a username with them.

This adds a lint check that ensures all TODO comments have a username with them.

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 has an appropriate "CHANGELOG: ..." label (If you are unsure of which label to add, ask the reviewers for guidance).
  • The PR follows the style guide.
  • The PR addresses the points mentioned in the codeowner checks for the files/folders changed. (See the codeowner's wiki page.)
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer and don't tick this checkbox.
    • 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. Do not only request the review but also add the reviewer as an assignee.

@teddymarchildon teddymarchildon requested a review from apb7 as a code owner July 8, 2019 22:59
@teddymarchildon teddymarchildon changed the title Todo comment lint check Fixes #7010: Adds a linting check that ensures all TODO comments have a username with them Jul 8, 2019
@teddymarchildon
Copy link
Contributor Author

I'm having a hard time adding reviewers (not quite sure why) but @seanlip @apb7 @lilithxxx PTAL whenever you get a chance! Thanks so much.

@DubeySandeep
Copy link
Member

Hi @teddymarchildon, I've assigned @apb7 as a reviewer for this PR! (and sorry for the trouble!)

Also, can you please check why the lint tests are failing for this PR and fix it?

@teddymarchildon
Copy link
Contributor Author

It looks like it is failing the linter because this PR adds a lint check to ensure that TODO comments are assigned to a user. I thought the scripts/pre_commit_linter.py only is run on the files changed in the commit, but it looks like it is run on the entire codebase in the travis-ci. So, for example, core/domain/story_services_test line 1358 has a TODO comment without an assigned user, but that file is not changed in this PR.

Should I find the owner, or the last person who edited the TODO comment, of the TODO comments currently unassigned and write them in as the assigned user? It looks like the vast majority of TODO comments already have an assigned user.

@DubeySandeep
Copy link
Member

I thought the scripts/pre_commit_linter.py only is run on the files changed in the commit

Locally (as git push hook) it runs on the files changed in the feature-branch. But on travis we run these tests for the entire repo.

Should I find the owner, or the last person who edited the TODO comment, of the TODO comments currently unassigned and write them in as the assigned user?

Yeah, this sounds good to me! Also, in case you'll find it hard to assign a username for any TODO item than you can assign it to the code-owner of the file.

(For issues like #7010 we expect the contributor to introduce the new check as well as fix the existing issues. )

@oppiabot
Copy link

oppiabot bot commented Jul 9, 2019

Hi @teddymarchildon. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

@codecov
Copy link

codecov bot commented Jul 9, 2019

Codecov Report

Merging #7114 into develop will decrease coverage by 0.23%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #7114      +/-   ##
===========================================
- Coverage    98.06%   97.82%   -0.24%     
===========================================
  Files          377      376       -1     
  Lines        63208    62757     -451     
===========================================
- Hits         61987    61395     -592     
- Misses        1221     1362     +141
Impacted Files Coverage Δ
core/controllers/cron.py 36.26% <0%> (-63.74%) ⬇️
core/domain/cron_services.py 36.84% <0%> (-63.16%) ⬇️
core/controllers/reader.py 81.47% <0%> (-18.53%) ⬇️
core/controllers/reader_test.py 100% <0%> (ø) ⬆️
main.py 87.61% <0%> (ø) ⬆️
core/controllers/pages.py 100% <0%> (ø) ⬆️
core/controllers/pages_test.py 100% <0%> (ø) ⬆️
main_cron.py
core/controllers/cron_test.py
__init__.py 100% <0%> (ø)
... and 1 more

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 05cff06...6ee8e38. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 9, 2019

Codecov Report

Merging #7114 into develop will not change coverage.
The diff coverage is 95.12%.

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #7114   +/-   ##
=======================================
  Coverage     87.5%   87.5%           
=======================================
  Files          945     945           
  Lines        83414   83414           
  Branches      2349    2349           
=======================================
  Hits         72993   72993           
  Misses        9976    9976           
  Partials       445     445
Impacted Files Coverage Δ
...plates/dev/head/domain/story/StoryObjectFactory.ts 100% <ø> (ø) ⬆️
...v/head/domain/state_card/StateCardObjectFactory.ts 80.45% <ø> (ø) ⬆️
...in/exploration/WrittenTranslationsObjectFactory.ts 64.7% <ø> (ø) ⬆️
...domain/suggestion/SuggestionThreadObjectFactory.ts 93.75% <ø> (ø) ⬆️
...dev/head/domain/exploration/StatesObjectFactory.ts 84.21% <ø> (ø) ⬆️
...head/domain/statistics/PlaythroughObjectFactory.ts 100% <ø> (ø) ⬆️
...ev/head/domain/story/StoryContentsObjectFactory.ts 88.08% <ø> (ø) ⬆️
...ead/domain/exploration/ExplorationObjectFactory.ts 55.26% <ø> (ø) ⬆️
core/domain/story_services_test.py 100% <ø> (ø) ⬆️
...ates/dev/head/domain/user/UserInfoObjectFactory.ts 100% <ø> (ø) ⬆️
... and 60 more

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 d5f4315...b459568. Read the comment docs.

@teddymarchildon teddymarchildon requested a review from seanlip as a code owner July 9, 2019 20:19
Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

Hi @teddymarchildon, thanks for the PR. Left some comments, ptal.

core/domain/story_services_test.py Outdated Show resolved Hide resolved
@@ -220,6 +220,13 @@
'excluded_files': (),
'excluded_dirs': ('core/tests/')
},
{
'regexp': r'\/\/\sTODO[^\(]*[^\)]$',
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of points here:

  1. I think it would be better if we put the regexp in BAD_PATTERNS since this needs to be checked for all files, irrespective of the type.
  2. Let's enforce the TODO(@username): pattern instead of TODO(username):.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, will enforce the @ sign!

I actually thought about putting the regexp in BAD_PATTERNS, but all of those patterns are checked here as just seeing if the pattern exists in the file, not with a regular expression. I would be happy to find a pattern that works for that method if you prefer! Something like TODO: as a bad pattern

Copy link
Contributor

Choose a reason for hiding this comment

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

@teddymarchildon, I see. Can we set up a BAD_PATTERNS_REGEXP for this (since we have bad patterns regexp for different file types)? We can then use the same mechanism. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @teddymarchildon, have you looked into this? 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.

Ah I must've missed that comment, working on it now!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apb7 Updated! Much cleaner - thanks for the heads up.

scripts/pre_commit_linter.py Outdated Show resolved Hide resolved
scripts/pre_commit_linter.py Outdated Show resolved Hide resolved
scripts/pre_commit_linter.py Outdated Show resolved Hide resolved
@apb7 apb7 removed their assignment Jul 10, 2019
@kevinlee12
Copy link
Contributor

Github was having issues with their API earlier, which might be why.

@oppiabot
Copy link

oppiabot bot commented Jul 19, 2019

Hi @teddymarchildon. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks, @teddymarchildon. Nice work!

Copy link
Member

@DubeySandeep DubeySandeep left a comment

Choose a reason for hiding this comment

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

@teddymarchildon, This looks great, thanks for adding the checks and fixing the existing wrong patterns :)

I've left a few comments, PTAL.

@apb7: Can we have a follow-up issue for handling: (We can implement this latter)

  • TODO comments end with a period(.) [I think we have such checks for comments]
  • TODO message should start with a capital letter.

BAD_PATTERNS_REGEXP = [
{
'regexp': r'TODO[^\(]*[^\)][^:]*[^\w]*$',
'message': 'Please assign TODO comments to a user ' +
Copy link
Member

Choose a reason for hiding this comment

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

Do we need + here?

Copy link
Member

Choose a reason for hiding this comment

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

@apb7, do we want these test to only fail for a specific pattern or for any unexpected TODO pattern?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DubeySandeep The + sign is used so that each line length is below 80 characters as mandated by pylint

I'm happy to enforce the uppercase starting character in this regexp, and I believe all comments have to end with a period as enforced by one of the linting processes

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @DubeySandeep, thanks for the comments. Please find the responses inline:

do we want these test to only fail for a specific pattern or for any unexpected TODO pattern?

I think the scope of this PR is to ensure that all TODO comments have an associated username in a specific pattern. Let me know if you think otherwise.

Do we need + here?

Nice catch! No, I don't think we require + here. @teddymarchildon, can you please check other multi-line bad pattern messages. They do not use +.

TODO comments end with a period(.) [I think we have such checks for comments]

I think the comment check will cover this as well, right?

TODO message should start with a capital letter.

I'll file a follow-up issue for this (filed #7182). @teddymarchildon, if you're interested, please let us know on that issue thread. We'll assign it to you. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the reply @apb7, @teddymarchildon can you please update the PR as Apurv suggested so that we can quickly merge this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DubeySandeep I believe I have addressed the comments, and can start working on the next issue once this one is merged. Let me know if there is anything else to fix up or if I missed something from those comments!

if _check_bad_pattern_in_file(
filepath, file_content, regexp):
failed = True
total_error_count += 1
Copy link
Member

Choose a reason for hiding this comment

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

@apb7, total_error_count is the number of files with bad patterns? (that's also not true though) or it's the number of failed patterns?

(I mean in one file there can be multiple errors for a single bad_pattern regexp.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's the total number of failed patterns (for reference, please see other regexp checks). Thanks!

@DubeySandeep DubeySandeep removed their assignment Jul 20, 2019
@@ -46,7 +46,7 @@ <h2 translate="I18N_GET_STARTED_PAGE_PARAGRAPH_8_HEADING"></h2>
<p translate="I18N_GET_STARTED_PAGE_PARAGRAPH_8">
</p>

<!-- todo: make it easy to get the right link to share, update this doc with that info -->
<!-- TODO(vojtechjelinek): make it easy to get the right link to share, update this doc with that info -->
Copy link
Member

Choose a reason for hiding this comment

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

@apb7, I think the "Period at the end of comment" doesn't work here!

@@ -48,7 +48,7 @@ describe('rich-text components', function() {
explorationEditorMainTab.setContent(function(richTextEditor) {
richTextEditor.appendBoldText('bold');
richTextEditor.appendPlainText(' ');
// TODO (Jacob) add test for image RTE component
// TODO(Jacob): add test for image RTE component
Copy link
Member

Choose a reason for hiding this comment

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

@apb7, Ditto.

@@ -95,11 +95,11 @@ describe('Oppia static pages tour', function() {

afterEach(function() {
general.checkForConsoleErrors([
// TODO (Jacob) Remove when
// TODO(Jacob): Remove when
// https://code.google.com/p/google-cast-sdk/issues/detail?id=309 is fixed
Copy link
Member

Choose a reason for hiding this comment

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

@apb7, I see this in multiple places, ca we add this also as a part of #7182?

@seanlip
Copy link
Member

seanlip commented Jul 23, 2019

I'm a little confused about what the next step is here. I see some comments by @DubeySandeep addressed to @apb7 and I don't know whether the ball is still in @teddymarchildon's court or not.

I'm assigning @apb7 to reply to @DubeySandeep's comments. @teddymarchildon -- would you mind replying to this thread and leaving a top-level comment if you're done with everything and would just like to get a review? I'm happy to merge this once @apb7 and @DubeySandeep confirm.

Thanks!

@teddymarchildon
Copy link
Contributor Author

My bad, I forgot to add a comment once I was done addressing comments. I just added one replying, but I think I have addressed the issues @DubeySandeep and @apb7 brought up - if not let me know and I can fix it up!

I can start working on the next issue once this one is merged.

@seanlip
Copy link
Member

seanlip commented Jul 23, 2019

Great, thanks @teddymarchildon! In that case, deassigning you and adding @DubeySandeep @apb7 for final review/confirmation.

Also, please note that you can work on more than one issue at a time! Just make sure to do that on a new, separate feature branch created from develop, as described here.

Copy link
Member

@DubeySandeep DubeySandeep left a comment

Choose a reason for hiding this comment

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

I think the issue stated in #7010 is resolved and we can merge this PR. LGTM!

@DubeySandeep
Copy link
Member

@seanlip, Can we merge this PR directly (As stated here)?

Note: @apb7 has already approved this PR!

@DubeySandeep
Copy link
Member

@teddymarchildon, Congrats on your first successful PR to Oppia! :)

@seanlip
Copy link
Member

seanlip commented Jul 23, 2019

OK, merging! Congrats @teddymarchildon :D

@seanlip seanlip merged commit d89d68f into oppia:develop Jul 23, 2019
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.

Implement a lint check to ensure all TODOs contain a username within it
7 participants