|
1 | 1 | # Contributing |
2 | 2 |
|
3 | | -Here's some ways to help: |
| 3 | +Bug reports, focused test cases, documentation fixes, and code contributions |
| 4 | +are welcome. Before starting a large change, open an issue to confirm the |
| 5 | +approach. |
4 | 6 |
|
5 | | -* Select an item from the [issues list](https://github.com/osteele/liquid/issues) |
6 | | -* Search the sources for FIXME and TODO comments using `make list-todo` |
7 | | -* Improve the code coverage - run `make coverage` to see current coverage (currently ~84%) |
| 7 | +Review the |
| 8 | +[pull request template](https://github.com/osteele/liquid/blob/main/.github/PULL_REQUEST_TEMPLATE.md) |
| 9 | +before writing the final description. |
8 | 10 |
|
9 | | -Review the [pull request template](https://github.com/osteele/liquid/blob/master/.github/PULL_REQUEST_TEMPLATE.md) before you get too far along on coding. |
| 11 | +## Set up the repository |
10 | 12 |
|
11 | | -A note on lint: `nolint: gocyclo` has been used to disable cyclomatic complexity checks on generated functions, hand-written parsers, and some of the generic interpreter functions. IMO this check isn't appropriate for those classes of functions. This isn't a license to disable cyclomatic complexity checks or lint in general. |
12 | | - |
13 | | -## Cookbook |
14 | | - |
15 | | -### Set up your machine |
16 | | - |
17 | | -Fork and clone the repo. |
18 | | - |
19 | | -[Install go](https://golang.org/doc/install#install). On macOS running Homebrew, `brew install go` is easier than the linked instructions. |
20 | | - |
21 | | -Install package dependencies and development tools: |
| 13 | +Install [Go](https://go.dev/doc/install), then fork and clone the repository. |
| 14 | +Download the pinned tools and module dependencies: |
22 | 15 |
|
23 | 16 | ```bash |
24 | | -make tools # Download the versions pinned in go.mod |
25 | | -make deps # Download Go dependencies |
| 17 | +make tools |
| 18 | +make deps |
26 | 19 | ``` |
27 | 20 |
|
28 | | -The lint target runs the golangci-lint version pinned in `go.mod`; a separate |
29 | | -global installation is not required. |
30 | | - |
31 | | -#### Set up Git Hooks (Recommended) |
| 21 | +The lint target uses the `golangci-lint` version pinned in `go.mod`. You do not |
| 22 | +need a global installation. |
32 | 23 |
|
33 | | -This project uses pre-commit hooks to automatically run formatting, linting, and tests before commits and pushes: |
| 24 | +Optional pre-commit hooks run formatting, lint, tests, and basic repository |
| 25 | +checks: |
34 | 26 |
|
35 | 27 | ```bash |
36 | | -make install-hooks # Install pre-commit hooks |
| 28 | +make install-hooks |
37 | 29 | ``` |
38 | 30 |
|
39 | | -This will: |
40 | | -- Install pre-commit if not already installed |
41 | | -- Set up hooks to run automatically on `git commit` and `git push` |
42 | | -- Run formatting (`go fmt`) |
43 | | -- Run linting (`golangci-lint`) |
44 | | -- Run tests (`go test -short`) |
45 | | -- Check for common issues (trailing whitespace, large files, merge conflicts) |
| 31 | +Run all hooks manually with `make run-hooks`. Update the hook definitions with |
| 32 | +`make update-hooks`. |
46 | 33 |
|
47 | | -To test the hooks manually: |
48 | | -```bash |
49 | | -make run-hooks # Run all hooks on all files |
50 | | -``` |
| 34 | +## Develop and test |
51 | 35 |
|
52 | | -To update hooks to latest versions: |
53 | | -```bash |
54 | | -make update-hooks # Update pre-commit hooks |
55 | | -``` |
56 | | - |
57 | | -### Development Workflow |
58 | | - |
59 | | -Quick start for development: |
| 36 | +Run the standard pre-commit checks before opening a pull request: |
60 | 37 |
|
61 | 38 | ```bash |
62 | | -make all # Clean, lint, test, and build everything |
63 | | -make pre-commit # Run formatter, linter, and tests before committing |
| 39 | +make pre-commit |
64 | 40 | ``` |
65 | 41 |
|
66 | | -### Testing |
| 42 | +Useful targets include: |
67 | 43 |
|
68 | 44 | ```bash |
69 | | -make test # Run all tests |
70 | | -make test-short # Run short tests only |
71 | | -make coverage # Generate test coverage report |
72 | | -make benchmark # Run performance benchmarks |
| 45 | +make test # Run all tests |
| 46 | +make test-short # Run short tests |
| 47 | +make coverage # Write coverage.out and print package coverage |
| 48 | +make benchmark # Run benchmarks |
| 49 | +make fmt # Format Go source |
| 50 | +make lint # Run golangci-lint |
| 51 | +make lint-fix # Apply supported lint fixes |
| 52 | +make vet # Run go vet |
| 53 | +make build # Build the command |
| 54 | +make ci # Run the local CI sequence |
73 | 55 | ``` |
74 | 56 |
|
75 | | -**Coverage Reporting**: Code coverage is tracked automatically via GitHub Actions. When you push to the main branch, the CI pipeline: |
76 | | -- Generates a coverage report using Go's native coverage tools |
77 | | -- Extracts the coverage percentage |
78 | | -- Displays coverage details in the workflow summary |
79 | | -- Optionally creates a coverage badge (if `GIST_SECRET` is configured) |
| 57 | +Use `make help` to list every target. |
80 | 58 |
|
81 | | -To view coverage locally, run `make coverage`. This generates `coverage.out` and displays per-package coverage percentages. The coverage data is generated without external SaaS services, using only Go's built-in tooling. |
| 59 | +Do not suppress a lint finding without a specific reason. Existing |
| 60 | +`nolint:gocyclo` directives cover generated functions, hand-written parsers, |
| 61 | +and generic interpreter functions where the complexity metric is not useful. |
82 | 62 |
|
83 | | -### Code Quality |
| 63 | +## Manage dependencies |
84 | 64 |
|
85 | 65 | ```bash |
86 | | -make fmt # Format code |
87 | | -make lint # Run linter |
88 | | -make lint-fix # Run linter with auto-fix |
89 | | -make vet # Run go vet |
| 66 | +make deps # Download dependencies |
| 67 | +make deps-update # Update dependencies |
| 68 | +make deps-list # List dependencies |
| 69 | +make mod-tidy # Run go mod tidy |
| 70 | +make mod-verify # Verify downloaded modules |
| 71 | +make check-mod # Check whether go.mod and go.sum are current |
90 | 72 | ``` |
91 | 73 |
|
92 | | -### Building |
| 74 | +## Generate the parser |
93 | 75 |
|
94 | | -```bash |
95 | | -make build # Build the binary |
96 | | -make install # Build and install to GOPATH/bin |
97 | | -make clean # Remove build artifacts |
98 | | -``` |
| 76 | +The expression lexer uses Ragel, and the parser uses `goyacc`. Install Ragel |
| 77 | +before editing `expressions/scanner.rl`. On macOS, run `brew install ragel`. |
99 | 78 |
|
100 | | -### Dependencies |
| 79 | +After changing `expressions/scanner.rl` or `expressions/expressions.y`, |
| 80 | +regenerate the checked-in Go files: |
101 | 81 |
|
102 | 82 | ```bash |
103 | | -make deps # Download dependencies |
104 | | -make deps-update # Update dependencies to latest versions |
105 | | -make deps-list # List all dependencies |
106 | | -make mod-tidy # Clean up go.mod and go.sum |
107 | | -make mod-verify # Verify dependencies are correct |
108 | | -make check-mod # Check if go.mod is up to date |
| 83 | +make generate |
109 | 84 | ``` |
110 | 85 |
|
111 | | -### Utilities |
| 86 | +The generation target downloads the pinned Go tools and checks for Ragel. |
112 | 87 |
|
113 | | -```bash |
114 | | -make list-todo # Find all TODO and FIXME comments |
115 | | -make list-imports # List all package imports |
116 | | -make ci # Run full CI suite locally |
117 | | -make help # Show all available commands |
118 | | -``` |
| 88 | +## Preview API documentation |
119 | 89 |
|
120 | | -### Preview the Documentation |
| 90 | +Run a local documentation server: |
121 | 91 |
|
122 | 92 | ```bash |
| 93 | +go install golang.org/x/tools/cmd/godoc@latest |
123 | 94 | godoc -http=:6060 |
124 | | -open http://localhost:6060/pkg/github.com/osteele/liquid/ |
125 | | -``` |
126 | | - |
127 | | -### Work on the Expression Parser and Lexer |
128 | | - |
129 | | -To work on the lexer, install Ragel. On macOS: `brew install ragel`. |
130 | | - |
131 | | -The Go code-generation tools are pinned in `go.mod` and downloaded by `make tools`: |
132 | | -- `goyacc` for parser generation |
133 | | -- `stringer` for string method generation |
134 | | - |
135 | | -After editing `scanner.rl` or `expressions.y`: |
136 | | - |
137 | | -```bash |
138 | | -make generate # Re-generate lexers and parsers |
139 | 95 | ``` |
140 | 96 |
|
141 | | -Or directly: |
142 | | - |
143 | | -```bash |
144 | | -go generate ./... |
145 | | -``` |
146 | | - |
147 | | -Test just the scanner: |
148 | | - |
149 | | -```bash |
150 | | -cd expressions |
151 | | -ragel -Z scanner.rl && go test |
152 | | -``` |
| 97 | +Then open <http://localhost:6060/pkg/github.com/osteele/liquid/>. |
0 commit comments