Skip to content

Commit bd308e4

Browse files
committed
refactor(exporter): rewrite HTML exporter to use Go templates
Replaces the manual string-building implementation of the HTML exporter with a more robust and maintainable solution using Go's `html/template` package. This improves readability, security, and separation of concerns. - HTML structure and CSS styles are moved into their own files and embedded into the binary using `go:embed`. - A new data preparation layer adapts the course model for the template, simplifying rendering logic. - Tests are updated to reflect the new implementation, removing obsolete test cases for the old string-building methods. Additionally, this commit: - Adds an `AGENTS.md` file with development and contribution guidelines. - Updates `.golangci.yml` to allow standard Go patterns for interface package naming.
1 parent 227f88c commit bd308e4

File tree

7 files changed

+650
-897
lines changed

7 files changed

+650
-897
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ linters:
188188
- gochecknoglobals
189189
- gochecknoinits
190190

191+
# Exclude var-naming for interfaces package (standard Go pattern for interface definitions)
192+
- path: internal/interfaces/
193+
text: "var-naming: avoid meaningless package names"
194+
linters:
195+
- revive
196+
191197
# Allow fmt.Print* in main package
192198
- path: ^main\.go$
193199
text: "use of fmt.Print"

AGENTS.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Agent Guidelines for articulate-parser
2+
3+
## Build/Test Commands
4+
- **Build**: `task build` or `go build -o bin/articulate-parser main.go`
5+
- **Run tests**: `task test` or `go test -race -timeout 5m ./...`
6+
- **Run single test**: `go test -v -race -run ^TestName$ ./path/to/package`
7+
- **Test with coverage**:
8+
- `task test:coverage` or
9+
- `go test -race -coverprofile=coverage/coverage.out -covermode=atomic ./...`
10+
- **Lint**: `task lint` (runs vet, fmt check, staticcheck, golangci-lint)
11+
- **Format**: `task fmt` or `gofmt -s -w .`
12+
- **CI checks**: `task ci` (deps, lint, test with coverage, build)
13+
14+
## Code Style Guidelines
15+
16+
### Imports
17+
- Use `goimports` with local prefix: `github.com/kjanat/articulate-parser`
18+
- Order: stdlib, external, internal packages
19+
- Group related imports together
20+
21+
### Formatting
22+
- Use `gofmt -s` (simplify) and `gofumpt` with extra rules
23+
- Function length: max 100 lines, 50 statements
24+
- Cyclomatic complexity: max 15
25+
- Cognitive complexity: max 20
26+
27+
### Types & Naming
28+
- Use interface-based design (see `internal/interfaces/`)
29+
- Export types/functions with clear godoc comments ending with period
30+
- Use descriptive names: `ArticulateParser`, `MarkdownExporter`
31+
- Receiver names: short (1-2 chars), consistent per type
32+
33+
### Error Handling
34+
- Always wrap errors with context: `fmt.Errorf("operation failed: %w", err)`
35+
- Use `%w` verb for error wrapping to preserve error chain
36+
- Check all error returns (enforced by `errcheck`)
37+
- Document error handling rationale in defer blocks when ignoring close errors
38+
39+
### Comments
40+
- All exported types/functions require godoc comments
41+
- End sentences with periods (`godot` linter enforced)
42+
- Mark known issues with TODO/FIXME/HACK/BUG/XXX
43+
44+
### Security
45+
- Use `#nosec` with justification for deliberate security exceptions (G304 for CLI file paths, G306 for export file permissions)
46+
- Run `gosec` and `govulncheck` for security audits
47+
48+
### Testing
49+
- Enable race detection: `-race` flag
50+
- Use table-driven tests where applicable
51+
- Mark test helpers with `t.Helper()`
52+
- Benchmarks in `*_bench_test.go`, examples in `*_example_test.go`
53+
54+
### Dependencies
55+
- Minimal external dependencies (currently: go-docx, golang.org/x/net, golang.org/x/text)
56+
- Run `task deps:tidy` after adding/removing dependencies

0 commit comments

Comments
 (0)