Newbie question: Suppress some warnings?

When I build stuff with spago I get lots of warnings. Particular the following two I would like tosupress:

  1. Name f was introduced but not used. and
  2. Module Prelude has unspecified imports, consider using the explicit form…

Is that possible? Also, is this advisable? I think particularly with Prelude it is quite cumbersome to specify all imports, but I’m just a newbie…

1 Like

You can suppress specific warnings using psa: GitHub - natefaubion/purescript-psa: Error/Warning reporting frontend for the PureScript compiler

The unspecified imports warning only triggers if there is more than one imported module with unspecified imports in a particular module. The idea is that you can import Prelude without having to specify everything you’re using, but other imports should either be qualified or use the explicit form, so that if you come back to this code in a month’s time you are able to track down where everything is coming from.

1 Like

It also protects you from name collisions in the future, as if you’re open-importing multiple modules and some of them come from external libraries, new members being added to these libraries could result in conflicts.

3 Likes

In the PureScript book, a lot of warnings are expected. The book’s code breaks the importing best-practices in several places so that the user doesn’t have to ever edit the imports in the test modules. The aim is that the only edits needed in the test modules is just uncommenting some tests as the code being tested is implemented. The alternatives to just ignoring all the warnings would be to use psa and exclude those 2 expected warnings as Harry suggested, or to take control of the imports in each test module and edit them to import each function one at a time as you implement them.

2 Likes

Thanks for all the responses. Much apreciated!

Taking it all in I might indeed specify all imports explicitly - it will help me to remember better where things are…

The poster’s original question was about suppressing warnings using spago build. That’s my question too–also from a newbie. It’s not clear to me whether it’s possible to invoke psa as an intermediate processor from spago.

On the other hand, I don’t know how to build a project using psa (or purs) directly. I tried psa src/Main.purs, where that’s the only source file but I get a lot of ModuleNotFound errors that I don’t get with spago build. I assume that spago build is calling purs or some other program with arguments that tell it about libraries listed in spago.yaml. I’m using spago@next as you can tell.
Thanks!

Spago indeed runs the compiler under the hood. You can see the commands run if you use verbose mode:

Psa is now included in Spago directly so there’s no need for a standalone tool. You can configure it in your spago.yaml or via flags passed to spago

1 Like

Thanks @thomashoneyman. This is what I needed. However, I’m having trouble figuring out the syntax to make it work.

Based on the comments in the documentation you linked and on error messages when my experiments in spago.yaml didn’ work, it appears that censorLibraryWarnings: has to be followed either by "all", or by a yaml array of strings naming Purescript warning names, I think (or of prefix strings–not sure what the syntax is). But when I add “all” or something like [ "MissingTypeDeclaration" ], after `censorLibraryWarnings:', no warning is suppressed, as far as I can see. I tried some other yaml array syntaxes, and using single-quotes or no quotes for strings, and didn’t get an error from the config file but again no warnings were suppressed.

workspace:
  buildOpts:
    censorLibraryWarnings: 
       <what goes here?>

It also appears the spago option -v for verbose ouptut has become an option for version number in spago@next. I’m not seeing anything about how to produce verbose output. I tried a couple of obvious things, but they didn’t work. My guess is that this is probably just an issue due to spago@next being alpha.

Maybe the same is true for the spago.yaml section for suppressing warnings: It’s not working yet because spago@next is still alpha.

Hm — I haven’t tried censoring warnings from a library recently; what library are you using? I can try and reproduce.

Here’s an example of censoring warnings in your source code. The two relevant files are this spago.yaml and Main.purs.

Starting with this package definition you’ll see any warnings in your source:

package:
  name: warning-tester
  dependencies:
    - effect
    - prelude
workspace:
  packageSet:
    registry: 67.0.0

This source will produce an unused import warning:

module Main where

import Prelude

import Effect (Effect, forE)

main :: Effect Unit
main = pure unit

Here’s what I see on spago build:

[WARNING 1/1 UnusedExplicitImport] src/Main.purs:5:1

  5  import Effect (Effect, forE)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  The import of module Effect contains the following unused references:
    forE
  It could be replaced with:
    import Effect (Effect)

However, if you then adjust your spago.yaml to censor warnings:

package:
  name: warning-tester
  dependencies:
    - effect
    - prelude
  build:
    censorProjectWarnings:
      - UnusedImport
workspace:
  packageSet:
    registry: 67.0.0

Then on build there are no longer any warnings:

✓ Selecting package to build: warning-tester

Downloading dependencies...
Building...
           Src   Lib   All
Warnings     0     0     0
Errors       0     0     0

✓ Build succeeded.
1 Like

Oh, also, with the -v flag — correct, if you just run spago -v you’ll see the version, but if you run a command with -v then you get verbose mode. For instance:

$ spago build -v
(...omitting a few lines here...)
✓ Selecting package to build: spago-tester
[     101ms] Package path: "."
[     101ms] Parsing the lockfile...
[     124ms] Parsed the lockfile
[     124ms] Lockfile is up to date, using it
[     124ms] Found the lockfile, using the package set from there
[     125ms] Workspace root path: "/Users/trh/Desktop/spago-tester"
[     125ms] Local cache: .spago
[     125ms] Requested to install these packages: []
[     126ms] Downloading dependencies...
[     144ms] Building...
[     145ms] Running command:
purs compile --codegen corefn,docs,js,sourcemaps --json-errors .spago/BuildInfo.purs .spago/p/console-6.1.0/src/**/*.purs .spago/p/effect-4.0.0/src/**/*.purs .spago/p/prelude-6.0.2/src/**/*.purs src/**/*.purs
(...omitting some more lines...)
1 Like

Thanks again @thomashoneyman. Perfect–censorProjectWarnings was what I was looking for. This is great! No more annoying warnings (until I want them, and turn them on). Thanks for the detailed illustration, and for giving me an example of the yaml syntax for specifying particular warnings.

I had tried censorLibraryWarnings only because it appeared first in the example configuration file. I didn’t know what it meant (still don’t, really), but it sounded like what I was looking for. I didn’t realize that I needed to scroll further to find censorProjectWarnings.

Thanks also for spago build -v. That looks useful.

Glad it helped! The censorLibraryWarnings option is for when a dependency of your project has warnings, and you want to censor those. For instance, if the effect library itself had warnings then you’d want the censorLibraryWarnings option.

1 Like