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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ valk-guard-example/
Workflow install target is configured as:

```text
github.com/valkdb/valk-guard/cmd/valk-guard@latest
github.com/valkdb/valk-guard/cmd/valk-guard.0.0-20260304065917-b9d9468a4ea3@latest
```

Rationale:

- This repository is a demo showcase; tracking latest keeps examples aligned with current built-in behavior.
- If you need strict reproducibility, pin a fixed tag in workflow `VALK_GUARD_INSTALL_REF`.
- This repository is a demo showcase, but CI is pinned to a known-good valk-guard build to keep output shape stable.
- Pinning avoids format drift that can break downstream tooling steps (for example: `Convert to reviewdog format`).
- When upgrading, bump `VALK_GUARD_INSTALL_REF` intentionally and verify the full workflow output.

## Creating Demo PRs (one rule at a time)

Expand Down
15 changes: 15 additions & 0 deletions demo/violations/dist2-vg004-006/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dist 2: VG004-VG006

This demo bundle intentionally triggers:

- VG004 (unbounded select)
- VG005 (LIKE with leading wildcard)
- VG006 (`SELECT ... FOR UPDATE` without `WHERE`)

Coverage in this bundle:

- SQL files
- Go `database/sql`
- Goqu
- Python ORM
- Python non-ORM (`session.execute(text(...))`)
9 changes: 9 additions & 0 deletions demo/violations/dist2-vg004-006/go/goqu_queries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package demo

import goqulib "github.com/doug-martin/goqu/v9"

func GoquViolations() {
_ = goqulib.L("SELECT id, email FROM users WHERE active = true")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true

_ = goqulib.L("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Query: SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1

_ = goqulib.L("SELECT id FROM users FOR UPDATE")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE

}
13 changes: 13 additions & 0 deletions demo/violations/dist2-vg004-006/go/std_queries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package demo

import (
"context"
"database/sql"
)

func StdViolations(db *sql.DB) {
ctx := context.Background()
_, _ = db.QueryContext(ctx, "SELECT id, email FROM users WHERE active = true")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true

_, _ = db.QueryContext(ctx, "SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Query: SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1

_, _ = db.QueryContext(ctx, "SELECT id FROM users FOR UPDATE")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE

}
16 changes: 16 additions & 0 deletions demo/violations/dist2-vg004-006/python/orm_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from sqlalchemy import text
from sqlalchemy.orm import Session

from models import User


def orm_unbounded_select(session: Session):
return session.query(User.id, User.email).filter(User.active.is_(True)).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Origin: SQLAlchemy query builder | Query: SELECT "User"."id", "User"."email" FROM "User" WHERE 1=1



def orm_like_leading_wildcard(session: Session):
return session.query(User.id).filter(User.email.like("%@example.com")).limit(1).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Origin: SQLAlchemy query builder | Query: SELECT "User"."id" FROM "User" WHERE "User"."email" LIKE '%@example.com' LIMIT 1



def orm_select_for_update_no_where(session: Session):
return session.execute(text("SELECT id FROM users FOR UPDATE")).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE

16 changes: 16 additions & 0 deletions demo/violations/dist2-vg004-006/python/raw_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from sqlalchemy import text
from sqlalchemy.orm import Session


def raw_unbounded_select(session: Session):
return session.execute(text("SELECT id, email FROM users WHERE active = true")).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true



def raw_like_leading_wildcard(session: Session):
return session.execute(
text("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1")
).all()
Comment on lines +10 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Query: SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1



def raw_select_for_update_no_where(session: Session):
return session.execute(text("SELECT id FROM users FOR UPDATE")).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT id, email FROM users WHERE active = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Query: SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT id FROM users FOR UPDATE;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE