All Projects → zio → zio-shield

zio / zio-shield

Licence: Apache-2.0 license
Enforce best coding practices with ZIO

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to zio-shield

zio-nio
A small, unopinionated ZIO interface to NIO.
Stars: ✭ 177 (+110.71%)
Mutual labels:  zio
zio-redis
A ZIO-based redis client
Stars: ✭ 76 (-9.52%)
Mutual labels:  zio
event-driven-messenger
No description or website provided.
Stars: ✭ 43 (-48.81%)
Mutual labels:  zio
code-examples-manager
Software tool to manage your notes and code examples, to publish them as gists or snippets
Stars: ✭ 26 (-69.05%)
Mutual labels:  zio
bfect
Some bifunctor IO type classes
Stars: ✭ 19 (-77.38%)
Mutual labels:  zio
zorechka-bot
Github bot for keeping your Bazel dependencies up-to-date and clean
Stars: ✭ 25 (-70.24%)
Mutual labels:  zio
classy-optics
🔎 Source code shown at my talks at Scale by the Bay 2018 and Scalar 2019
Stars: ✭ 25 (-70.24%)
Mutual labels:  zio
idealingua-v1
IdeaLingua RPC for Scala, TypeScript, C#, Go
Stars: ✭ 13 (-84.52%)
Mutual labels:  zio
zio-http4s-example
For anyone who's struggling to put an http4s server together with ZIO
Stars: ✭ 19 (-77.38%)
Mutual labels:  zio
podpodge
Convert YouTube playlists to audio-only RSS feeds for podcast apps to consume.
Stars: ✭ 32 (-61.9%)
Mutual labels:  zio
zio-telemetry
ZIO-powered OpenTelemetry library
Stars: ✭ 93 (+10.71%)
Mutual labels:  zio
etlflow
EtlFlow is an ecosystem of functional libraries in Scala based on ZIO for writing various different tasks, jobs on GCP and AWS.
Stars: ✭ 38 (-54.76%)
Mutual labels:  zio
free-arrow
Implementation of the Free Arrow in Scala and other helpful tools for working with Arrows
Stars: ✭ 14 (-83.33%)
Mutual labels:  zio
tamer
Standalone alternatives to Kafka Connect Connectors
Stars: ✭ 42 (-50%)
Mutual labels:  zio
zio-event-sourcing
Purely functional concurent and scalable persistance layer implementing CQRS
Stars: ✭ 34 (-59.52%)
Mutual labels:  zio
tutorials
🎥 Source code of the examples shown in the video tutorials
Stars: ✭ 18 (-78.57%)
Mutual labels:  zio
conduktor-coding-challenge
Want to work with us? Here is a mini-coding challenge you can try :)
Stars: ✭ 41 (-51.19%)
Mutual labels:  zio
Zio
ZIO — A type-safe, composable library for async and concurrent programming in Scala
Stars: ✭ 3,167 (+3670.24%)
Mutual labels:  zio
zio-pulsar
Apache Pulsar client for Scala with ZIO and ZIO Streams integration.
Stars: ✭ 16 (-80.95%)
Mutual labels:  zio
zio-entity
Zio-Entity, a distributed, high performance, functional event sourcing library
Stars: ✭ 68 (-19.05%)
Mutual labels:  zio

ZIO Shield 🛡️

Project Stage
Project stage

Build Status

ZIO Shield statically analyses the source code, enforcing best coding practices with ZIO.
It aims to keep your code pure, total and clean with the help of powerful ZIO ecosystem.

Powered by Scalafix and Scalazzi rules.

Installation

sbt

Add zio-shield sbt plugin to your project/plugins.sbt:

addSbtPlugin("dev.zio" % "zio-shield" % "0.1.0")

It will add semanticdb-scalac compiler plugin and -Yrangepos scalac option to your project settings if they doesn't exist. They are needed to generate SemanticDb files for static analysis.

Usage

Running shield command will start the analysis.

> shield
[warn] ZioShieldShowcase.scala:23:7: error: possibly nullable
[warn]   def nullable(): Response = {
[warn]       ^^^^^^^^
[warn] ZioShieldShowcase.scala:24:18: error: nullable: null usage
[warn]     GoodResponse(null)
[warn]                  ^^^^
[warn] ZioShieldShowcase.scala:27:7: error: possibly nullable
[warn]   def handleResponse(response: Response): Unit = {
[warn]       ^^^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:40:24: error: possibly nullable
[warn]         handleResponse(nullable())
[warn]                        ^^^^^^^^
[warn] ZioShieldShowcase.scala:27:7: error: possible partial symbol
[warn]   def handleResponse(response: Response): Unit = {
[warn]       ^^^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:32:7: error: not total: throwing exceptions
[warn]       throw new RuntimeException("Bad response!")
[warn]       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:28:18: error: type casting
[warn]     if (response.isInstanceOf[BadResponse]) {
[warn]                  ^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:29:34: error: type casting
[warn]       val badResponse = response.asInstanceOf[BadResponse]
[warn]                                  ^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:34:35: error: type casting
[warn]       val goodResponse = response.asInstanceOf[GoodResponse]
[warn]                                   ^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:39:9: error: ignored expression
[warn]         handleResponse(alwaysGood())
[warn]         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:40:9: error: ignored expression
[warn]         handleResponse(nullable())
[warn]         ^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn] ZioShieldShowcase.scala:8:7: error: Future returning method
[warn]   def bigComputation(data: String): Future[Int] = Future {
[warn]       ^^^^^^^^^^^^^^
...

ZioShieldShowcase.scala source code located here.

Configuration

You can set shieldFatalWarnings sbt setting to make all warnings fatal, blocking you build if there are any problems detected by ZIO Shield.

shieldFatalWarnings := true
> shield
[error] ZioShieldShowcase.scala:23:7: error: possibly nullable
[error]   def nullable(): Response = {
[error]       ^^^^^^^^
...

To exlude specific rules from analysis you can create .shield.yaml file in the project root and specify exludedRules option.

# .shield.yaml
excludedRules: [ZioShieldNoIgnoredExpressions]

metals

For using ZIO Shield with metals you should provide custom version of metals language server.

In vscode it can be done in your settings.json:

  "metals.customRepositories": ["central", "bintray:vovapolu/maven"],
  "metals.serverVersion": "0.7.6-zio-shield-RC0"

And then run Metals: Restart server command or just restart the editor.

metals1

metals2

Troubleshooting

  • Warnings are not shown

    Run Metals: Import build in vscode. If it doesn't help restart the editor and try again.

Rules

  • ZioShieldNoFutureMethods blocks any val or def that has type of Future[...]
  • ZioShieldNoIgnoredExpressions blocks ignored expressions except in ZIO.effect* blocks
  • ZioShieldNoReflection blocks all methods from scala.reflect, java.lang.reflect and java.lang.Class
  • ZioShieldNoTypeCasting blocks asInstanceOf, isInstanceOf and any case x: Y except in ZIO.effect* blocks
  • ZioShieldNoImpurity blocks direct usages of Unit returning methods and indirect usages through other methods except in ZIO.effect* blocks
  • ZioShieldNoIndirectUse blocks "effectful" methods, which contain usages of ZIO.effect*, expect when they are defined in ancestors of "pure" traits, i.e. traits without methods that use ZIO.effect*.
  • ZioShieldNoNull blocks direct null usages and indirect usages through other methods except in ZIO.effect* blocks
  • ZioShieldNoPartial blocks direct throw and try {...} catch ... usages and indirect usages through other methods except in ZIO.effect* blocks
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].