Skip to content

censorProjectWarnings in monorepo workspace spago.yaml #1316

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 110 additions & 5 deletions CHANGELOG.md

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1384,7 +1384,7 @@ workspace:
# Value 1: "all" - All warnings are censored
all

# Value 2: `NonEmptyArray (Either String { byPrefix :: String })`
# Value 2: `Array (Either String { byPrefix :: String })`
# - String values:
# censor warnings if the code matches this code
# - { byPrefix } values:
@@ -1396,6 +1396,16 @@ workspace:
- byPrefix: >
"Data.Map"'s `Semigroup instance`

# Specify whether to censor warnings coming from the compiler
# for files in workspace project source
# Optional - takes the same values as censorLibraryWarnings above
censorProjectWarnings: all

# Specify whether to censor warnings coming from the compiler
# for files in workspace project tests
# Optional - takes the same values as censorLibraryWarnings above
censorTestWarnings: all

# Specify whether to show statistics at the end of the compilation,
# and how verbose they should be.
# Can be 'no-stats', 'compact-stats' (default), or 'verbose-stats',
11 changes: 7 additions & 4 deletions core/src/Config.purs
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@ module Spago.Core.Config
import Spago.Core.Prelude

import Codec.JSON.DecodeError as CJ.DecodeError
import Data.Array.NonEmpty as NonEmptyArray
import Data.Codec as Codec
import Data.Codec.JSON as CJ
import Data.Codec.JSON.Record as CJ.Record
@@ -349,19 +348,23 @@ workspaceConfigCodec = CJ.named "WorkspaceConfig" $ CJS.objectStrict
type WorkspaceBuildOptionsInput =
{ output :: Maybe RawFilePath
, censorLibraryWarnings :: Maybe CensorBuildWarnings
, censorProjectWarnings :: Maybe CensorBuildWarnings
, censorTestWarnings :: Maybe CensorBuildWarnings
, statVerbosity :: Maybe StatVerbosity
}

buildOptionsCodec :: CJ.Codec WorkspaceBuildOptionsInput
buildOptionsCodec = CJ.named "WorkspaceBuildOptionsInput" $ CJS.objectStrict
$ CJS.recordPropOptional @"output" CJ.string
$ CJS.recordPropOptional @"censorLibraryWarnings" censorBuildWarningsCodec
$ CJS.recordPropOptional @"censorProjectWarnings" censorBuildWarningsCodec
$ CJS.recordPropOptional @"censorTestWarnings" censorBuildWarningsCodec
$ CJS.recordPropOptional @"statVerbosity" statVerbosityCodec
$ CJS.record

data CensorBuildWarnings
= CensorAllWarnings
| CensorSpecificWarnings (NonEmptyArray WarningCensorTest)
| CensorSpecificWarnings (Array WarningCensorTest)

derive instance Eq CensorBuildWarnings

@@ -375,7 +378,7 @@ censorBuildWarningsCodec = Codec.codec' decode encode
where
encode = case _ of
CensorAllWarnings -> CJ.encode CJ.string "all"
CensorSpecificWarnings censorTests -> CJ.encode (CJ.array warningCensorTestCodec) $ NonEmptyArray.toArray censorTests
CensorSpecificWarnings censorTests -> CJ.encode (CJ.array warningCensorTestCodec) censorTests

decode json = decodeNoneOrAll <|> decodeSpecific
where
@@ -385,7 +388,7 @@ censorBuildWarningsCodec = Codec.codec' decode encode

decodeSpecific = CensorSpecificWarnings <$> do
arr <- Codec.decode (CJ.array warningCensorTestCodec) json
except $ Either.note (CJ.DecodeError.basic "Expected array of warning codes") $ NonEmptyArray.fromArray arr
except $ Right arr

