WebUI: Apply ESLint presubmit checks to TypeScript files
Previously only JavaScript files would be checked. With this change, the same checks that apply on JS files will be applied on TS files. The addition of TypeScript specific checks will be evaluated and possibly added in follow up CLs. Bug: 1201269 Change-Id: Id04f29056cb03099de799c8d835339b5432091c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2952840 Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Commit-Queue: dpapad <dpapad@chromium.org> Cr-Commit-Position: refs/heads/master@{#891989}
This commit is contained in:
@ -56,4 +56,9 @@ module.exports = {
|
||||
|
||||
// TODO(dpapad): Add more checks according to our styleguide.
|
||||
},
|
||||
|
||||
'overrides': [{
|
||||
'files': ['**/*.ts'],
|
||||
'parser': './third_party/node/node_modules/@typescript-eslint/parser',
|
||||
}]
|
||||
};
|
||||
|
@ -98,7 +98,7 @@ class JSChecker(object):
|
||||
|
||||
affected_files = self.input_api.AffectedFiles(file_filter=self.file_filter,
|
||||
include_deletes=False)
|
||||
affected_js_files = filter(lambda f: f.LocalPath().endswith(".js"),
|
||||
affected_js_files = filter(lambda f: f.LocalPath().endswith((".js", ".ts")),
|
||||
affected_files)
|
||||
|
||||
if affected_js_files:
|
||||
|
@ -21,8 +21,8 @@ class JsCheckerEsLintTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
os.remove(self._tmp_file)
|
||||
|
||||
def _runChecks(self, file_contents):
|
||||
tmp_args = {'suffix': '.js', 'dir': _HERE_PATH, 'delete': False}
|
||||
def _runChecks(self, file_contents, file_type):
|
||||
tmp_args = {'suffix': '.' + file_type, 'dir': _HERE_PATH, 'delete': False}
|
||||
with tempfile.NamedTemporaryFile(**tmp_args) as f:
|
||||
self._tmp_file = f.name
|
||||
f.write(file_contents)
|
||||
@ -47,11 +47,18 @@ class JsCheckerEsLintTest(unittest.TestCase):
|
||||
self.assertEqual(line, message.get('line'))
|
||||
|
||||
def testGetElementByIdCheck(self):
|
||||
results = self._runChecks("const a = document.getElementById('foo');")
|
||||
results = self._runChecks("const a = document.getElementById('foo');", 'js')
|
||||
self._assertError(results, 'no-restricted-properties', 1)
|
||||
|
||||
results = self._runChecks(
|
||||
"const a: HTMLELement = document.getElementById('foo');", 'ts')
|
||||
self._assertError(results, 'no-restricted-properties', 1)
|
||||
|
||||
def testPrimitiveWrappersCheck(self):
|
||||
results = self._runChecks('const a = new Number(1);')
|
||||
results = self._runChecks('const a = new Number(1);', 'js')
|
||||
self._assertError(results, 'no-new-wrappers', 1)
|
||||
|
||||
results = self._runChecks('const a: number = new Number(1);', 'ts')
|
||||
self._assertError(results, 'no-new-wrappers', 1)
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ import resource_checker
|
||||
|
||||
|
||||
def IsResource(f):
|
||||
return f.LocalPath().endswith(('.html', '.css', '.js'))
|
||||
return f.LocalPath().endswith(('.html', '.css', '.js', '.ts'))
|
||||
|
||||
|
||||
def CheckStyle(input_api, output_api, file_filter=lambda f: True):
|
||||
@ -29,11 +29,13 @@ def CheckStyle(input_api, output_api, file_filter=lambda f: True):
|
||||
|
||||
|
||||
def CheckStyleESLint(input_api, output_api):
|
||||
is_js = lambda f: f.LocalPath().endswith('.js')
|
||||
js_files = input_api.AffectedFiles(file_filter=is_js, include_deletes=False)
|
||||
if not js_files:
|
||||
should_check = lambda f: f.LocalPath().endswith(('.js', '.ts'))
|
||||
files_to_check = input_api.AffectedFiles(file_filter=should_check,
|
||||
include_deletes=False)
|
||||
if not files_to_check:
|
||||
return []
|
||||
return js_checker.JSChecker(input_api, output_api).RunEsLintChecks(js_files)
|
||||
return js_checker.JSChecker(input_api,
|
||||
output_api).RunEsLintChecks(files_to_check)
|
||||
|
||||
|
||||
def DisallowIncludes(input_api, output_api, msg):
|
||||
|
Reference in New Issue
Block a user