Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 1 | # Copyright 2017 The Chromium Authors |
dbeam | ccf7fef | 2017-05-17 22:24:29 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | |
dpapad | e9f53c8 | 2024-10-09 23:41:13 | [diff] [blame] | 6 | PRESUBMIT_VERSION = '2.0.0' |
| 7 | |
| 8 | |
dbeam | ccf7fef | 2017-05-17 22:24:29 | [diff] [blame] | 9 | def CheckChangeOnUpload(*args): |
| 10 | return _CommonChecks(*args) |
| 11 | |
| 12 | |
| 13 | def CheckChangeOnCommit(*args): |
| 14 | return _CommonChecks(*args) |
| 15 | |
| 16 | |
| 17 | def _CommonChecks(input_api, output_api): |
Dan Harrington | d8a17cb | 2021-06-23 19:36:54 | [diff] [blame] | 18 | tests = ['test_suite.py'] |
dbeam | ccf7fef | 2017-05-17 22:24:29 | [diff] [blame] | 19 | |
Takuto Ikuta | e108f10 | 2023-06-01 21:38:30 | [diff] [blame] | 20 | return input_api.canned_checks.RunUnitTests(input_api, output_api, tests) |
dpapad | e9f53c8 | 2024-10-09 23:41:13 | [diff] [blame] | 21 | |
| 22 | |
| 23 | def CheckEsLintConfigChanges(input_api, output_api): |
| 24 | """Suggest using "git cl presubmit --files" when the global configuration |
| 25 | file eslint.config.mjs file is modified. This is important because |
| 26 | modifications to this file can trigger ESLint errors in any .js or .ts |
| 27 | files in the repository, leading to hidden presubmit errors.""" |
| 28 | results = [] |
| 29 | |
| 30 | eslint_filter = lambda f: input_api.FilterSourceFile( |
| 31 | f, files_to_check=[r'tools/web_dev_style/eslint.config.mjs$']) |
| 32 | for f in input_api.AffectedFiles(include_deletes=False, |
| 33 | file_filter=eslint_filter): |
| 34 | results.append( |
| 35 | output_api.PresubmitNotifyResult( |
| 36 | '%(file)s modified. Consider running \'git cl presubmit ' |
| 37 | '--files "*.js;*.ts"\' in order to check and fix the affected ' |
| 38 | 'files before landing this change.' % {'file': f.LocalPath()})) |
| 39 | return results |