Skip to content

Commit

Permalink
just use lists
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten committed Sep 17, 2024
1 parent bbd90a9 commit 11e55d4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/App/Fossa/Lernie/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,6 @@ createLicenseUnitSingles ((path, title), licenseUnitData) =
, licenseUnitDir = ""
, licenseUnitFiles = NE.singleton (unCustomLicensePath path)
, licenseUnitData = NE.singleton licenseUnitData
, licenseUnitNoticeFiles = Nothing
, licenseUnitNoticeFiles = []
, licenseUnitInfo = LicenseUnitInfo{licenseUnitInfoDescription = Just $ "custom license search " <> unCustomLicenseTitle title}
}
18 changes: 9 additions & 9 deletions src/App/Fossa/ManualDeps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ toSourceUnit root depsFile manualDeps@ManualDependencies{..} maybeApiOpts vendor
, sourceUnitType = "user-specific-yaml"
, sourceUnitBuild = build
, sourceUnitGraphBreadth = Complete
, sourceUnitNoticeFiles = Nothing
, sourceUnitNoticeFiles = []
, sourceUnitOriginPaths = [someBaseToOriginPath originPath]
, additionalData = additional
}
Expand Down Expand Up @@ -427,24 +427,24 @@ instance FromJSON ReferencedDependency where
<$> (obj `neText` "name")
<*> pure depType
<*> (unTextLike <$$> obj .:? "version")
<* forbidNonRefDepFields obj
<* forbidLinuxFields depType obj
<* forbidEpoch depType obj
<* forbidNonRefDepFields obj
<* forbidLinuxFields depType obj
<* forbidEpoch depType obj
)

parseApkOrDebDependency :: Object -> DepType -> Parser ReferencedDependency
parseApkOrDebDependency obj depType =
LinuxApkDebDep
<$> parseLinuxDependency obj depType
<* forbidNonRefDepFields obj
<* forbidEpoch depType obj
<* forbidNonRefDepFields obj
<* forbidEpoch depType obj

parseRpmDependency :: Object -> DepType -> Parser ReferencedDependency
parseRpmDependency obj depType =
LinuxRpmDep
<$> parseLinuxDependency obj depType
<*> (unTextLike <$$> obj .:? "epoch")
<* forbidNonRefDepFields obj
<* forbidNonRefDepFields obj

parseLinuxDependency :: Object -> DepType -> Parser LinuxReferenceDependency
parseLinuxDependency obj depType =
Expand Down Expand Up @@ -511,7 +511,7 @@ instance FromJSON CustomDependency where
<*> (obj `neText` "license")
<*> obj
.:? "metadata"
<* forbidMembers "custom dependencies" ["type", "path", "url"] obj
<* forbidMembers "custom dependencies" ["type", "path", "url"] obj

instance FromJSON RemoteDependency where
parseJSON = withObject "RemoteDependency" $ \obj -> do
Expand All @@ -521,7 +521,7 @@ instance FromJSON RemoteDependency where
<*> (obj `neText` "url")
<*> obj
.:? "metadata"
<* forbidMembers "remote dependencies" ["license", "path", "type"] obj
<* forbidMembers "remote dependencies" ["license", "path", "type"] obj

validateRemoteDep :: (Has Diagnostics sig m) => RemoteDependency -> Organization -> m RemoteDependency
validateRemoteDep r org =
Expand Down
2 changes: 1 addition & 1 deletion src/Srclib/Converter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ toSourceUnit leaveUnfiltered path dependencies projectType graphBreadth originPa
, buildDependencies = deps
}
, sourceUnitGraphBreadth = graphBreadth
, sourceUnitNoticeFiles = Nothing
, sourceUnitNoticeFiles = []
, sourceUnitOriginPaths = originPaths
, additionalData = Nothing
}
Expand Down
16 changes: 8 additions & 8 deletions src/Srclib/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ textToOriginPath = OriginPath . toString
data SourceUnitNoticeFile = SourceUnitNoticeFile
{ sourceUnitNoticeFilePath :: Text
, sourceUnitNoticeFileContents :: Text
, sourceUnitNoticeFileCopyrights :: Maybe (NonEmpty Text)
, sourceUnitNoticeFileCopyrights :: [Text]
}
deriving (Eq, Ord, Show)

Expand All @@ -133,7 +133,7 @@ instance FromJSON SourceUnitNoticeFile where
SourceUnitNoticeFile
<$> obj .: "path"
<*> obj .: "contents"
<*> obj .:? "copyrights"
<*> obj .:? "copyrights" .!= []

