Skip to content

Commit fca917d

Browse files
Athem-MAthem-M
Athem-M
authored and
Athem-M
committed
chore(validator): refactored code to comply with lint rule of max 88 characters
1 parent ead3d76 commit fca917d

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

internal/validator/validator.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,17 @@ func checkMessageSubject(s *string) error {
122122
* This function ensures the commit message does not exceed 50 characters in length.
123123
*
124124
* Parameters:
125-
* - l (*string): A pointer to the string representing the length of the commit message.
126-
*
125+
* - l (*string): A pointer to the string representing the length
126+
* of the commit message.
127127
* Returns:
128128
* - error: Returns an error if the commit message is more than 50 characters.
129129
* Returns nil if the message is within the valid length
130130
*/
131131

132132
func checkMessageLength(l *string) error {
133133
if len(*l) >= 50 {
134-
return fmt.Errorf("commit message exceeds 50 characters, current length: %d", len(*l))
134+
return fmt.Errorf("commit message exceeds 50 characters, current length: %d",
135+
len(*l))
135136
}
136137
return nil
137138
}

internal/validator/validator_test.go

+34-20
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func TestCheckMessageScope(t *testing.T) {
6060
expectedError: "",
6161
},
6262
{
63-
name: "Invalid Scope - Uppercase",
64-
scope: "User",
65-
expectedError: `invalid commit message scope casing, "User" should be "user"`, // Expected error message
66-
},
63+
name: "Invalid Scope - Uppercase",
64+
scope: "User",
65+
expectedError: `invalid commit message scope casing, "User" ` +
66+
`should be "user"`},
6767
}
6868

6969
for _, tc := range testCases {
@@ -95,9 +95,10 @@ func TestCheckMessageSubject(t *testing.T) {
9595
expectedError: "",
9696
},
9797
{
98-
name: "Invalid Subject - Uppercase",
99-
subject: "Add a new feature",
100-
expectedError: "commit message subject should be lowercased & not end with a period(.)",
98+
name: "Invalid Subject - Uppercase",
99+
subject: "Add a new feature",
100+
expectedError: "commit message subject should be lowercased & " +
101+
"not end with a period(.)",
101102
},
102103
}
103104

@@ -130,10 +131,14 @@ func TestCheckMessageLength(t *testing.T) {
130131
expectedError: "",
131132
},
132133
{
133-
name: "Invalid Length",
134-
message: "Add a new feature that makes the application run faster and more efficiently",
135-
expectedError: fmt.Sprintf("commit message exceeds 50 characters, current length: %d",
136-
len("Add a new feature that makes the application run faster and more efficiently")),
134+
name: "Invalid Length",
135+
message: "Add a new feature that makes the application run " +
136+
"faster and more efficiently",
137+
expectedError: fmt.Sprintf(
138+
"commit message exceeds 50 characters, current length: %d",
139+
len("Add a new feature that makes the application run "+
140+
"faster and more efficiently"),
141+
),
137142
},
138143
}
139144

@@ -188,7 +193,8 @@ func TestValidateMessage(t *testing.T) {
188193
Scope: "User",
189194
Description: "add a new feature",
190195
},
191-
expectedError: `invalid commit message scope casing, "User" should be "user"`,
196+
expectedError: `invalid commit message scope casing, "User" ` +
197+
`should be "user"`,
192198
expectedMessage: "",
193199
},
194200
{
@@ -198,18 +204,23 @@ func TestValidateMessage(t *testing.T) {
198204
Scope: "user",
199205
Description: "Add a new feature",
200206
},
201-
expectedError: "commit message subject should be lowercased & not end with a period(.)",
207+
expectedError: "commit message subject should be lowercased & " +
208+
"not end with a period(.)",
202209
expectedMessage: "",
203210
},
204211
{
205212
name: "Invalid Message - Exceeds Length",
206213
message: parser.Message{
207-
Type: "feat",
208-
Scope: "user",
209-
Description: "add a new feature that makes the application run faster and more efficiently", // More than 50 chars
214+
Type: "feat",
215+
Scope: "user",
216+
Description: "add a new feature that makes the application run " +
217+
"faster and more efficiently",
210218
},
211-
expectedError: fmt.Sprintf("commit message exceeds 50 characters, current length: %d",
212-
len("Add a new feature that makes the application run faster and more efficiently")),
219+
expectedError: fmt.Sprintf(
220+
"commit message exceeds 50 characters, current length: %d",
221+
len("Add a new feature that makes the application run "+
222+
"faster and more efficiently"),
223+
),
213224
expectedMessage: "",
214225
},
215226
{
@@ -231,11 +242,14 @@ func TestValidateMessage(t *testing.T) {
231242
if tc.expectedError == "" && err != nil {
232243
t.Errorf("expected no error, got %v", err)
233244
} else if err != nil && err.Error() != tc.expectedError {
234-
t.Errorf("expected error %q, got %q", tc.expectedError, err.Error())
245+
t.Errorf("expected error %q, got %q",
246+
tc.expectedError, err.Error())
235247
}
236248

237249
if messageResult != tc.expectedMessage {
238-
t.Errorf("expected message %q, got %q", tc.expectedMessage, messageResult)
250+
t.Errorf("expected message %q, got %q",
251+
tc.expectedMessage, messageResult,
252+
)
239253
}
240254
})
241255
}

0 commit comments

Comments
 (0)