-
Notifications
You must be signed in to change notification settings - Fork 105
Fix #604 Where applicable, use elif in Cabal files
#605
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
mpilgrem
wants to merge
1
commit into
main
Choose a base branch
from
fix-elif
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,9 @@ module Hpack.Config ( | |
| , VerbatimValue(..) | ||
| , verbatimValueToString | ||
| , CustomSetup(..) | ||
| , HasEmpty(..) | ||
| , Section(..) | ||
| , maybeSectionAConditional | ||
| , Library(..) | ||
| , Executable(..) | ||
| , Conditional(..) | ||
|
|
@@ -527,6 +529,9 @@ instance Monoid Empty where | |
| mempty = Empty | ||
| mappend = (<>) | ||
|
|
||
| instance HasEmpty Empty where | ||
| empty = Empty | ||
|
|
||
| instance Semigroup Empty where | ||
| Empty <> Empty = Empty | ||
|
|
||
|
|
@@ -868,7 +873,7 @@ ensureRequiredCabalVersion inferredLicense pkg@Package{..} = pkg { | |
| executableHasGeneratedModules :: Section Executable -> Bool | ||
| executableHasGeneratedModules = any (not . null . executableGeneratedModules) | ||
|
|
||
| sectionCabalVersion :: (Section a -> [Module]) -> Section a -> Maybe CabalVersion | ||
| sectionCabalVersion :: (Eq a, HasEmpty a) => (Section a -> [Module]) -> Section a -> Maybe CabalVersion | ||
| sectionCabalVersion getMentionedModules sect = maximum $ [ | ||
| makeVersion [2,2] <$ guard (sectionSatisfies (not . null . sectionCxxSources) sect) | ||
| , makeVersion [2,2] <$ guard (sectionSatisfies (not . null . sectionCxxOptions) sect) | ||
|
|
@@ -880,6 +885,7 @@ ensureRequiredCabalVersion inferredLicense pkg@Package{..} = pkg { | |
| uses "RebindableSyntax" | ||
| && (uses "OverloadedStrings" || uses "OverloadedLists") | ||
| && pathsModule `elem` getMentionedModules sect) | ||
| , makeVersion [2,2] <$ guard (sectionSatisfies (isJust . maybeSectionAConditional) sect) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What this is saying is that if a nested conditional can be transformed into an What I think you would want to do is the other way around: If the rendered |
||
| ] ++ map versionFromSystemBuildTool systemBuildTools | ||
| where | ||
| defaultExtensions :: [String] | ||
|
|
@@ -1040,6 +1046,10 @@ data CustomSetup = CustomSetup { | |
| customSetupDependencies :: Dependencies | ||
| } deriving (Eq, Show) | ||
|
|
||
| -- | A class for types that have a value corresponding to being \'empty\'. | ||
| class HasEmpty a where | ||
| empty :: a | ||
|
|
||
| data Library = Library { | ||
| libraryExposed :: Maybe Bool | ||
| , libraryVisibility :: Maybe String | ||
|
|
@@ -1050,12 +1060,30 @@ data Library = Library { | |
| , librarySignatures :: [String] | ||
| } deriving (Eq, Show) | ||
|
|
||
| instance HasEmpty Library where | ||
| empty = Library | ||
| { libraryExposed = Nothing | ||
| , libraryVisibility = Nothing | ||
| , libraryExposedModules = [] | ||
| , libraryOtherModules = [] | ||
| , libraryGeneratedModules = [] | ||
| , libraryReexportedModules = [] | ||
| , librarySignatures = [] | ||
| } | ||
|
|
||
| data Executable = Executable { | ||
| executableMain :: Maybe FilePath | ||
| , executableOtherModules :: [Module] | ||
| , executableGeneratedModules :: [Module] | ||
| } deriving (Eq, Show) | ||
|
|
||
| instance HasEmpty Executable where | ||
| empty = Executable | ||
| { executableMain = Nothing | ||
| , executableOtherModules = [] | ||
| , executableGeneratedModules = [] | ||
| } | ||
|
|
||
| data BuildTool = BuildTool String String | LocalBuildTool String | ||
| deriving (Show, Eq, Ord) | ||
|
|
||
|
|
@@ -1093,6 +1121,41 @@ data Section a = Section { | |
| , sectionVerbatim :: [Verbatim] | ||
| } deriving (Eq, Show, Functor, Foldable, Traversable) | ||
|
|
||
| instance HasEmpty a => HasEmpty (Section a) where | ||
| empty = Section | ||
| { sectionData = Hpack.Config.empty | ||
| , sectionSourceDirs = [] | ||
| , sectionDependencies = mempty | ||
| , sectionPkgConfigDependencies = [] | ||
| , sectionDefaultExtensions = [] | ||
| , sectionOtherExtensions = [] | ||
| , sectionLanguage = Nothing | ||
| , sectionGhcOptions = [] | ||
| , sectionGhcProfOptions = [] | ||
| , sectionGhcSharedOptions = [] | ||
| , sectionGhcjsOptions = [] | ||
| , sectionCppOptions = [] | ||
| , sectionAsmOptions = [] | ||
| , sectionAsmSources = [] | ||
| , sectionCcOptions = [] | ||
| , sectionCSources = [] | ||
| , sectionCxxOptions = [] | ||
| , sectionCxxSources = [] | ||
| , sectionJsSources = [] | ||
| , sectionExtraLibDirs = [] | ||
| , sectionExtraLibraries = [] | ||
| , sectionExtraFrameworksDirs = [] | ||
| , sectionFrameworks = [] | ||
| , sectionIncludeDirs = [] | ||
| , sectionInstallIncludes = [] | ||
| , sectionLdOptions = [] | ||
| , sectionBuildable = Nothing | ||
| , sectionConditionals = [] | ||
| , sectionBuildTools = mempty | ||
| , sectionSystemBuildTools = mempty | ||
| , sectionVerbatim = [] | ||
| } | ||
|
|
||
| data Conditional a = Conditional { | ||
| conditionalCondition :: Cond | ||
| , conditionalThen :: a | ||
|
|
@@ -1657,3 +1720,12 @@ pathsModuleFromPackageName name = Module ("Paths_" ++ map f name) | |
| where | ||
| f '-' = '_' | ||
| f x = x | ||
|
|
||
| -- | If the given section contains only a single conditional, yields just that | ||
| -- conditional, otherwise 'Nothing'. | ||
| maybeSectionAConditional :: (Eq a, HasEmpty a) => Section a -> Maybe (Conditional (Section a)) | ||
| maybeSectionAConditional s@(Section { sectionConditionals = [c] }) = | ||
| if s == Hpack.Config.empty { sectionConditionals = sectionConditionals s } | ||
| then Just c | ||
| else Nothing | ||
| maybeSectionAConditional _ = Nothing | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is relevant user documentation. Nested if-statements and elif are semantically equivalent. As I understand it, this is a purely cosmetic change.
I say, either remove this completely, or add a separate section that describes how
.cabalfiles are formatted. This section could then also include what I mentioned here: #606 (comment)