Skip to content
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

cabal-install: check: Whitelist doc file extensions #8747

Merged
merged 3 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions Cabal/src/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,19 +2545,21 @@ checkGlobFiles verbosity pkg root = do
)

-- Predicate for desirable documentation file on Hackage server
isDesirableExtraDocFile :: [FilePath] -> FilePath -> Bool
isDesirableExtraDocFile paths path = map toLower basename `elem` paths
isDesirableExtraDocFile :: ([FilePath], [FilePath]) -> FilePath -> Bool
isDesirableExtraDocFile (basenames, extensions) path =
basename `elem` basenames && ext `elem` extensions
where
(basename, _ext) = splitExtension path
(basename, ext) = splitExtension (map toLower path)

-- Changelog patterns
-- Changelog patterns (basenames & extensions)
-- Source: hackage-server/src/Distribution/Server/Packages/ChangeLog.hs
desirableChangeLog =
[ "news"
, "changelog"
, "change_log"
, "changes"
]
desirableChangeLogExtensions = ["", ".txt", ".md", ".markdown", ".rst"]
-- [TODO] Check readme. Observations:
-- • Readme is not necessary if package description is good.
-- • Some readmes exists only for repository browsing.
Expand All @@ -2567,7 +2569,7 @@ checkGlobFiles verbosity pkg root = do
-- -- Readme patterns
-- -- Source: hackage-server/src/Distribution/Server/Packages/Readme.hs
-- desirableReadme = ["readme"]
desirableDocFiles = desirableChangeLog
desirableDocFiles = (desirableChangeLog, desirableChangeLogExtensions)

-- If there's a missing directory in play, since our globs don't
-- (currently) support disjunction, that will always mean there are no
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Test.Cabal.Prelude

import System.Directory (createDirectoryIfMissing)

-- Omitting ChangeLog.md but not README in extra-doc-files
main = cabalTest $ do
cabal "check" []
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Needed for test, to ensure we test the file extension as well.
!ChangeLog.md~
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Test.Cabal.Prelude

import System.Directory (createDirectoryIfMissing)

-- Omitting ChangeLog.md but not README in extra-doc-files
main = cabalTest $ do
cabal "check" []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# cabal check
Warning: These warnings may cause trouble when distributing the package:
Warning: Please consider including the file './ChangeLog.md' in the 'extra-doc-files' section of the .cabal file if it contains useful information for users of the package.
Warning: Please consider including the file './CHANGELOG.TXT' in the 'extra-doc-files' section of the .cabal file if it contains useful information for users of the package.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Test.Cabal.Prelude

import System.Directory (createDirectoryIfMissing)

-- Omitting ChangeLog.md but not README in extra-doc-files
main = cabalTest $ do
cabal "check" []
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Test.Cabal.Prelude

import System.Directory (createDirectoryIfMissing)

-- Included ChangeLog.md but not in extra-doc-files
main = cabalTest $ do
cabal "check" []
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Test.Cabal.Prelude

import System.Directory (createDirectoryIfMissing)

-- Included ChangeLog.md but not in extra-doc-files
main = cabalTest $ do
cabal "check" []