~wegtam/smederee
~wegtam/smederee/CODINGSTYLE.md
~wegtam/smederee/CODINGSTYLE.md
This document tries to describe the coding style to make it easier for everyone to contribute.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
defaultWithAlign
using the runner dialect scala3
of Scalafmt with some additions..editorconfig
file in the project root MUST exist and SHALL contain the necessary settings.stringNameOption
.defaultWithAlign
preset⇒
SHALL be written as =>
or ←
as <-
and so on.val foo = ???
val bar = foo match {
case something => ???
case _ => ???
}
import java.time.*
) MUST be written (grouped) first, followed by a blank line.import scala.util.Failure
) MUST be written (grouped) last, prefixed by a blank line.munit.
or org.scalacheck.
) SHOULD be put last and grouped.groupedImports = Explode
for Scalafix is intended to rewrite affected code automatically.importsOrder
setting of Scalafix.rewrite.rules
including RedundantBraces
).rewrite.rules
including RedundantParens
).*.sbt
) MUST NOT be formatted via Scalafmt.TODO: Describe danglingParentheses.preset = true
We are using the Twirl templating engine to render templates which reside under src/main/twirl
folders. The most common use case is to render HTML output which is indicated by the .scala.html
file extension. However others are possible for example .scala.txt
for rendering plain text emails.
@for
or @defining
) MAY not be indented to avoid too deeply nested code.@(
a: A,
b: Option[B],
c: Either[A, B]
)(
d: D,
e: Option[E]
)
lazy val library
block inside the build.sbt
file, following these rules:
object Version
having a name clearly identifying the dependency e.g. val cats = "2.8.0"
.val catsCore = "org.typelevel" %% "cats-core" % Version.cats
val catsEffect = "org.typelevel" %% "cats-effect" % Version.catsEffect
project/plugins.sbt
file and be vertically aligned like in the following example:
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
build.sbt
and project/plugins.sbt
) SHALL not be formatted automatically via scalafmt
.The application contains database migrations files and SQL commands / queries for these the following rules apply:
[table].[column]
or "table"."column"
.COMMENT
command. This also applies to each column of a table.COMMENT
statement SHALL NOT be wrapped even if it exceeds 80 characters.CREATE TABLE
statement MUST be split over multiple lines to have the CREATE TABLE
, the starting parenthesis, each column and constraint and the closing parenthesis on a separate line.CONSTRAINT
line MAY be wrapped to span multiple lines if it exceeds 80 characters.CREATE TABLE
statement MUST end with WITH (OIDS=FALSE);
.An example for a database migration SQL file looks like this:
CREATE TABLE sessions
(
id VARCHAR(32) NOT NULL,
uid UUID NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT sessions_pk PRIMARY KEY (id),
CONSTRAINT sessions_fk_uid FOREIGN KEY (uid)
REFERENCES accounts (uid) ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
OIDS=FALSE
);
COMMENT ON TABLE sessions IS 'Keeps the sessions of users.';
COMMENT ON COLUMN sessions.id IS 'A globally unique session ID.';
COMMENT ON COLUMN sessions.uid IS 'The unique ID of the user account to whom the session belongs.';
COMMENT ON COLUMN sessions.created_at IS 'The timestamp of when the session was created.';
COMMENT ON COLUMN sessions.updated_at IS 'The session ID should be re-generated in regular intervals resulting in a copy of the old session entry with a new ID and the corresponding timestamp in this column.';