All Projects → ghik → Silencer

ghik / Silencer

Licence: apache-2.0
Scala compiler plugin for warning suppression

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Silencer

Idea Php Toolbox
Collections of tools and improvements to make PhpStorm a little bit better
Stars: ✭ 147 (-38.49%)
Mutual labels:  annotation
Cloud annotation tool
L-CAS 3D Point Cloud Annotation Tool
Stars: ✭ 182 (-23.85%)
Mutual labels:  annotation
Dart Json Mapper
Serialize / Deserialize Dart Objects to / from JSON
Stars: ✭ 206 (-13.81%)
Mutual labels:  annotation
Controllerextrabundle
Controller extra Bundle for Symfony2
Stars: ✭ 157 (-34.31%)
Mutual labels:  annotation
3d Bat
3D Bounding Box Annotation Tool (3D-BAT) Point cloud and Image Labeling
Stars: ✭ 179 (-25.1%)
Mutual labels:  annotation
Atlas
ATLAS - Three commands to start analysing your metagenome data
Stars: ✭ 187 (-21.76%)
Mutual labels:  annotation
Jupiter
jupiter是一个aio web框架,基于aiohttp。支持(restful格式、扫描注解、依赖注入、jinja2模板引擎、ORM框架)等。
Stars: ✭ 140 (-41.42%)
Mutual labels:  annotation
Idea Php Annotation Plugin
Add PHP annotation support for PhpStorm and IntelliJ
Stars: ✭ 216 (-9.62%)
Mutual labels:  annotation
H
Annotate with anyone, anywhere.
Stars: ✭ 2,271 (+850.21%)
Mutual labels:  annotation
React Image Annotation
An infinitely customizable image annotation library built on React
Stars: ✭ 203 (-15.06%)
Mutual labels:  annotation
Open Semantic Etl
Python based Open Source ETL tools for file crawling, document processing (text extraction, OCR), content analysis (Entity Extraction & Named Entity Recognition) & data enrichment (annotation) pipelines & ingestor to Solr or Elastic search index & linked data graph database
Stars: ✭ 165 (-30.96%)
Mutual labels:  annotation
Aubio
a library for audio and music analysis
Stars: ✭ 2,601 (+988.28%)
Mutual labels:  annotation
Genometools
GenomeTools genome analysis system.
Stars: ✭ 186 (-22.18%)
Mutual labels:  annotation
Pdfanno
Linguistic Annotation and Visualization Tool for PDF Documents
Stars: ✭ 156 (-34.73%)
Mutual labels:  annotation
Pcat open source
PointCloud Annotation Tools, support to label object bound box, ground, lane and kerb
Stars: ✭ 209 (-12.55%)
Mutual labels:  annotation
Annotorious
A JavaScript library for image annotation
Stars: ✭ 138 (-42.26%)
Mutual labels:  annotation
Hover
🚤 Never spend O(n) to annotate data again. Fun and precision come free.
Stars: ✭ 183 (-23.43%)
Mutual labels:  annotation
Prodigy Recipes
🍳 Recipes for the Prodigy, our fully scriptable annotation tool
Stars: ✭ 229 (-4.18%)
Mutual labels:  annotation
Errant
ERRor ANnotation Toolkit: Automatically extract and classify grammatical errors in parallel original and corrected sentences.
Stars: ✭ 208 (-12.97%)
Mutual labels:  annotation
Grasp
A reliable org-capture browser extension for Chrome/Firefox
Stars: ✭ 193 (-19.25%)
Mutual labels:  annotation

Silencer: Scala compiler plugin for warning suppression

Build Status Maven Central

NOTE: Scala 2.13.2 and 2.12.13 introduced configurable warnings. This means that unless you're still cross compiling for Scala 2.11, this plugin is obsolete, and you should use @nowarn.

If you're still cross compiling for 2.11 then this plugin can be used in conjunction with scala-collection-compat in order to suppress warnings in all Scala versions using @nowarn.

Setup

If you're using SBT, add this to your project definition:

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

If you're using Gradle:

ext {
    scalaVersion = "..." // e.g. "2.13.0"
    silencerVersion = "..." // appropriate silencer version
}
configurations {
    scalacPlugin {
        transitive = false
    }
}
dependencies {
    compile "com.github.ghik:silencer-lib_$scalaVersion:$silencerVersion"
    scalacPlugin "com.github.ghik:silencer-plugin_$scalaVersion:$silencerVersion"
}
tasks.withType(ScalaCompile) {
    scalaCompileOptions.additionalParameters =
            configurations.scalacPlugin.collect { "-Xplugin:" + it.absolutePath }
}

Note that since both silencer-plugin and silencer-lib are compile time only dependencies, Silencer can be used in ScalaJS and Scala Native without having to be cross compiled for them.

Annotation-based suppression

With the plugin enabled, warnings can be suppressed using the @com.github.ghik.silencer.silent or @scala.annotation.nowarn 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

Message pattern

By default the @silent annotation suppresses all warnings in some code fragment. You can limit the suppression to some specific classes of warnings by passing a message pattern (regular expression) to the annotation, e.g.

@silent("deprecated") 
def usesDeprecatedApi(): Unit = {
  someDeprecatedApi("something")
}

Using @nowarn

Scala 2.13.2 and 2.12.13 introduced configurable warnings using -Wconf compiler option and @scala.annotation.nowarn. annotation. For Scala 2.11, this annotation is provided by the scala-collection-compat library and interpreted by the silencer plugin.

NOTE: @nowarn in Scala 2.13.2 supports various fine-grained filters (e.g. warning category, message patttern, etc.). Silencer only supports the msg=<pattern> filter - all other filters simply suppress everything, as if there were no filters specified.

Detecting unused annotations

If a @silent annotation does not actually suppress any warnings, you can make silencer report an error in such situation. This can be enabled by passing the checkUnused option to the plugin:

scalacOptions += "-P:silencer:checkUnused"

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=<semicolon separated message regexes>"

Line content based suppression

Filtering may also be based on the content of source line that generated the warning. This is particularly useful for suppressing 'unused import' warnings based on what's being imported.

scalacOptions += "-P:silencer:lineContentFilters=<semicolon separated line content regexes>"

Filename based suppression

Another option is to suppress all warnings in selected source files. This can be done by specifying a list of file path regexes:

scalacOptions += "-P:silencer:pathFilters=<semicolon separated file path regexes>"

NOTE: In order to make builds independent of environment, filename separators are normalized to UNIX style (/) before the path is matched against path patterns.

By default, absolute file path is matched against path patterns. In order to make your build independent of where your project is checked out, you can specify a list of source root directories. Source file paths will be relativized with respect to them before being matched against path patterns. Usually it should be enough to pass project base directory as source root (i.e. baseDirectory.value in SBT):

scalacOptions += s"-P:silencer:sourceRoots=${baseDirectory.value.getCanonicalPath}"

Another good choice for source roots may be actual SBT source directories:

scalacOptions += s"-P:silencer:sourceRoots=${sourceDirectories.value.map(_.getCanonicalPath).mkString(";")}"

Searching macro expansions

By default (starting from version 1.6.0) silencer does not look for @silent annotations in macro expansions. If you want to bring back the old behaviour where both macro expansions and expandees are searched, use the -P:silencer:searchMacroExpansions option.

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].