feat(rules): standardize PATH-first approach for Go and Bun

This commit is contained in:
Nicola Zangrandi 2025-02-21 08:35:51 +01:00
parent 4aa4541913
commit 23b6535eee
Signed by: wasp
GPG key ID: 43C1470D890F23ED
3 changed files with 88 additions and 21 deletions

View file

@ -1,21 +1,25 @@
---
description: Always use Bun instead of Node/npm, and ensure to use the local installation at ~/.bun/bin/bun
globs: **/*
globs: **/*.{ts,js,json,svelte}
---
<rule>
When using Bun:
1. Always use the local installation at ~/.bun/bin/bun
2. Use Bun instead of Node/npm for all package management and running scripts
3. For running commands, use the full path: ~/.bun/bin/bun
4. Replace npm scripts with Bun equivalents in package.json
5. Use Bun for installing, running, and testing packages
6. Ensure Bun is used for all CI/CD pipelines and automation scripts
7. Document any exceptions where Node/npm must be used
Command mappings:
1. Installation and Path:
- Primary: Use Bun from PATH if available
- Fallback: $HOME/.bun/bin/bun
- Always use command path resolution pattern from command-paths.mdc
2. Package Management:
- Use Bun instead of Node/npm for all package management
- Replace npm scripts with Bun equivalents in package.json
- Use Bun for installing, running, and testing packages
3. Command Mappings:
- npm install -> bun install
- npm run -> bun run
- node -> bun
4. CI/CD and Automation:
- Ensure Bun is used for all CI/CD pipelines
- Document any exceptions where Node/npm must be used
- Use build.sh for consistent builds across environments
Never use npm or node commands directly.
@ -26,11 +30,25 @@ metadata:
examples:
- input: |
# Running tests
COMMAND="test"
output: "~/.bun/bin/bun test"
# Bad: Using absolute path directly
~/.bun/bin/bun test
output: |
# Good: Try PATH first
if command -v bun >/dev/null 2>&1; then
BUN_CMD="bun"
else
BUN_CMD="$HOME/.bun/bin/bun"
fi
$BUN_CMD test
- input: |
# Installing packages
PACKAGE="express"
output: "~/.bun/bin/bun add express"
# Bad: Using npm commands
npm install express
output: |
# Good: Using Bun with PATH resolution
if command -v bun >/dev/null 2>&1; then
BUN_CMD="bun"
else
BUN_CMD="$HOME/.bun/bin/bun"
fi
$BUN_CMD add express

49
.cursor/rules/go.mdc Normal file
View file

@ -0,0 +1,49 @@
---
description: Standards for Go development, including installation paths and build preferences
globs: **/*.{go,mod,sum}
---
<rule>
When working with Go:
1. Installation and Path:
- Primary: Use Go from PATH if available
- Fallback: /usr/local/go/bin/go
- Always use command path resolution pattern from command-paths.mdc
2. Dependencies:
- Prefer pure Go implementations over CGO when available
- Examples:
- Use github.com/glebarez/sqlite over gorm.io/driver/sqlite
- Document any CGO dependencies in go.mod comments
3. Build Process:
- Always run `go mod tidy` after dependency changes
- Verify builds work without CGO: `CGO_ENABLED=0 go build`
- Use build.sh for full application builds
4. Module Management:
- Keep go.mod and go.sum in sync
- Document version constraints
- Run `go mod verify` before commits
metadata:
priority: high
version: 1.0
</rule>
examples:
- input: |
# Bad: Using CGO-dependent SQLite
import "gorm.io/driver/sqlite"
output: |
# Good: Using pure Go SQLite
import "github.com/glebarez/sqlite"
- input: |
# Bad: Direct dependency add
go get some/package
output: |
# Good: Add dependency and tidy
go get some/package
go mod tidy
go mod verify

View file

@ -23,6 +23,6 @@ $BUN_CMD run build
mkdir -p build/css
cp static/css/bulma.min.css build/css/
# Build backend
# Build backend (without CGO)
popd
$GO_CMD build -o notes-app
CGO_ENABLED=0 $GO_CMD build -o notes-app