Skip to content

Commit

Permalink
feat: add more diagnostics
Browse files Browse the repository at this point in the history
- Check if message header contains a description
- Check if message type and description are separated by space
  • Loading branch information
benpueschel committed Jun 30, 2024
1 parent 1b7bab7 commit 88a31a3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions analysis/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func getHeaderDiagnostics(header string) []lsp.Diagnostic {
})
}

commit_type, description, found := strings.Cut(header, ":")
commit_type, description, found := strings.Cut(header, ": ")
if !found {
line_range := LineRange(0, 0, 0, len(header))
diagnostics = append(diagnostics, lsp.Diagnostic{
Severity: 1,
Range: line_range,
Source: "conventional-commit-lsp",
Message: "Commit message must contain a type and description, separated by a colon. ",
Message: "Commit message must contain a type and description, separated by a colon and space. ",
})
return diagnostics
}
Expand All @@ -66,6 +66,16 @@ func getHeaderDiagnostics(header string) []lsp.Diagnostic {
return diagnostics
}

if strings.TrimSpace(description) == "" {
line_range := LineRange(0, len(commit_type)+1, 0, len(header))
diagnostics = append(diagnostics, lsp.Diagnostic{
Severity: 1,
Range: line_range,
Source: "conventional-commit-lsp",
Message: "Commit message must contain a description",
})
}

if commit_type == "" {
line_range := LineRange(0, 0, 0, len(header)-1)
diagnostics = append(diagnostics, lsp.Diagnostic{
Expand Down

0 comments on commit 88a31a3

Please sign in to comment.