{"id":15050628,"url":"https://github.com/ghik/silencer","last_synced_at":"2025-05-15T08:07:22.456Z","repository":{"id":30202712,"uuid":"33753632","full_name":"ghik/silencer","owner":"ghik","description":"Scala compiler plugin for warning suppression","archived":false,"fork":false,"pushed_at":"2025-01-17T23:12:58.000Z","size":207,"stargazers_count":254,"open_issues_count":7,"forks_count":33,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-07T03:12:03.095Z","etag":null,"topics":["annotation","compiler-plugin","scala","scala-compiler","suppression","warnings"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-10T22:30:39.000Z","updated_at":"2025-02-21T20:26:10.000Z","dependencies_parsed_at":"2024-02-21T10:27:37.603Z","dependency_job_id":"fb4206c3-3350-4ef4-b1d3-cb8e6f3bf17b","html_url":"https://github.com/ghik/silencer","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghik%2Fsilencer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghik%2Fsilencer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghik%2Fsilencer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghik%2Fsilencer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghik","download_url":"https://codeload.github.com/ghik/silencer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248870968,"owners_count":21175127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation","compiler-plugin","scala","scala-compiler","suppression","warnings"],"created_at":"2024-09-24T21:28:17.085Z","updated_at":"2025-04-14T11:27:41.302Z","avatar_url":"https://github.com/ghik.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Silencer: Scala compiler plugin for warning suppression\n\n[![Build Status](https://travis-ci.org/ghik/silencer.svg?branch=master)](https://travis-ci.org/ghik/silencer)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ghik/silencer-plugin_2.13.2/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ghik/silencer-plugin_2.13.2)\n\n## Compatibility\n\nSilencer is available for Scala 2.11, 2.12, and 2.13.\n\n**NOTE**: Scala 2.13.2 and 2.12.13 introduced [configurable warnings](https://github.com/scala/scala/pull/8373).\nThis means that unless you're still cross compiling for Scala 2.11, this plugin is obsolete, and you should use\n[`@nowarn`](https://www.scala-lang.org/api/current/scala/annotation/nowarn.html).\n\nIf you're still cross compiling for 2.11 then this plugin can be used in conjunction with\n[scala-collection-compat](https://github.com/scala/scala-collection-compat) in order to suppress warnings in all \nScala versions using `@nowarn`.\n\nAs a compiler plugin, Silencer must be separately built for every minor version of Scala. If you find that Silencer is not\navailable for your version of Scala (most likely some newly released one), please contribute - the instructions on how to do it are below :)\n\n### How to add support for a new version of Scala\n\n1. Fork and clone the repository.\n1. Edit `build.sbt` and add the new Scala version to `crossScalaVersions`. Make sure to keep the order of the list,\n   which should start with the newest version.\n1. Invoke `sbt githubWorkflowGenerate`\n1. Commit changes in `build.sbt` and Github workflow definitions\n1. Make a PR :)\n\n## Setup\n\nIf you're using SBT, add this to your project definition:\n\n```scala\nThisBuild / libraryDependencies ++= Seq(\n  compilerPlugin(\"com.github.ghik\" % \"silencer-plugin\" % silencerVersion cross CrossVersion.full),\n  \"com.github.ghik\" % \"silencer-lib\" % silencerVersion % Provided cross CrossVersion.full\n)\n```\n\nIf you're using Gradle:\n\n```groovy\next {\n    scalaVersion = \"...\" // e.g. \"2.13.0\"\n    silencerVersion = \"...\" // appropriate silencer version\n}\nconfigurations {\n    scalacPlugin {\n        transitive = false\n    }\n}\ndependencies {\n    compile \"com.github.ghik:silencer-lib_$scalaVersion:$silencerVersion\"\n    scalacPlugin \"com.github.ghik:silencer-plugin_$scalaVersion:$silencerVersion\"\n}\ntasks.withType(ScalaCompile) {\n    scalaCompileOptions.additionalParameters =\n            configurations.scalacPlugin.collect { \"-Xplugin:\" + it.absolutePath }\n}\n```\n    \nNote that since both `silencer-plugin` and `silencer-lib` are compile time only dependencies, Silencer can be used \nin ScalaJS and Scala Native without having to be cross compiled for them.\n\n## Annotation-based suppression\n\nWith the plugin enabled, warnings can be suppressed using the `@com.github.ghik.silencer.silent` \nor `@scala.annotation.nowarn` annotation. \nIt can be applied on a single statement or expression, entire `def`/`val`/`var` definition or entire \n`class`/`object`/`trait` definition.\n\n```scala\nimport com.github.ghik.silencer.silent\n\n@silent class someClass { ... }\n@silent def someMethod() = { ... }\nsomeDeprecatedApi(\"something\"): @silent\n```\n\n### Message pattern\n\nBy default the `@silent` annotation suppresses *all* warnings in some code fragment. You can limit the suppression to\nsome specific classes of warnings by passing a message pattern (regular expression) to the annotation, e.g.\n\n```scala\n@silent(\"deprecated\") \ndef usesDeprecatedApi(): Unit = {\n  someDeprecatedApi(\"something\")\n}\n```\n\n### Using `@nowarn`\n\nScala 2.13.2 and 2.12.13 introduced [configurable warnings](https://github.com/scala/scala/pull/8373) using `-Wconf` \ncompiler option and `@scala.annotation.nowarn`. annotation. For Scala 2.11, this annotation is provided by the \n[scala-collection-compat](https://github.com/scala/scala-collection-compat) library and interpreted by the `silencer`\nplugin.\n\n**NOTE**: `@nowarn` in Scala 2.13.2 supports various fine-grained filters (e.g. warning category, message pattern, etc.).\nSilencer only supports the `msg=\u003cpattern\u003e` filter - all other filters simply suppress everything, as if there were\nno filters specified.\n\n### Detecting unused annotations\n\nIf a `@silent` annotation does not actually suppress any warnings, you can make `silencer` report an error in such\nsituation. This can be enabled by passing the `checkUnused` option to the plugin:\n\n```scala\nscalacOptions += \"-P:silencer:checkUnused\"\n```\n\n## Global regex-based suppression\n\nYou can also suppress warnings globally based on a warning message regex. In order to do that, pass this option to `scalac`:\n\n```scala\nscalacOptions += \"-P:silencer:globalFilters=\u003csemicolon separated message regexes\u003e\"\n```\n\n## Line content based suppression\n\nFiltering may also be based on the content of source line that generated the warning.\nThis is particularly useful for suppressing 'unused import' warnings based on what's being imported.\n\n```scala\nscalacOptions += \"-P:silencer:lineContentFilters=\u003csemicolon separated line content regexes\u003e\"\n```\n\n## Filename based suppression\n\nAnother option is to suppress all warnings in selected source files. This can be done by specifying a list of file path regexes:\n\n```scala\nscalacOptions += \"-P:silencer:pathFilters=\u003csemicolon separated file path regexes\u003e\"\n```\n\n**NOTE**: In order to make builds independent of environment, filename separators are normalized to UNIX style (`/`) \nbefore the path is matched against path patterns.\n\nBy default, absolute file path is matched against path patterns. In order to make your build independent of where your \nproject is checked out, you can specify a list of source root directories. Source file paths will be relativized with \nrespect to them  before being matched against path patterns. Usually it should be enough to pass project base directory \nas source root (i.e. `baseDirectory.value` in SBT):\n\n```scala\nscalacOptions += s\"-P:silencer:sourceRoots=${baseDirectory.value.getCanonicalPath}\"\n```\n\nAnother good choice for source roots may be actual SBT source directories:\n\n```scala\nscalacOptions += s\"-P:silencer:sourceRoots=${sourceDirectories.value.map(_.getCanonicalPath).mkString(\";\")}\"\n```\n\n## Searching macro expansions\n\nBy default (starting from version 1.6.0) silencer does not look for `@silent` annotations in macro expansions.\nIf you want to bring back the old behaviour where both macro expansions and expandees are searched, use the\n`-P:silencer:searchMacroExpansions` option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghik%2Fsilencer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghik%2Fsilencer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghik%2Fsilencer/lists"}