Home › Scala › Scala 3 Windsurf rules

Scala 3 Windsurf rules

Windsurf rules for Scala 3 projects with sbt or scala-cli: immutable data, ADTs with enums, explicit effects, scalafmt, and MUnit tests.

WindsurfScala

How to use

Save this as .windsurf/rules/scala.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.windsurf/rules/scala.mdDownload  
---
trigger: glob
globs: **/*.scala,**/*.sbt,**/*.sc
---

# Scala 3

- Build with the repo's tool: `sbt compile test` (or `scala-cli test .`). Format with `scalafmt` (config in `.scalafmt.conf`) and fix `scalafix` warnings if configured.
- Scala 3 syntax: `enum` for ADTs, `given`/`using` for context parameters, extension methods instead of implicit classes. Follow the brace style already used in the repo (significant indentation or braces), don't mix them in one file.
- Immutable by default: `case class`, `val`, immutable collections. No `var` or mutable collections outside tight, local performance code.
- No `null`: use `Option`. No `.get` on `Option`/`Try`, and no `asInstanceOf`.
- Model errors as values: `Either[DomainError, A]` or the effect system's typed errors; exceptions only at boundaries.
- Effects: if the project uses Cats Effect (`IO`) or ZIO, keep side effects inside it, never call `unsafeRun*` except in `main`. Don't introduce a second effect library.
- Pattern matches on sealed types/enums must be exhaustive; treat the compiler warning as an error (`-Wunused:all`, `-Xfatal-warnings` or `-Werror` in scalacOptions if present).
- JSON with the repo's library (circe, jsoniter-scala, upickle) via derived codecs; validate input at the edge.
- Public APIs get explicit return types.

## Tests
MUnit (or the repo's framework) with property tests via ScalaCheck for pure logic.

## Done when
`sbt scalafmtCheckAll test` passes with no new warnings.

More: all Scala rules · all Windsurf rules

Related rules

Django Windsurf rules

Windsurf rules for Django 5.2 LTS projects: apps, models and migrations, ORM performance, forms, and tests.

WindsurfDjango

FastAPI Windsurf rules

Windsurf rules for FastAPI apps with Pydantic v2, SQLAlchemy 2.0 async, dependency injection, and pytest.

WindsurfPython / FastAPI

Go concurrency Windsurf rules

Windsurf rules for safe Go concurrency: goroutine lifetimes, context cancellation, errgroup, channels, and the race detector.

WindsurfGo

Go Fiber web API Windsurf rules

Windsurf rules for Go REST APIs on Fiber: fasthttp gotchas, handler layout, validation, middleware, graceful shutdown and app.Test.

WindsurfGo

Go + Gin web API Windsurf rules

Windsurf rules for Go 1.27 REST APIs built with Gin: handlers, binding/validation, middleware, and tests.

WindsurfGo

Apache Kafka producers and consumers Windsurf rules

Windsurf rules for Kafka client code: keys and partitioning, idempotent producers, manual commits after processing, retries and DLQs, and schema evolution.

WindsurfApache Kafka

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.