Code Monkey home page Code Monkey logo

silencer's Introduction

Scala compiler plugin for warning suppression

Build Status Maven Central

Scala has no local warning suppression (see e.g. scala/bug/issues/1781 for discussion). This plugin aims to change the situation. The direct motivation for this plugin is to be able to turn on -Xfatal-warnings option in Scala compiler and enforce zero-warning policy but still be able to consciously silent out warnings which would otherwise be a pointless noise.

Usage

If you're using SBT, simply add these lines to your build.sbt to enable the plugin:

val silencerVersion = "1.2.1"

libraryDependencies ++= Seq(
  compilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion),
  "com.github.ghik" %% "silencer-lib" % silencerVersion % Provided
)

Silencer currently works with Scala 2.11.4+, 2.12.0+ and 2.13.0-M4+. Also note that since both silencer-plugin and silencer-lib are compile time only dependencies, Silencer can also be used in ScalaJS and Scala Native without having to be cross compiled for it.

Annotation-based suppression

With the plugin enabled, warnings can be silenced using the @com.github.ghik.silencer.silent annotation. It can be applied on a single statement or expression, entire def/val/var definition or entire class/object/trait definition.

import com.github.ghik.silencer.silent

@silent class someClass { ... }
@silent def someMethod() = { ... }
someDeprecatedApi("something"): @silent

The @silent annotation suppresses all warnings in some code fragment. There is currently no way to silent out only specific classes of warnings, like with @SuppressWarnings annotation in Java.

Global regex-based suppression

You can also suppress warnings globally based on a warning message regex. In order to do that, pass this option to scalac:

scalacOptions += "-P:silencer:globalFilters=[semi-colon separated message patterns]"

Status

Silencer is succesfully being used in AVSystem open source and closed projects, e.g. AVSystem Scala Commons Library

silencer's People

Contributors

ghik avatar rogach avatar xuwei-k avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.