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

Fix #8869: Add innerHTML lint check #8870

Merged
merged 10 commits into from
Mar 28, 2020
Prev Previous commit
Next Next commit
fix conflicts and merge
  • Loading branch information
Kevin Thomas committed Mar 26, 2020
commit 3ea453ed1b7ed208f27cc97513468987b9c3ffb3
32 changes: 19 additions & 13 deletions scripts/linters/general_purpose_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
# TODO in core/tests/protractor_desktop/embedding.js pointing to the
# same issue. The following was placed due to a necessary sleep as
# a temporary measure to keep the embedding tests from failing.
'core/tests/protractor_desktop/embedding.js'
'core/tests/protractor_desktop/embedding.js',
),
'excluded_dirs': ()
},
Expand Down Expand Up @@ -165,7 +165,7 @@
'message': 'The directives must be directly referenced.',
'excluded_files': (
'core/templates/pages/exploration-player-page/'
'FeedbackPopupDirective.js'
'FeedbackPopupDirective.js',
),
'excluded_dirs': (
'extensions/answer_summarizers/',
Expand All @@ -186,7 +186,13 @@
'regexp': re.compile(r'require\(.*\.\..*\);'),
'message': 'Please, don\'t use relative imports in require().',
'excluded_files': (),
'excluded_dirs': ('core/tests/')
'excluded_dirs': ('core/tests/',)
},
{
'regexp': re.compile(r'innerHTML'),
'message': 'Please do not use innerHTML property.',
'excluded_files': ('core/templates/Polyfills.ts',),
'excluded_dirs': ('core/tests/',)
}
]

Expand Down Expand Up @@ -262,7 +268,7 @@
{
'regexp': re.compile(r'\sprint\('),
'message': 'Please use python_utils.PRINT().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
Expand All @@ -285,7 +291,7 @@
{
'regexp': re.compile(r'with open\(|= open\('),
'message': 'Please use python_utils.open_file() instead of open().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
Expand Down Expand Up @@ -328,37 +334,37 @@
{
'regexp': re.compile(r'urlsplit'),
'message': 'Please use python_utils.url_split().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
'regexp': re.compile(r'urlparse'),
'message': 'Please use python_utils.url_parse().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
'regexp': re.compile(r'urlunsplit'),
'message': 'Please use python_utils.url_unsplit().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
'regexp': re.compile(r'parse_qs'),
'message': 'Please use python_utils.parse_query_string().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
'regexp': re.compile(r'\Wunquote\('),
'message': 'Please use python_utils.urllib_unquote().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
'regexp': re.compile(r'urljoin'),
'message': 'Please use python_utils.url_join().',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
Expand Down Expand Up @@ -410,7 +416,7 @@
'used in webapp2\'s built-in methods or for strings used directly '
'in NDB datastore models. If you need to cast ints/floats to '
'strings, please use python_utils.UNICODE() instead.'),
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
Expand All @@ -422,7 +428,7 @@
{
'regexp': re.compile(r'basestring'),
'message': 'Please use python_utils.BASESTRING.',
'excluded_files': ('python_utils.py'),
'excluded_files': ('python_utils.py',),
'excluded_dirs': ()
},
{
Expand Down
10 changes: 8 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ def get_file_contents(filepath, raw_bytes=False, mode='r'):
*. Either the raw_bytes stream if the flag is set or the
decoded stream in utf-8 format.
"""
with python_utils.open_file(filepath, mode) as f:
return f.read() if raw_bytes else f.read().decode('utf-8')
if raw_bytes:
mode = 'rb'
encoding = None
else:
encoding = 'utf-8'

with python_utils.open_file(filepath, mode, encoding=encoding) as f:
return f.read()


def get_exploration_components_from_dir(dir_path):
Expand Down