-
Notifications
You must be signed in to change notification settings - Fork 14
Configurable and suppressable warnings #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
perhaps the right context to tackle this would be in association with backporting the structured-errors stuff form Dotty |
This would be useful for tools like scalafix. In particular, it would be useful to have the ability override the severity level per message kind, despite presence of -Xfatal-warnings. It would also be useful to have unique identifiers attached to each reported message (cc/ scalameta/scalameta#924) |
Unique identifiers would be appreciated for scala-clippy as well. Currently we are using regexes to try to determine the message type. |
The other thing that is sorely lacking currently is a general escape hatch mechanism usable per-use-site, e.g. |
I think having |
Agree. Wartremover uses @SuppressWarnings rather than comments, but only because it has to implement that itself. scalastyle uses comments, as you say, and it's very fragile/dangerous. It would be amazing if there was a single annotation where you could specify the particular warnings to silence, and it was respected by scalac, scalafix linters, wartremover, ... |
Get excited? scala/scala3#5337 |
Maybe bundled with this we can do scala/bug#8829. |
done!!! scala/scala#8373 |
Motivation
Broken Windows Theory: clean codebases that keep warnings under control encourage to keep the codebase clean.
-Werror
can often not be enabled, for example due to non-avoidable deprecation warnings when cross-building.This proposal has two goals: make warnings globally configurable using compiler flags, and allow suppressing warnings locally.
What we have today
@unchecked
in pattern matching@unused
: omit-Ywarn-unused
/-Xlint:unused
warnings for annotated declarations (added in Annotationunused
to suppress warnings scala#7623, discussion at Helper for unused parameters bug#10790)@migration
-Xmigration:<fromScalaVersion>
, show warnings that have a version bigger thanfromScalaVersion
private[scala]
Considerations for new functionality
Global Configuration: allow users to configure what is reported as error, warning, info, or not at all.
-Werror
, which escalates all warnings-Wconfig
was proposed in deprecatedError + restricted annotation scala#7790 (comment)@restricted
warningssince
version -- for cross-building, upgrading (adriaan has a WIP, see below)since
is not only used in standard library, each library has its own version numbersdeprecated
says "Library authors should prepend the name of their library to the version number"-W
Managing many errors/warnings
-Xmaxerrs
,-Xmaxwarns
-deprecation
and-feature
to show all warnings, one-line-summary otherwise-Werror
still breaks Consider reporting deprecation and feature warnings by default bug#8829Local suppression
@SuppressWarnings
,@silent
(see below)Links, Discussions, WIPs
@unchecked
annotation to work for an annotated scope, e.g.@unchecked class C { ... }
for all code in a class-Xreporter
command line-Xsuppress-message-ids
,-Xsuppress-warning-kinds
global flags. dotty has error/warning ids and kinds (not sure what kinds are).-deprecation-suppress
flag. conditions on:since
, definition package, use site packageforRemoval
,since
Xlint
check to ensure that@deprecated
has explicit arguments@restricted
/@compileTimeOnly
as generalization of@deprecated
to mark APIsseverity
parameter. (should we do that? or make them warnings, allow users to change severity?)@deprecated
with configurable reporting is enough / better than a new annotation (deprecatedError + restricted annotation scala#7790 (comment)).Existing Tools
Java:
@java.lang.SuppressWarnings
unchecked
,deprecated
, lint warnings (seejavac -X
to get the list). Eclipse supports may more (https://stackoverflow.com/questions/1205995/what-is-the-list-of-valid-suppresswarnings-warning-names-in-java)Silencer https://github.com/ghik/silencer
@silent
for scoped suppression@silent("deprecated")
for message pattern, regular expresisonWartremover http://www.wartremover.org/
wartremoverErrors ++= Warts.unsafe
,wartremoverWarnings ++= ...
@SuppressWarnings(Array("org.wartremover.warts.Var", "org.wartremover.warts.Null"))
on declarationwartremoverExcluded += baseDirectory.value / "src" / "main" / "scala" / "SomeFile.scala"
in sbtRelated Topics
Downstream impact
Better warning & error messages (considered out of scope / separate proposal)
-explain
, https://github.com/softwaremill/scala-clippy)Rough Syntax Proposal
Syntax needs to be clarified and probably made less ambiguous, so far i only thought about categories, filters and severities.
Global Configuration
-Wconf <config>
lint-x
for every-Xlint:<x>
,lint
for all lintsx
for every-W<x>
(dead-code
,value-discard
,unused
)deprecation
language-x
for every-language:<x>
,language
for all feature flagsany
: matches any warning, whether or not it's in one of the categories above - filterspos:com.package.Class
where the warning is triggered, displayedmsg:expr
-- need to decide details (full regex? only simple wildcard? substring match?)from:com.package.Class
where the deprecated entity is declaredsince<2.12
. see https://github.com/scala/scala/pull/7728/files#diff-3da64c3c223da7bbf9970ac26f9fb9b8R108. examples:since<Library 2.3
,since<*2.3
to match any character prefix ("foo bar 2.3"), seems useful in combination withfrom:pkg
e(rror)
w(arning)
/w-summary
/w-group
i(nfo)
/i-summary
/i-group
: show, but don't fail on-Werror
(useful?)s(ilent)
warning
andinfo
:summary
: there were n warnings, per category.group
: show every warning with the same mesage once, mention how many instances.Note: this only configures how warnings are emitted.
-Xlint
,-Wunused
,Wdead-code
etc are still required to make the compiler do the additional checks and emit warnings.First matching rule wins
Relation to existing functionality
-Wconf deprecation:language:warning-summary,any:warning
-Wconf
adds rules on the left, i.e., the default comes last-deprecation
is the same as-Wconf deprecation:warning
-feature
is-Wconf language:warning
-language:x
is-Wconf language-x:silent
import scala.language.x
is@silent("language-x")
(see below)Examples
-Wconf any:pos:com.corp.yolo:silent
-Wconf deprecation:from:org.fancy.library:since<*2.2:e,deprecation:i-group
error on some deprecations, info-group others-Wconf 'any:msg:pure expression does nothing in statement position:s'
Local Suppression
@silent
: basically the same as https://github.com/ghik/silencer#annotation-based-suppression@silent class C
,@silent def f
{foo; bar}: @silent
@silent("deprecated")
,@silent("deprecated,language-higherKinds")
@silent(msg="comparing true and false will always")
@silent
doesn't silence anythingThe text was updated successfully, but these errors were encountered: