-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Fix part of issue #8423 Lint concatenation checker #19908
base: develop
Are you sure you want to change the base?
Conversation
Hi @Helper2020, can you complete the following:
|
Assigning @vojtechjelinek for the first pass review of this PR. Thanks! |
Unassigning @Helper2020 since a re-review was requested. @Helper2020, please make sure you have addressed all review comments. 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.
Thanks @Helper2020! Could you please fix the lint checks that are failing on CI? 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.
Thanks! Left a few comments.
scripts/linters/pylint_extensions.py
Outdated
if (isinstance(left_inferred.value, str) and | ||
isinstance(right_inferred.value, str)): | ||
self.add_message('prefer-string-interpolation', node=node) |
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.
if (isinstance(left_inferred.value, str) and | |
isinstance(right_inferred.value, str)): | |
self.add_message('prefer-string-interpolation', node=node) | |
if ( | |
isinstance(left_inferred.value, str) and | |
isinstance(right_inferred.value, str) | |
): | |
self.add_message('prefer-string-interpolation', node=node) |
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.
Unassigning @vojtechjelinek since the review is done. |
@Helper2020 please correct the issues flagged by Oppiabot in #19908 (comment):
I'm de-assigning myself for now until these issues and CI checks are fixed |
@vojtechjelinek I'm not sure how I can handle errors from .infer() without try-except blocks. Any suggestions? |
Why can't you use try-except? |
I can, just according to the coding style guide, raising exceptions are rarely used. |
@StephenYu2018 PTAL, @vojtechjelinek PTAL, @seanlip PTAL |
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 have no new changes to request. Please address my remaining reviewer comments, as I've left some new comments under those threads. Once that's done, I'll approve these changes.
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 @Helper2020. Looks great! I just left a few notes on my codeowner files, PTAL.
score_category: str = ('%s%s%s' % ( | ||
suggestion_models.SCORE_TYPE_TRANSLATION, | ||
suggestion_models.SCORE_CATEGORY_DELIMITER, 'English') | ||
) |
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.
Deindent by 4 (to match opening scope).
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.
suggestion_models.SCORE_TYPE_TRANSLATION + | ||
suggestion_models.SCORE_CATEGORY_DELIMITER + 'English') | ||
'%s%s%s' % ( | ||
suggestion_models.SCORE_TYPE_TRANSLATION, |
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.
Indent this line and the next by 4 from the previous line, since the ( introduces a new indentation scope.
scripts/linters/html_linter.py
Outdated
@@ -410,7 +410,7 @@ def _get_trimmed_error_output(html_lint_output: str) -> str: | |||
|
|||
for line in html_output_lines: | |||
trimmed_error_messages.append(line) | |||
return '\n'.join(trimmed_error_messages) + '\n' | |||
return '\n%s%s' % (''.join(trimmed_error_messages), '\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.
Why not just put the last \n in the main string literal?
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/linters/js_ts_linter.py
Outdated
@@ -526,7 +526,7 @@ def _get_trimmed_error_output(eslint_output: str) -> str: | |||
else: | |||
error_message = line | |||
trimmed_error_messages.append(error_message) | |||
return '\n'.join(trimmed_error_messages) + '\n' | |||
return '\n%s%s' % (trimmed_error_messages, '\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.
Ditto, put the last \n in the main string literal
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/linters/pylint_extensions.py
Outdated
@@ -2919,6 +2919,55 @@ def visit_importfrom(self, node: astroid.nodes.ImportFrom) -> None: | |||
self.add_message('disallowed-text-import', node=node) | |||
|
|||
|
|||
# TODO(#16567): Here we use MyPy ignore because of the incomplete typing of |
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.
Strike the first "of"
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/linters/pylint_extensions.py
Outdated
# (Class cannot subclass 'BaseChecker' (has type 'Any')), | ||
# we added an ignore here. | ||
class PreventStringConcatenationChecker(checkers.BaseChecker): # type: ignore[misc] | ||
"""Checks for string concactenation and encourage string interpolation.""" |
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.
encourage --> encourages
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.
Args: node: astroid.BinOp The binary operation node to check. | ||
""" | ||
|
||
if isinstance(node, astroid.BinOp) and node.op == '+': |
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.
Not done? (I don't see the changes in the code.)
scripts/setup_test.py
Outdated
'-linux-x64.tar.gz', | ||
'https://nodejs.org/dist/v%s/node-v%s%s' % ( | ||
common.NODE_VERSION, common.NODE_VERSION, | ||
'-linux-x64.tar.gz'), |
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 just add this to the main string, since it is hardcoded?
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.
Hi @Helper2020. 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! |
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 PTAL, @StephenYu2018 PTAL, @vojtechjelinek PTAL
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! Took a pass. Please make sure to check if similar stuff that I mention in my comments occurs in other places too.
score_category: str = ('%s%s%s' % ( | ||
suggestion_models.SCORE_TYPE_TRANSLATION, | ||
suggestion_models.SCORE_CATEGORY_DELIMITER, 'English')) |
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.
Put the last string into the main string. Ditto elsewhere.
@@ -736,7 +736,7 @@ def put(self, topic_id: str) -> None: | |||
topic_id: str. The ID of the topic. | |||
""" | |||
assert self.normalized_payload is not None | |||
topic_url = feconf.TOPIC_EDITOR_URL_PREFIX + '/' + topic_id | |||
topic_url = '%s%s%s' % (feconf.TOPIC_EDITOR_URL_PREFIX, '/', topic_id) |
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.
Put the '/'
into the main string. Ditto elsewhere.
@@ -898,7 +898,7 @@ def _convert_collection_contents_v3_dict_to_v4_dict( | |||
# this key MyPy throw an error. | |||
skill_names.update(node['prerequisite_skills']) # type: ignore[misc] | |||
skill_names_to_ids = { | |||
name: _SKILL_ID_PREFIX + str(index) | |||
name: '{}{}'.format(_SKILL_ID_PREFIX, index) |
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 d you use format
and not %
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.
Ditto elsewhere
EXPLORATION_ROLE_MANAGER: ('%s%s%s' % ( | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_manage'], | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'], | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | ||
), | ||
EXPLORATION_ROLE_EDITOR: ('%s%s' % ( | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'], | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | ||
), | ||
EXPLORATION_ROLE_VOICE_ARTIST: ('%s%s' % ( | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_voiceover'], | ||
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | ||
), |
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.
EXPLORATION_ROLE_MANAGER: ('%s%s%s' % ( | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_manage'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | |
), | |
EXPLORATION_ROLE_EDITOR: ('%s%s' % ( | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | |
), | |
EXPLORATION_ROLE_VOICE_ARTIST: ('%s%s' % ( | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_voiceover'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | |
), | |
EXPLORATION_ROLE_MANAGER: ('%s%s%s' % ( | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_manage'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | |
), | |
EXPLORATION_ROLE_EDITOR: ('%s%s' % ( | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_edit'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | |
), | |
EXPLORATION_ROLE_VOICE_ARTIST: ('%s%s' % ( | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_voiceover'], | |
_EDITOR_ROLE_EMAIL_HTML_RIGHTS['can_play']) | |
), |
story_link = ('%s%s/%s' % ( | ||
str(feconf.OPPIA_SITE_URL), | ||
str(feconf.STORY_EDITOR_URL_PREFIX), | ||
overdue_story.id) | ||
) |
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.
story_link = ('%s%s/%s' % ( | |
str(feconf.OPPIA_SITE_URL), | |
str(feconf.STORY_EDITOR_URL_PREFIX), | |
overdue_story.id) | |
) | |
story_link = ('%s%s/%s' % ( | |
str(feconf.OPPIA_SITE_URL), | |
str(feconf.STORY_EDITOR_URL_PREFIX), | |
overdue_story.id | |
)) |
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 elsewhere
'%s%s/story_1' % ( | ||
feconf.OPPIA_SITE_URL, | ||
feconf.STORY_EDITOR_URL_PREFIX) |
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 get rid of this format inside format and just modify the main string.
@@ -6372,14 +6372,14 @@ def test_get_story_id_linked_to_exploration(self) -> None: | |||
change_list = [ | |||
story_domain.StoryChange({ | |||
'cmd': story_domain.CMD_ADD_STORY_NODE, | |||
'node_id': story_domain.NODE_ID_PREFIX + '1', | |||
'node_id': f'{story_domain.NODE_ID_PREFIX}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.
Why use f-strings and not %-format?
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 elsewhere
Unassigning @vojtechjelinek since the review is done. |
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.
LGTM!
Unassigning @StephenYu2018 since they have already approved the PR. |
Assigning @BenHenning, @U8NWXD for code owner reviews. Thanks! |
Overview
Essential Checklist