From f3602806e3cfe00f2660a754d32e36aa157b09d1 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Fri, 15 Dec 2023 11:17:26 +0000 Subject: [PATCH] Don't crash on empty problem line list --- docs/changelog.md | 6 +++++- internal/checks/base.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 8990b7e5..6b627f4d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,9 +4,13 @@ ### Added -- pint will now report any comment that looks like [pint control comment](./ignoring.md) +- pint will now report any comment that looks like a [pint control comment](./ignoring.md) but cannot be parsed correctly. +### Fixed + +- Fixed a crash when running `pint ci` and using `ignore/file` comments. + ## v0.52.0 ### Added diff --git a/internal/checks/base.go b/internal/checks/base.go index a90c7090..e7db03db 100644 --- a/internal/checks/base.go +++ b/internal/checks/base.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log/slog" "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" @@ -113,6 +114,15 @@ type Problem struct { } func (p Problem) LineRange() (int, int) { + if len(p.Lines) == 0 { + slog.Warn( + "Bug: empty line range", + slog.String("severity", p.Severity.String()), + slog.String("reporter", p.Reporter), + slog.String("problem", p.Text), + ) + return 1, 1 + } return p.Lines[0], p.Lines[len(p.Lines)-1] }