data FullSourceUnit = FullSourceUnit
{ fullSourceUnitName :: Text
Expand All @@ -142,7 +142,7 @@ data FullSourceUnit = FullSourceUnit
, fullSourceUnitManifest :: Maybe Text
, fullSourceUnitBuild :: Maybe SourceUnitBuild
, fullSourceUnitGraphBreadth :: GraphBreadth
, fullSourceUnitNoticeFiles :: Maybe (NonEmpty SourceUnitNoticeFile)
, fullSourceUnitNoticeFiles :: [SourceUnitNoticeFile]
, fullSourceUnitOriginPaths :: [OriginPath]
, fullSourceUnitAdditionalData :: Maybe AdditionalDepData
, fullSourceUnitFiles :: Maybe (NonEmpty Text)
Expand Down Expand Up @@ -231,7 +231,7 @@ data LicenseUnit = LicenseUnit
, licenseUnitDir :: Text
, licenseUnitFiles :: (NonEmpty Text)
, licenseUnitData :: (NonEmpty LicenseUnitData)
, licenseUnitNoticeFiles :: Maybe (NonEmpty SourceUnitNoticeFile)
, licenseUnitNoticeFiles :: [SourceUnitNoticeFile]
, licenseUnitInfo :: LicenseUnitInfo
}
deriving (Eq, Ord, Show)
Expand All @@ -245,7 +245,7 @@ emptyLicenseUnit =
, licenseUnitDir = ""
, licenseUnitFiles = "" :| []
, licenseUnitData = emptyLicenseUnitData :| []
, licenseUnitNoticeFiles = Nothing
, licenseUnitNoticeFiles = []
, licenseUnitInfo = LicenseUnitInfo{licenseUnitInfoDescription = Nothing}
}

Expand Down Expand Up @@ -277,7 +277,7 @@ instance FromJSON LicenseUnit where
<*> obj .: "Dir"
<*> obj .: "Files"
<*> obj .: "Data"
<*> obj .:? "NoticeFiles"
<*> obj .:? "NoticeFiles" .!= []
<*> obj .: "Info"

newtype LicenseUnitInfo = LicenseUnitInfo
Expand Down Expand Up @@ -381,7 +381,7 @@ data SourceUnit = SourceUnit
-- ^ path to manifest file
, sourceUnitBuild :: Maybe SourceUnitBuild
, sourceUnitGraphBreadth :: GraphBreadth
, sourceUnitNoticeFiles :: Maybe (NonEmpty SourceUnitNoticeFile)
, sourceUnitNoticeFiles :: [SourceUnitNoticeFile]
, sourceUnitOriginPaths :: [OriginPath]
, additionalData :: Maybe AdditionalDepData
}
Expand Down Expand Up @@ -476,7 +476,7 @@ instance FromJSON SourceUnit where
<*> obj .: "Manifest"
<*> obj .:? "Build"
<*> obj .: "GraphBreadth"
<*> obj .:? "NoticeFiles"
<*> obj .:? "NoticeFiles" .!= []
<*> obj .: "OriginPaths"
<*> obj .:? "AdditionalDependencyData"

Expand Down
4 changes: 2 additions & 2 deletions test/App/Fossa/Analyze/UploadSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ expectedMergedFullSourceUnits = NE.fromList [fullSourceUnit, fullLicenseUnit]
, fullSourceUnitFiles = Nothing
, fullSourceUnitData = Nothing
, fullSourceUnitInfo = Nothing
, fullSourceUnitNoticeFiles = Nothing
, fullSourceUnitNoticeFiles = []
}
fullLicenseUnit =
FullSourceUnit
Expand All @@ -103,7 +103,7 @@ expectedMergedFullSourceUnits = NE.fromList [fullSourceUnit, fullLicenseUnit]
, fullSourceUnitFiles = Just $ "" NE.:| []
, fullSourceUnitData = Just $ emptyLicenseUnitData NE.:| []
, fullSourceUnitInfo = Just LicenseUnitInfo{licenseUnitInfoDescription = Nothing}
, fullSourceUnitNoticeFiles = Nothing
, fullSourceUnitNoticeFiles = []
}

expectGetSuccessWithReachability :: Has MockApi sig m => m ()
Expand Down
2 changes: 1 addition & 1 deletion test/App/Fossa/Container/AnalyzeNativeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ jarsInContainerSpec = describe "Jars in Containers" $ do
}
, sourceUnitGraphBreadth = Complete
, sourceUnitOriginPaths = [textToOriginPath "package-lock.json"]
, sourceUnitNoticeFiles = Nothing
, sourceUnitNoticeFiles = []
, additionalData = Nothing
}

