Skip to content

Commit f0e69df

Browse files
style: P2 code style improvements
- Unexport 21 symbols only used within their package: ui: FilterMode, FilterNone, FilterInput, FilterRegex, ExpandedJSON, InfoStyle, WarnStyle, ErrorStyle, DebugStyle, FatalStyle, JSONStyle, SourceStyle, SelectedStyle, GetLevelStyle, ShouldAutoScroll, MsgLogLine, ReadLogs domain: DetectLevel, ParseTimestamp, IsValidJSON, ErrorPercentage - Break 5+ arg ReadExistingContent calls onto separate lines - Fix %s -> %q in test Errorf for user-provided values - Remove duplicate package doc comments from 6 test files - Fix test function names (TestdetectLevel -> TestDetectLevel)
1 parent 47bfb92 commit f0e69df

16 files changed

Lines changed: 129 additions & 123 deletions

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestDefaultConfig(t *testing.T) {
1515
t.Errorf("Expected BufferMax 10000, got %d", cfg.BufferMax)
1616
}
1717
if cfg.Theme != "dark" {
18-
t.Errorf("Expected Theme 'dark', got %s", cfg.Theme)
18+
t.Errorf("Expected Theme 'dark', got %q", cfg.Theme)
1919
}
2020
}
2121

internal/domain/bookmarks_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package domain тестирует менеджер bookmarks.
21
package domain
32

