Skip to content

Commit

Permalink
Don't crash on empty problem line list
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Dec 15, 2023
1 parent 1b351de commit f360280
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/checks/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"

"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/parser"
Expand Down Expand Up @@ -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]
}

Expand Down

0 comments on commit f360280

Please # to comment.