Suggest checking *.js;*.ts when .eslintrc.js changes

When new warnings are enabled in .eslintrc.js this will usually trigger
new messages - and thus new presubmit errors - in the affected .js and
.ts files. Experts know that they can avoid this by running

  git cl presubmit --files "*.js;*.ts"

However not all developers will realize or remember this. This cl adds a
presubmit message whenever a .eslintrc.js file is changed. For instance:

  > git cl presubmit --force --files ash\webui\.eslintrc.js
  Running Python 3 presubmit commit checks ...
  ash\webui\.eslintrc.js modified. Consider running 'git cl presubmit
  --files "ash/webui/*.js;ash/webui/*.ts"' in order to check and fix the
  affected files before landing this change.

This should help reduce one of the historically common causes of
presubmit errors creeping in.

Bug: 720034, 1309977
Change-Id: I213b527abb66548c338f4a81df8463147ec37147
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3894651
Reviewed-by: Demetrios Papadopoulos <[email protected]>
Commit-Queue: Bruce Dawson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1071979}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 9f8def5d..426ba0cf 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -5048,6 +5048,30 @@
     return [output_api.PresubmitPromptWarning(message)]
 
 
+def CheckEsLintConfigChanges(input_api, output_api):
+    """Suggest using "git cl presubmit --files" when .eslintrc.js files are
+    modified. This is important because enabling an error in .eslintrc.js can
+    trigger errors in any .js or .ts files in its directory, leading to hidden
+    presubmit errors."""
+    results = []
+    eslint_filter = lambda f: input_api.FilterSourceFile(
+        f, files_to_check=[r'.*\.eslintrc\.js$'])
+    for f in input_api.AffectedFiles(include_deletes=False,
+                                     file_filter=eslint_filter):
+        local_dir = input_api.os_path.dirname(f.LocalPath())
+        # Use / characters so that the commands printed work on any OS.
+        local_dir = local_dir.replace(input_api.os_path.sep, '/')
+        if local_dir:
+            local_dir += '/'
+        results.append(
+            output_api.PresubmitNotifyResult(
+                '%(file)s modified. Consider running \'git cl presubmit --files '
+                '"%(dir)s*.js;%(dir)s*.ts"\' in order to check and fix the affected '
+                'files before landing this change.' %
+                { 'file' : f.LocalPath(), 'dir' : local_dir}))
+    return results
+
+
 # string pattern, sequence of strings to show when pattern matches,
 # error flag. True if match is a presubmit error, otherwise it's a warning.
 _NON_INCLUSIVE_TERMS = (