data WarningCensorTest
= ByCode String
2 changes: 2 additions & 0 deletions src/Spago/Command/Build.purs
Original file line number Diff line number Diff line change
@@ -116,6 +116,8 @@ run opts = do
, selectedPackages: NEA.toArray selectedPackages
, psaCliFlags: { strict: strictWarnings, statVerbosity: workspace.buildOptions.statVerbosity }
, censorLibWarnings: workspace.buildOptions.censorLibWarnings
, censorProjectWarnings: workspace.buildOptions.censorProjectWarnings
, censorTestWarnings: workspace.buildOptions.censorTestWarnings
}
let
psaArgs =
4 changes: 4 additions & 0 deletions src/Spago/Config.purs
Original file line number Diff line number Diff line change
@@ -89,6 +89,8 @@ type Workspace =
type WorkspaceBuildOptions =
{ output :: Maybe LocalPath
, censorLibWarnings :: Maybe Core.CensorBuildWarnings
, censorProjectWarnings :: Maybe Core.CensorBuildWarnings
, censorTestWarnings :: Maybe Core.CensorBuildWarnings
, statVerbosity :: Maybe Core.StatVerbosity
}

@@ -227,6 +229,8 @@ discoverWorkspace options cwd = do
, buildOptions:
{ output: workspace.config.buildOpts >>= _.output <#> \o -> withForwardSlashes $ rootPath </> o
, censorLibWarnings: _.censorLibraryWarnings =<< workspace.config.buildOpts
, censorProjectWarnings: _.censorProjectWarnings =<< workspace.config.buildOpts
, censorTestWarnings: _.censorTestWarnings =<< workspace.config.buildOpts
, statVerbosity: _.statVerbosity =<< workspace.config.buildOpts
}
, doc: Just workspace.doc
19 changes: 12 additions & 7 deletions src/Spago/Psa.purs
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import Control.Alternative as Alternative
import Control.Monad.Except.Trans (ExceptT(..), runExceptT)
import Control.Monad.Trans.Class (lift)
import Data.Array as Array
import Data.Array.NonEmpty as NonEmptyArray
import Data.Codec.JSON as CJ
import Data.Either (blush)
import Data.Map as Map
@@ -106,12 +105,14 @@ toPathDecisions
, selectedPackages :: Array WorkspacePackage
, psaCliFlags :: PsaOutputOptions
, censorLibWarnings :: Maybe Core.CensorBuildWarnings
, censorProjectWarnings :: Maybe Core.CensorBuildWarnings
, censorTestWarnings :: Maybe Core.CensorBuildWarnings
}
-> Array (Effect (Array (LocalPath -> Maybe PathDecision)))
toPathDecisions { rootPath, allDependencies, selectedPackages, psaCliFlags, censorLibWarnings } =
toPathDecisions { rootPath, allDependencies, selectedPackages, psaCliFlags, censorLibWarnings, censorProjectWarnings, censorTestWarnings } =
projectDecisions <> dependencyDecisions
where
projectDecisions = selectedPackages <#> \selected -> toWorkspacePackagePathDecision { selected, psaCliFlags }
projectDecisions = selectedPackages <#> \selected -> toWorkspacePackagePathDecision { selected, psaCliFlags, censorProjectWarnings, censorTestWarnings }

