Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ jobs:
go-version: '1.24'
check-latest: true

- name: Check Go formatting
run: |
echo "Checking Go code formatting..."
if [ -n "$(gofmt -l .)" ]; then
echo "❌ The following files need formatting:"
gofmt -l .
echo ""
echo "Run 'make fmt' or 'gofmt -w .' to format them"
exit 1
fi
echo "✓ All files are properly formatted"

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6 # v6.1.0
with:
Expand Down
87 changes: 87 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
run:
timeout: 5m
tests: true
modules-download-mode: readonly

linters:
enable:
- gofmt # Check that code is formatted (auto-fixable)
- goimports # Check import statements are formatted (auto-fixable)
- govet # Check for common mistakes
- errcheck # Check for unchecked errors
- staticcheck # Advanced static analysis
- ineffassign # Detect ineffectual assignments
- unused # Check for unused code (auto-fixable)
- gosimple # Suggest code simplifications (auto-fixable)
- gocritic # Comprehensive code analyzer
- misspell # Check for misspelled words (auto-fixable)
- godot # Check that comments end in periods (auto-fixable)
- prealloc # Find slice preallocation opportunities
- nolintlint # Check nolint directives
- revive # Fast, configurable linter
- bodyclose # Check HTTP response body is closed
- gci # Sorts imports (auto-fixable)
- whitespace # Checks for whitespace issues (auto-fixable)

linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: github.com/vladkampov/markdocify
gci:
sections:
- standard
- default
- prefix(github.com/vladkampov/markdocify)
govet:
enable:
- shadow
errcheck:
check-type-assertions: true
check-blank: true
gocritic:
enabled-tags:
- diagnostic
- performance
- style
disabled-checks:
- commentedOutCode
revive:
severity: warning
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unreachable-code
- name: redefines-builtin-id

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- ineffassign
- path: cmd/
linters:
- gochecknoinits
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
49 changes: 48 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test clean install lint security-scan
.PHONY: build test clean install lint security-scan fmt fmt-check check-all fmt-fix

# Build configuration
BINARY_NAME=markdocify
Expand Down Expand Up @@ -34,6 +34,53 @@ lint:
security-scan:
gosec ./...

# Format Go code
fmt:
@echo "Formatting Go code..."
@gofmt -w .
@goimports -w .
@echo "✓ Code formatted"

# Auto-fix what we can with golangci-lint
fmt-fix:
@echo "Auto-fixing code issues..."
@gofmt -w .
@goimports -w .
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "Running golangci-lint with auto-fix..."; \
golangci-lint run --fix; \
else \
echo "⚠️ golangci-lint not installed - only running gofmt/goimports"; \
fi
@echo "✓ Auto-fixes applied"

# Check if code is formatted
fmt-check:
@echo "Checking Go code formatting..."
@if [ -n "$$(gofmt -l .)" ]; then \
echo "❌ The following files need formatting:"; \
gofmt -l .; \
echo "Run 'make fmt' to format them"; \
exit 1; \
else \
echo "✓ All files are properly formatted"; \
fi

# Run all checks locally (same as CI)
check-all: fmt-check
@echo "Running all local checks..."
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "Running linter..."; \
golangci-lint run; \
else \
echo "⚠️ golangci-lint not installed. Install with:"; \
echo " brew install golangci-lint"; \
echo " OR: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
@echo "Running tests..."
@go test ./...
@echo "✅ All checks passed!"

# Clean build artifacts
clean:
rm -rf bin/
Expand Down
12 changes: 6 additions & 6 deletions cmd/markdocify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ func createQuickConfig(inputURL string) (*config.Config, error) {
// Create comprehensive domain patterns for following links
domain := parsedURL.Hostname()
basePattern := strings.ReplaceAll(domain, ".", "\\.")

// Much more aggressive following patterns for comprehensive documentation coverage
followPatterns := []string{
fmt.Sprintf("^https?://%s/.*", basePattern), // Main domain pattern
}

// Add specific documentation path patterns based on the starting URL
if strings.Contains(inputURL, "/docs") {
followPatterns = append(followPatterns,
followPatterns = append(followPatterns,
fmt.Sprintf("^https?://%s/docs/.*", basePattern),
fmt.Sprintf("^https?://%s/documentation/.*", basePattern),
fmt.Sprintf("^https?://%s/guide/.*", basePattern),
Expand All @@ -135,7 +135,7 @@ func createQuickConfig(inputURL string) (*config.Config, error) {
BaseURL: fmt.Sprintf("%s://%s", parsedURL.Scheme, parsedURL.Host),
OutputFile: outputFile,
StartURLs: []string{inputURL},

FollowPatterns: followPatterns,
IgnorePatterns: []string{
// Media files
Expand Down Expand Up @@ -178,7 +178,7 @@ func createQuickConfig(inputURL string) (*config.Config, error) {
},

Selectors: config.SelectorConfig{
Title: "h1, title, .page-title, .doc-title, [data-testid='page-title']",
Title: "h1, title, .page-title, .doc-title, [data-testid='page-title']",
Content: strings.Join([]string{
// Primary content containers
"main", "article", ".content", ".documentation", ".docs", "#content", ".main-content",
Expand Down Expand Up @@ -288,4 +288,4 @@ func main() {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
}
Loading
Loading