Suppressing warnings in code

Is there an option to suppress specific warnings in code? I have two use cases in my work project:

  • My renderer library uses a type-level machinery to render tables in a type-safe way. I don’t annotate toplevel declarations of renderer types as those would usually take about 20 lines of code with all the foralls and constraints. I usually decide to put them into where clauses, but they look better in a toplevel context. I would like to suppress the “no-type-annotation” warning.
  • Another use case (perhaps I could live with this one) is where my http client library imports a ton of request/response types from http types, and making all the imports explicit again takes already like 5 lines of code. I would like to suppress “implicit import” warning.

Is there such a mechanism, or plans to implement it?

4 Likes

If you use PSA, you can suppress warnings from the output of your build command. Instead of running, e.g., spago build, you can run
spago build --purs-args "--censor-codes=MissingTypeDeclaration,<ImplicitImport>" (I don’t know the name of the implicit import warning off-hand - you’d have to replace that with it’s actual name). Then you’ll see build output that looks something like this
image
saying that it found 3 warnings in your source code, but all were censored.

Note that I use VS Code for my IDE, and it does not suppress the warnings in VS Code, only in the CLI output.

1 Like

Yeah, I use purescript-language-server in a VSCode.

I have not found a way for VS Code to stop showing the yellow underlines. This might be helpful even though it doesn’t solve your problem, but for no type annotations, I think it highlights the entire definition, which can be a little overwhelming for a warning you’re trying to ignore. Sometimes it works better if you include an annotation, but set the whole type to just a wildcard, and then the highlighted warning is just on the wildcard (and you can mouse over it to see the warning, which tells you what the inferred type is, so it can actually be helpful). I don’t recall though how that works with type variables and constraints, so that might not help in your case.

1 Like

Haha, I thought about it too, but when I add just

renderer :: _
renderer = ...

I get an error that some constraints are not fulfilled.

I have this in my vscode config

  "purescript.censorWarnings": [
    "UnusedName",
    "ShadowedName",
    "UserDefinedWarning"
  ]
3 Likes

If the compiler can infer a type for a declaration with no type annotation, it probably shouldn’t produce an error when providing a wildcard annotation like that. This might be a bug; if you could put together a minimal reproducing case and report it that would be very much appreciated.

2 Likes

The compiler replaces wild cards with unification variables, which are monotypes. You would need to special case a singleton wildcard annotation.

And you can combine the censorWarnings setting with VSCode’s ability to specify your settings on a per-Workspace or per-Folder level.

I have a stack censored (same as those of Adrielus, but also several to do with explicit/implicit imports) in the Workspace file of my more scrap-book / playground-like repos. But the default for my User / Remote level is to have no warnings censored. Can’t trust myself to remember reenable them for each new /or cloned repo where it would matter.

1 Like

Ah right ok, never mind then.