Source code

Revision control

Copy as Markdown

Other Tools

# 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
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:
editor = get_editor()
if not editor:
print("warning: could not find a default editor")
name = os.path.basename(editor)
if name in ("vim", "nvim", "gvim"):
cmd = [
# need errorformat to match both Error and Warning, with or without a column
"set errorformat+=%f:\\ line\\ %l\\\\,\\ col\\ %c\\\\,\\ %trror\\ -\\ %m",
"set errorformat+=%f:\\ line\\ %l\\\\,\\ col\\ %c\\\\,\\ %tarning\\ -\\ %m",
"set errorformat+=%f:\\ line\\ %l\\\\,\\ %trror\\ -\\ %m",
"set errorformat+=%f:\\ line\\ %l\\\\,\\ %tarning\\ -\\ %m",
# start with quickfix window opened
# running with -q seems to open an empty buffer in addition to the
# first file, this removes that empty buffer
with tempfile.NamedTemporaryFile(mode="w") as fh:
s = formatters.get("compact", summary=False)(result)
for path, errors in result.issues.items():[editor, path])