Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion server/app/services/findings/typescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def check(self):
# -- eslint ------------------------------------------------------------------


_ESLINT_ALL_IGNORED = re.compile(r"\ball of the files matching\s+the glob pattern [^\r\n]+ are ignored\.")


def eslint_configs(root: Path, stop: Optional[Path]) -> list[Path]:
found = find_within(root, ESLINT_CONFIGS)
if not found:
Expand Down Expand Up @@ -235,7 +238,11 @@ def check(self):
target = str(self.root) if self.root != cwd and cwd in self.root.parents else "."
out = run_process([str(self.binary), "--format", "json", target], cwd, self.timeout)
if out.returncode not in (0, 1):
raise ToolFailed(first_line(out.stderr or out.stdout) or f"exit code {out.returncode}")
# ESLint's generic banner precedes the real error, which can contain
# absolute paths. Only return fixed summaries to the Findings UI.
if any(_ESLINT_ALL_IGNORED.search(stream) for stream in (out.stderr, out.stdout)):
raise ToolFailed("all selected files are ignored; check ignore and file patterns in the ESLint config")
raise ToolFailed(f"exit code {out.returncode}; run ESLint directly for details")
findings, files = parse_eslint(out.stdout or "[]", self.id)
scope = str(self.root)
return [f for f in findings if f.path.startswith(scope)], [f for f in files if f.startswith(scope)]
Expand Down
36 changes: 35 additions & 1 deletion server/tests/test_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from app.services.findings import builtin_ts, ruff, typescript
from app.services.findings.model import Finding
from app.services.findings.runner import FindingsCache, collect, plan_tools, run_tools
from app.services.findings.tools import Tool, ToolFailed, run_process
from app.services.findings.tools import ProcessOutput, Tool, ToolFailed, run_process

PY_SOURCE = textwrap.dedent(
"""\
Expand Down Expand Up @@ -261,6 +261,40 @@ def test_tsc_global_config_error_is_a_failure() -> None:
# -- failures: never zero -------------------------------------------------------


@pytest.mark.parametrize("stream", ["stderr", "stdout"])
def test_eslint_ignored_files_explain_unassessed_result(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, stream: str,
) -> None:
config = tmp_path / "eslint.config.js"
tool = typescript.EslintTool(tmp_path, config, tmp_path / "eslint", tmp_path)
output = textwrap.dedent("""\
Oops! Something went wrong! :(

ESLint: 9.39.5

You are linting "/private/project/src", but all of the files matching
the glob pattern "/private/project/src" are ignored.
""")
process = ProcessOutput(2, output if stream == "stdout" else "", output if stream == "stderr" else "")
monkeypatch.setattr(typescript, "run_process", lambda *_: process)
run, checked = findings.tools.run(tool)
assert run.status == "na" and not run.ok and run.files is None and checked == []
assert run.reason == (
"eslint (eslint.config.js) failed: all selected files are ignored; "
"check ignore and file patterns in the ESLint config"
)


def test_eslint_unknown_failure_reports_exit_without_raw_output(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
config = tmp_path / "eslint.config.js"
tool = typescript.EslintTool(tmp_path, config, tmp_path / "eslint", tmp_path)
process = ProcessOutput(2, "", "Error loading /private/project/unknown-plugin.js")
monkeypatch.setattr(typescript, "run_process", lambda *_: process)
run, checked = findings.tools.run(tool)
assert run.status == "na" and not run.ok and run.files is None and checked == []
assert run.reason == "eslint (eslint.config.js) failed: exit code 2; run ESLint directly for details"


class _SlowTool(Tool):
def __init__(self, root: Path, timeout: float) -> None:
super().__init__(id="slow", tool="slow", label="slow-lint", source="project", root=root, extensions=(".py",), timeout=timeout)
Expand Down
Loading