43
import (

internal/domain/domain.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ var levelByIndex = []LogLevel{
8484
LevelTrace,
8585
}
8686

87-
// DetectLevel определяет уровень логирования по тексту строки.
87+
// detectLevel определяет уровень логирования по тексту строки.
8888
// Возвращает LevelUnknown если уровень не определён.
89-
func DetectLevel(line string) LogLevel {
89+
func detectLevel(line string) LogLevel {
9090
upper := strings.ToUpper(line)
9191
for i, pattern := range levelPatterns {
9292
if pattern.MatchString(upper) {
@@ -96,10 +96,10 @@ func DetectLevel(line string) LogLevel {
9696
return LevelUnknown
9797
}
9898

99-
// ParseTimestamp извлекает временную метку из строки лога.
99+
// parseTimestamp извлекает временную метку из строки лога.
100100
// Поддерживает форматы: ISO 8601, Apache, и другие.
101101
// Возвращает текущее время если парсинг не удался.
102-
func ParseTimestamp(line string) time.Time {
102+
func parseTimestamp(line string) time.Time {
103103
for _, pattern := range timestampPatterns {
104104
if match := pattern.FindString(line); match != "" {
105105
t, err := parseTimestampValue(match)
@@ -127,9 +127,9 @@ func parseTimestampValue(s string) (time.Time, error) {
127127
return time.Time{}, fmt.Errorf("cannot parse timestamp")
128128
}
129129

130-
// IsValidJSON проверяет, является ли строка валидным JSON.
130+
// isValidJSON проверяет, является ли строка валидным JSON.
131131
// Возвращает true если строка начинается с { или [ и валидна.
132-
func IsValidJSON(line string) bool {
132+
func isValidJSON(line string) bool {
133133
line = strings.TrimSpace(line)
134134
if len(line) < 2 || (line[0] != '{' && line[0] != '[') {
135135
return false
@@ -180,7 +180,7 @@ func (p *JSONParser) Parse(line string, source Source) *LogLine {
180180
Content: line,
181181
IsJSON: true,
182182
Parsed: data,
183-
Timestamp: ParseTimestamp(line),
183+
Timestamp: parseTimestamp(line),
184184
Level: LevelUnknown,
185185
}
186186

@@ -190,7 +190,7 @@ func (p *JSONParser) Parse(line string, source Source) *LogLine {
190190
} else if level, ok := data["severity"].(string); ok {
191191
logLine.Level = LogLevel(strings.ToUpper(level))
192192
} else {
193-
logLine.Level = DetectLevel(line)
193+
logLine.Level = detectLevel(line)
194194
}
195195

196196
// Извлекаем временную метку из JSON полей
@@ -213,7 +213,7 @@ func (p *JSONParser) Parse(line string, source Source) *LogLine {
213213

214214
// CanParse проверяет, является ли строка валидным JSON.
215215
func (p *JSONParser) CanParse(line string) bool {
216-
return IsValidJSON(line)
216+
return isValidJSON(line)
217217
}
218218

219219
// parseTime парсит время в формате RFC3339.
@@ -252,7 +252,7 @@ func (p *LogfmtParser) Parse(line string, source Source) *LogLine {
252252
Content: line,
253253
IsJSON: false,
254254
Parsed: data,
255-
Timestamp: ParseTimestamp(line),
255+
Timestamp: parseTimestamp(line),
256256
Level: LevelUnknown,
257257
}
258258

@@ -261,7 +261,7 @@ func (p *LogfmtParser) Parse(line string, source Source) *LogLine {
261261
} else if level, ok := data["severity"]; ok {
262262
logLine.Level = LogLevel(strings.ToUpper(level))
263263
} else {
264-
logLine.Level = DetectLevel(line)
264+
logLine.Level = detectLevel(line)
265265
}
266266

267267
return logLine
@@ -303,8 +303,8 @@ func (p *PlainParser) Parse(line string, source Source) *LogLine {
303303
Content: line,
304304
IsJSON: false,
305305
Parsed: nil,
306-
Timestamp: ParseTimestamp(line),
307-
Level: DetectLevel(line),
306+
Timestamp: parseTimestamp(line),
307+
Level: detectLevel(line),
308308
}
309309
}
310310

internal/domain/filter_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package domain тестирует фильтрацию по времени и JSON Path.
21
package domain
32

43
import (

internal/domain/jsonpath/jsonpath_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Package jsonpath предоставляет парсер и исполнитель JSON Path фильтров.
2-
// Поддерживаемые операторы: ==, !=, startswith, contains
31
package jsonpath
42

53
import (

internal/domain/parser_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestJSONParser_ValidJSON(t *testing.T) {
5050
for _, tt := range tests {
5151
t.Run(tt.name, func(t *testing.T) {
5252
if !parser.CanParse(tt.input) {
53-
t.Errorf("CanParse returned false for valid JSON: %s", tt.input)
53+
t.Errorf("CanParse returned false for valid JSON: %q", tt.input)
5454
}
5555
result := parser.Parse(tt.input, source)
5656
if result == nil {
@@ -174,7 +174,7 @@ func TestLogfmtParser_ValidLogfmt(t *testing.T) {
174174
for _, tt := range tests {
175175
t.Run(tt.name, func(t *testing.T) {
176176
if !parser.CanParse(tt.input) {
177-
t.Errorf("CanParse returned false for: %s", tt.input)
177+
t.Errorf("CanParse returned false for: %q", tt.input)
178178
}
179179
result := parser.Parse(tt.input, source)
180180
if result == nil {
@@ -304,9 +304,9 @@ func TestDetectLevel_CaseInsensitive(t *testing.T) {
304304
}
305305

306306
for _, tt := range tests {
307-
got := DetectLevel(tt.input)
307+
got := detectLevel(tt.input)
308308
if got != tt.want {
309-
t.Errorf("DetectLevel(%q) = %v, want %v", tt.input, got, tt.want)
309+
t.Errorf("detectLevel(%q) = %v, want %v", tt.input, got, tt.want)
310310
}
311311
}
312312
}
@@ -329,14 +329,14 @@ func TestIsValidJSON(t *testing.T) {
329329
}
330330

331331
for _, s := range valid {
332-
if !IsValidJSON(s) {
333-
t.Errorf("IsValidJSON(%q) = false, want true", s)
332+
if !isValidJSON(s) {
333+
t.Errorf("isValidJSON(%q) = false, want true", s)
334334
}
335335
}
336336

337337
for _, s := range invalid {
338-
if IsValidJSON(s) {
339-
t.Errorf("IsValidJSON(%q) = true, want false", s)
338+
if isValidJSON(s) {
339+
t.Errorf("isValidJSON(%q) = true, want false", s)
340340
}
341341
}
342342
}
@@ -356,7 +356,7 @@ func TestParseTimestamp(t *testing.T) {
356356

357357
for _, tt := range tests {
358358
before := time.Now()
359-
result := ParseTimestamp(tt.input)
359+
result := parseTimestamp(tt.input)
360360
after := time.Now()
361361

362362
if tt.want {
@@ -409,7 +409,7 @@ func BenchmarkDetectLevel(b *testing.B) {
409409

410410
b.ResetTimer()
411411
for i := 0; i < b.N; i++ {
412-
DetectLevel(input)
412+
detectLevel(input)
413413
}
414414
}
415415

@@ -418,6 +418,6 @@ func BenchmarkIsValidJSON(b *testing.B) {
418418

419419
b.ResetTimer()
420420
for i := 0; i < b.N; i++ {
421-
IsValidJSON(json)
421+
isValidJSON(json)
422422
}
423423
}

internal/domain/rate_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package domain тестирует калькулятор скорости (rate).
21
package domain
32

43
import (

internal/domain/stats.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func (rb *RingBuffer) CalculateStats() *Stats {
6666
return stats
6767
}
6868

69-
// ErrorPercentage возвращает процент ошибок от общего количества строк.
70-
func (s *Stats) ErrorPercentage() float64 {
69+
// errorPercentage возвращает процент ошибок от общего количества строк.
70+
func (s *Stats) errorPercentage() float64 {
7171
if s.TotalLines == 0 {
7272
return 0
7373
}
@@ -82,7 +82,7 @@ func (s *Stats) String() string {
8282
sb.WriteString(fmt.Sprintf("Lines: %d\n", s.TotalLines))
8383

8484
// Процент ошибок
85-
errorPct := s.ErrorPercentage()
85+
errorPct := s.errorPercentage()
8686
sb.WriteString(fmt.Sprintf("Errors: %d (%.2f%%)\n", s.ByLevel[LevelError]+s.ByLevel[LevelFatal], errorPct))
8787

8888
// По уровням

internal/domain/stats_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package domain тестирует калькулятор статистики логов.
21
package domain
32

43
import (
@@ -104,9 +103,10 @@ func TestStats_LevelPercentage(t *testing.T) {
104103
stats := rb.CalculateStats()
105104

106105
// Проверяем проценты
107-
errorPct := stats.ErrorPercentage()
108-
if errorPct != 20.0 {
109-
t.Errorf("Expected ErrorPercentage=20.0, got %f", errorPct)
106+
errorPct := stats.errorPercentage()
107+
108+
if errorPct != 20.0 {
109+
t.Errorf("Expected errorPercentage=20.0, got %f", errorPct)
110110
}
111111
}
112112

internal/domain/time_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package domain тестирует парсинг времени для фильтрации.
21
package domain
32

43
import (

0 commit comments

Comments
 (0)