Skip to content

Commit

Permalink
cabal-install: check: Whitelist doc file extensions (haskell#8747)
Browse files Browse the repository at this point in the history
* check: Test only doc files with supported extensions

* Cleanup

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
wismill and mergify[bot] authored Feb 12, 2023
1 parent e9b4744 commit bae536f
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 16 deletions.
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" []

0 comments on commit bae536f

Please sign in to comment.