summaryrefslogtreecommitdiffstats
path: root/python/mozlint/mozlint/editor.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /python/mozlint/mozlint/editor.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/mozlint/mozlint/editor.py')
-rw-r--r--python/mozlint/mozlint/editor.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/python/mozlint/mozlint/editor.py b/python/mozlint/mozlint/editor.py
new file mode 100644
index 0000000000..1738892f93
--- /dev/null
+++ b/python/mozlint/mozlint/editor.py
@@ -0,0 +1,57 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import subprocess
+import tempfile
+
+from mozlint import formatters
+
+
+def get_editor():
+ return os.environ.get("EDITOR")
+
+
+def edit_issues(result):
+ if not result.issues:
+ return
+
+ editor = get_editor()
+ if not editor:
+ print("warning: could not find a default editor")
+ return
+
+ name = os.path.basename(editor)
+ if name in ("vim", "nvim", "gvim"):
+ cmd = [
+ editor,
+ # need errorformat to match both Error and Warning, with or without a column
+ "--cmd",
+ "set errorformat+=%f:\\ line\\ %l\\\\,\\ col\\ %c\\\\,\\ %trror\\ -\\ %m",
+ "--cmd",
+ "set errorformat+=%f:\\ line\\ %l\\\\,\\ col\\ %c\\\\,\\ %tarning\\ -\\ %m",
+ "--cmd",
+ "set errorformat+=%f:\\ line\\ %l\\\\,\\ %trror\\ -\\ %m",
+ "--cmd",
+ "set errorformat+=%f:\\ line\\ %l\\\\,\\ %tarning\\ -\\ %m",
+ # start with quickfix window opened
+ "-c",
+ "copen",
+ # running with -q seems to open an empty buffer in addition to the
+ # first file, this removes that empty buffer
+ "-c",
+ "1bd",
+ ]
+
+ with tempfile.NamedTemporaryFile(mode="w") as fh:
+ s = formatters.get("compact", summary=False)(result)
+ fh.write(s)
+ fh.flush()
+
+ cmd.extend(["-q", fh.name])
+ subprocess.call(cmd)
+
+ else:
+ for path, errors in result.issues.items():
+ subprocess.call([editor, path])