Skip to content

Commit 3b704dd

Browse files
committed
feat: skip the length check if lineLimit not greater than 0
lineLimit has been initialized to 80 at the beginning, a value no greater than 0 is an intentional user config. Now it is no longer set to default 80 as an outlier, but just disabling the check.
1 parent 591c5da commit 3b704dd

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

validator/validate.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ func validateMsg(msg string, config *globalConfig) {
6969

7070
sections := strings.SplitN(msg, "\n", 2)
7171

72-
if config.LineLimit <= 0 {
73-
config.LineLimit = 80
74-
}
75-
7672
checkHeader(sections[0], config)
7773

7874
if len(sections) == 2 {
@@ -123,7 +119,8 @@ func checkHeader(header string, config *globalConfig) {
123119
// subject := groups[5]
124120

125121
length := len(header)
126-
if length > config.LineLimit &&
122+
if config.LineLimit > 0 &&
123+
length > config.LineLimit &&
127124
!(isFixupOrSquash || typ == "revert" || typ == "Revert") {
128125
state.LineOverLong.LogAndExit(length, config.LineLimit, header)
129126
}
@@ -178,7 +175,8 @@ func checkBody(body string, config *globalConfig) {
178175

179176
for _, line := range strings.Split(body, "\n") {
180177
length := len(line)
181-
if length > config.LineLimit {
178+
if config.LineLimit > 0 &&
179+
length > config.LineLimit {
182180
state.LineOverLong.LogAndExit(length, config.LineLimit, line)
183181
}
184182
}

validator/validate_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
var (
14+
zeroCfg = &globalConfig{}
1415
defaultCfg = &globalConfig{Lang: "en", BodyRequired: true, LineLimit: 80}
1516
scopeRequired = &globalConfig{ScopeRequired: true}
1617
scopesSpecified = &globalConfig{Scopes: []string{"model", "view", "controller"}}
@@ -116,6 +117,8 @@ func TestCheckHeader(t *testing.T) {
116117
{"test: ", "bad_header_no_title", defaultCfg, int(state.BadHeaderFormat)},
117118
{"feat: something changes", "scope_missing", scopeRequired, int(state.ScopeMissing)},
118119
{"feat( ): something changes", "empty_scope", scopeRequired, int(state.BadHeaderFormat)},
120+
{"feat: header that too lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng", "header_too_long", defaultCfg, int(state.LineOverLong)},
121+
{"feat: header that too lonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnng", "header_length_no_limit", zeroCfg, 0},
119122
}
120123
for _, tt := range headerCases {
121124
assertExitCode(t, func() {
@@ -126,18 +129,20 @@ func TestCheckHeader(t *testing.T) {
126129

127130
func TestCheckBody(t *testing.T) {
128131
var bodyCases = []struct {
129-
text string
130-
name string
131-
want int
132+
text string
133+
name string
134+
config *globalConfig
135+
want int
132136
}{
133-
{"", "body_missing", int(state.BodyMissing)},
134-
{"body", "no_empty_line", int(state.NoBlankLineBeforeBody)},
135-
{"\r\na body with too looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line", "line_over_long", int(state.LineOverLong)},
136-
{"\r\nnormal body", "normal", 0},
137+
{"", "body_missing", defaultCfg, int(state.BodyMissing)},
138+
{"body", "no_blank_line", defaultCfg, int(state.NoBlankLineBeforeBody)},
139+
{"\r\na body with too looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line", "body_line_over_long", defaultCfg, int(state.LineOverLong)},
140+
{"\r\na body with too looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line", "body_line_no_limit", zeroCfg, 0},
141+
{"\r\nnormal body", "normal", defaultCfg, 0},
137142
}
138143
for _, tt := range bodyCases {
139144
assertExitCode(t, func() {
140-
checkBody(tt.text, defaultCfg)
145+
checkBody(tt.text, tt.config)
141146
}, tt.name, tt.want)
142147
}
143148
}

0 commit comments

Comments
 (0)