dependencyDecisions =
map toDependencyDecision
@@ -129,6 +130,8 @@ toPathDecisions { rootPath, allDependencies, selectedPackages, psaCliFlags, cens
toWorkspacePackagePathDecision
{ selected: p
, psaCliFlags
, censorProjectWarnings
, censorTestWarnings
}
_ -> do
let pkgLocation = Tuple.uncurry (Config.getLocalPackageLocation rootPath) dep
@@ -144,23 +147,25 @@ toPathDecisions { rootPath, allDependencies, selectedPackages, psaCliFlags, cens
toWorkspacePackagePathDecision
:: { selected :: WorkspacePackage
, psaCliFlags :: PsaOutputOptions
, censorProjectWarnings :: Maybe Core.CensorBuildWarnings
, censorTestWarnings :: Maybe Core.CensorBuildWarnings
}
-> Effect (Array (LocalPath -> Maybe PathDecision))
toWorkspacePackagePathDecision { selected: { path, package }, psaCliFlags } = do
toWorkspacePackagePathDecision { selected: { path, package }, psaCliFlags, censorProjectWarnings, censorTestWarnings } = do
let srcPath = path </> "src"
let testPath = path </> "test"
pure
[ toPathDecision
{ pathIsFromPackage: (srcPath `Path.isPrefixOf` _)
, pathType: IsSrc
, strict: fromMaybe false $ psaCliFlags.strict <|> (package.build >>= _.strict)
, censorWarnings: package.build >>= _.censorProjectWarnings
, censorWarnings: (package.build >>= _.censorProjectWarnings) <|> censorProjectWarnings
}
, toPathDecision
{ pathIsFromPackage: (testPath `Path.isPrefixOf` _)
, pathType: IsSrc
, strict: fromMaybe false $ psaCliFlags.strict <|> (package.test >>= _.strict)
, censorWarnings: package.test >>= _.censorTestWarnings
, censorWarnings: (package.test >>= _.censorTestWarnings) <|> censorTestWarnings
}
]

@@ -193,4 +198,4 @@ shouldPrintWarning = case _ of
-- We return `true` to print the warning.
-- If an element was found (i.e. `Just` is returned), then one of the tests succeeded,
-- so we should not print the warning and return false here.
\code msg -> isNothing $ NonEmptyArray.find (\f -> f code msg) tests
\code msg -> isNothing $ Array.find (\f -> f code msg) tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package:
name: package-a
dependencies:
- prelude
build:
strict: true
test:
main: Src.PACKAGE.A.Test
dependencies: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Src.PACKAGE.A where

import Prelude

packageName :: String -> String
packageName foo =
"package" <> "package-a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Src.PACKAGE.A.Test where

import Prelude

main :: forall a. a -> Unit
main _ = do
let unused = "foo"
unit

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package:
name: package-b
dependencies:
- package-a
- prelude
build:
strict: true
censor_project_warnings: [] # override workspace setting
test:
main: Src.PACKAGE.B.Test
dependencies: []
censor_test_warnings: [] # override workspace setting
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Src.PACKAGE.B where

import Prelude

packageName :: _
packageName foo =
"package" <> "package-b"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Src.PACKAGE.B.Test where

import Prelude

main :: forall a. a -> Unit
main _ = do
let unused = "foo"
unit

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package:
name: package-c
dependencies:
- package-a
- package-b
- prelude
build:
strict: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Src.PACKAGE.C where

import Prelude

packageName :: _
packageName foo =
"package" <> "package-c"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
workspace:
buildOpts:
censor_project_warnings: all
censor_test_warnings: all
package_set:
registry: 0.0.1
extra_packages: {}
11 changes: 11 additions & 0 deletions test/Spago/Build/Monorepo.purs
Original file line number Diff line number Diff line change
@@ -138,6 +138,17 @@ spec = Spec.describe "monorepo" do
shouldNotHaveWarning = assertWarning paths false
spago [ "build" ] >>= check { stdout: mempty, stderr: shouldNotHaveWarning, result: isRight }

Spec.it "build fails when 'strict: true' because warnings censored at the workspace level were overridden" \{ spago, fixture, testCwd } -> do
FS.copyTree { src: fixture "monorepo/strict-true-workspace-censored-warnings", dst: Path.toGlobal testCwd }
let
errs =
[ "[ERROR 1/2 WildcardInferredType] " <> escapePathInErrMsg [ "package-b", "src", "Main.purs:5:16" ]
, "[ERROR 2/2 UnusedName] " <> escapePathInErrMsg [ "package-b", "src", "Main.purs:6:13" ]
, "[WARNING 1/1 UnusedName] " <> escapePathInErrMsg [ "package-b", "test", "Main.purs:7:7" ]
]
hasUnusedWarningError = assertWarning errs true
spago [ "build" ] >>= check { stdout: mempty, stderr: hasUnusedWarningError, result: isLeft }

Spec.it "build fails when 'strict: true' and warnings were not censored" \{ spago, fixture, testCwd } -> do
FS.copyTree { src: fixture "monorepo/strict-true-uncensored-warnings", dst: Path.toGlobal testCwd }
let
Loading
Oops, something went wrong.