Expand Down
10 changes: 5 additions & 5 deletions test/App/Fossa/FirstPartyScanSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control.Algebra (Has)
import Control.Effect.FossaApiClient (FossaApiClientF (..))
import Data.List qualified as List
import Data.List.NonEmpty qualified as NE
import Data.Maybe (fromMaybe, isJust)
import Data.Maybe (isJust)
import Data.Text (strip)
import Fossa.API.Types (Organization (..))
import Path (Dir, Path, Rel, mkRelDir, (</>))
Expand Down Expand Up @@ -114,12 +114,12 @@ spec = do
let noticeUnit = NE.head units
licenseUnitName noticeUnit `shouldBe'` ""
licenseUnitType noticeUnit `shouldBe'` "NoticeFileMatches"
let noticeFiles = fromMaybe (NE.fromList []) (licenseUnitNoticeFiles noticeUnit)
let noticeFiles = licenseUnitNoticeFiles noticeUnit
length noticeFiles `shouldBe'` 1
let noticeFile = NE.head noticeFiles
let copyrights = fromMaybe (NE.fromList []) (sourceUnitNoticeFileCopyrights noticeFile)
let noticeFile = head noticeFiles

Check warning on line 119 in test/App/Fossa/FirstPartyScanSpec.hs

View workflow job for this annotation

GitHub Actions / Windows-build

In the use of ‘head’

Check warning on line 119 in test/App/Fossa/FirstPartyScanSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-intel-build

In the use of ‘head’

Check warning on line 119 in test/App/Fossa/FirstPartyScanSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-arm64-build

In the use of ‘head’
let copyrights = sourceUnitNoticeFileCopyrights noticeFile
length copyrights `shouldBe'` 1
let copyright = NE.head copyrights
let copyright = head copyrights

Check warning on line 122 in test/App/Fossa/FirstPartyScanSpec.hs

View workflow job for this annotation

GitHub Actions / Windows-build

In the use of ‘head’

Check warning on line 122 in test/App/Fossa/FirstPartyScanSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-intel-build

In the use of ‘head’

Check warning on line 122 in test/App/Fossa/FirstPartyScanSpec.hs

View workflow job for this annotation

GitHub Actions / macOS-arm64-build

In the use of ‘head’
copyright `shouldBe'` "2024 Frank Frankson"
strip (sourceUnitNoticeFileContents noticeFile) `shouldBe'` "This is a notice file that is copyright 2024 Frank Frankson"
sourceUnitNoticeFilePath noticeFile `shouldBe'` "NOTICE.txt"
Expand Down
2 changes: 1 addition & 1 deletion test/App/Fossa/LernieSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ expectedLicenseUnit =
, licenseUnitFiles = NE.singleton $ toText . toFilePath $ absDir </> $(mkRelDir "two.txt")
, licenseUnitData = NE.singleton expectedUnitData
, licenseUnitInfo = LicenseUnitInfo{licenseUnitInfoDescription = Just "custom license search Proprietary License"}
, licenseUnitNoticeFiles = Nothing
, licenseUnitNoticeFiles = []
}

expectedDoubleSourceUnit :: LicenseSourceUnit
Expand Down
6 changes: 3 additions & 3 deletions test/App/Fossa/LicenseScannerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ unitOne =
, licenseUnitFiles =
NE.fromList ["foo/bar/LICENSE", "foo/bar/one.txt"]
, licenseUnitInfo = info
, licenseUnitNoticeFiles = Nothing
, licenseUnitNoticeFiles = []
}

unitTwo :: LicenseUnit
Expand All @@ -56,7 +56,7 @@ unitTwo =
, licenseUnitData = NE.fromList [emptyLicenseUnitData{licenseUnitDataPath = "foo/bar/baz/ANOTHER_LICENSE"}, emptyLicenseUnitData{licenseUnitDataPath = "foo/bar/baz/two.txt"}]
, licenseUnitFiles = NE.fromList ["foo/bar/baz/ANOTHER_LICENSE", "foo/bar/baz/two.txt"]
, licenseUnitInfo = info
, licenseUnitNoticeFiles = Nothing
, licenseUnitNoticeFiles = []
}
expectedCombinedUnit :: LicenseUnit
expectedCombinedUnit =
Expand All @@ -80,7 +80,7 @@ expectedCombinedUnit =
, "foo/bar/one.txt"
]
, licenseUnitInfo = info
, licenseUnitNoticeFiles = Nothing
, licenseUnitNoticeFiles = []
}

fixtureDir :: Path Rel Dir
Expand Down
4 changes: 2 additions & 2 deletions test/Test/Fixtures.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ sourceUnits = [unit]
, sourceUnitBuild = Nothing
, sourceUnitGraphBreadth = Complete
, sourceUnitOriginPaths = []
, sourceUnitNoticeFiles = Nothing
, sourceUnitNoticeFiles = []
, additionalData = Nothing
}

Expand Down Expand Up @@ -311,7 +311,7 @@ vsiSourceUnit =
}
, sourceUnitGraphBreadth = Complete
, sourceUnitOriginPaths = ["/tmp/one/two"]
, sourceUnitNoticeFiles = Nothing
, sourceUnitNoticeFiles = []
, additionalData = Nothing
}

Expand Down

0 comments on commit 11e55d4

Please sign in to comment.