diff --git a/CHANGELOG.md b/CHANGELOG.md index db4719455..a5868ed2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Bug fixes: - For Elm 0.18 and earlier, tag listings of documented custom types are no longer converted to `(..)` - Listing a value more than once in module documentation no longer results in an invalid module line - Code blocks in doc comments containing commented Elm expressions are now correctly separated by a single blank line + - When converting `exposing (..)` to an explicit listing, undocumented values are not longer hidden ## 0.8.0 diff --git a/elm-format.cabal b/elm-format.cabal index bb30415da..b8068f411 100644 --- a/elm-format.cabal +++ b/elm-format.cabal @@ -1,5 +1,5 @@ Name: elm-format -version: 0.8.1-rc1 +version: 0.8.1-rc2 Synopsis: A source code formatter for Elm diff --git a/package/npm/package.json b/package/npm/package.json index 0a209faf0..efc38659d 100644 --- a/package/npm/package.json +++ b/package/npm/package.json @@ -1,6 +1,6 @@ { "name": "elm-format", - "version": "0.8.1-rc1", + "version": "0.8.1-rc2", "description": "Install elm-format", "preferGlobal": true, "main": "index.js", diff --git a/src/ElmFormat/Render/Box.hs b/src/ElmFormat/Render/Box.hs index a0ff3efec..e1d59fc45 100644 --- a/src/ElmFormat/Render/Box.hs +++ b/src/ElmFormat/Render/Box.hs @@ -167,8 +167,8 @@ removeDuplicates input = else (ReversedList.push next acc, Set.insert next seen) -sortVars :: Bool -> Set (AST.Commented AST.Variable.Value) -> [[AST.Variable.Ref]] -> Set AST.Variable.Value -> ([[AST.Commented AST.Variable.Value]], AST.Comments) -sortVars forceMultiline fromExposing fromDocs fromModule = +sortVars :: Bool -> Set (AST.Commented AST.Variable.Value) -> [[AST.Variable.Ref]] -> ([[AST.Commented AST.Variable.Value]], AST.Comments) +sortVars forceMultiline fromExposing fromDocs = let refName (AST.Variable.VarRef _ (LowercaseIdentifier name)) = name refName (AST.Variable.TagRef _ (UppercaseIdentifier name)) = name @@ -201,9 +201,7 @@ sortVars forceMultiline fromExposing fromDocs fromModule = |> Map.fromList allowedInDocs = - Map.union - (varSetToMap fromExposing) - (varSetToMap $ Set.map (\v -> AST.Commented [] v []) fromModule) + varSetToMap fromExposing allFromDocs = Set.fromList $ fmap varName $ concat listedInDocs @@ -221,20 +219,9 @@ sortVars forceMultiline fromExposing fromDocs fromModule = |> fmap (\(AST.Commented pre _ post) -> pre ++ post) |> concat in - case (List.null $ concat listedInDocs) && (List.null remainingFromExposing) of - False -> - if List.null listedInDocs && forceMultiline - then ( fmap (\x -> [x]) remainingFromExposing, commentsFromReorderedVars ) - else ( listedInDocs ++ if List.null remainingFromExposing then [] else [ remainingFromExposing ], commentsFromReorderedVars ) - - True -> - -- we have no exposing, and no docs; use from module - fromModule - |> Set.toList - |> fmap (\x -> AST.Commented [] x []) - |> List.sortOn varOrder - |> (\x -> if List.null x then [] else [x]) - |> (\x -> (x, [])) + if List.null listedInDocs && forceMultiline + then ( fmap (\x -> [x]) remainingFromExposing, commentsFromReorderedVars ) + else ( listedInDocs ++ if List.null remainingFromExposing then [] else [ remainingFromExposing ], commentsFromReorderedVars ) formatModuleHeader :: ElmVersion -> AST.Module.Module -> Box @@ -266,19 +253,20 @@ formatModuleHeader elmVersion modu = '(':a:b:')':[] -> AST.Variable.OpRef (SymbolIdentifier $ a:b:[]) s -> AST.Variable.VarRef [] (LowercaseIdentifier s) - definedVars :: Set AST.Variable.Value + definedVars :: Set (AST.Commented AST.Variable.Value) definedVars = AST.Module.body modu |> concatMap extractVarName + |> fmap (\x -> AST.Commented [] x []) |> Set.fromList AST.KeywordCommented _ _ exportsList = AST.Module.exports header - detailedListingToSet :: AST.Variable.Listing AST.Module.DetailedListing -> Set (AST.Commented AST.Variable.Value) - detailedListingToSet (AST.Variable.OpenListing _) = Set.empty - detailedListingToSet AST.Variable.ClosedListing = Set.empty - detailedListingToSet (AST.Variable.ExplicitListing (AST.Module.DetailedListing values operators types) _) = + detailedListingToSet :: Set (AST.Commented AST.Variable.Value) -> AST.Variable.Listing AST.Module.DetailedListing -> Set (AST.Commented AST.Variable.Value) + detailedListingToSet allAvailable (AST.Variable.OpenListing _) = allAvailable + detailedListingToSet _ AST.Variable.ClosedListing = Set.empty + detailedListingToSet _ (AST.Variable.ExplicitListing (AST.Module.DetailedListing values operators types) _) = Set.unions [ Map.assocs values |> fmap (\(name, AST.Commented pre () post) -> AST.Commented pre (AST.Variable.Value name) post) |> Set.fromList , Map.assocs operators |> fmap (\(name, AST.Commented pre () post) -> AST.Commented pre (AST.Variable.OpValue name) post) |> Set.fromList @@ -292,9 +280,8 @@ formatModuleHeader elmVersion modu = varsToExpose = sortVars (detailedListingIsMultiline exportsList) - (detailedListingToSet exportsList) + (detailedListingToSet definedVars exportsList) documentedVars - definedVars extractVarName :: TopLevelStructure Declaration -> [AST.Variable.Value] extractVarName decl = diff --git a/src/Flags.hs b/src/Flags.hs index a57f79ebe..3773522f2 100644 --- a/src/Flags.hs +++ b/src/Flags.hs @@ -3,7 +3,6 @@ module Flags where import Data.Monoid ((<>)) import ElmVersion (ElmVersion(..)) -import qualified Data.Maybe as Maybe import qualified ElmVersion import qualified Options.Applicative as Opt import qualified Text.PrettyPrint.ANSI.Leijen as PP diff --git a/tests/test-files/transform/Elm-0.19/ListExports.elm b/tests/test-files/transform/Elm-0.19/ListExports.elm index 8327d909f..c1ee9d720 100644 --- a/tests/test-files/transform/Elm-0.19/ListExports.elm +++ b/tests/test-files/transform/Elm-0.19/ListExports.elm @@ -14,6 +14,8 @@ module ListExports exposing (..) type alias X = () type Y = Y1 | Y2 +q = 4 a = 1 b = 2 c = 3 +p = 5 diff --git a/tests/test-files/transform/Elm-0.19/ListExports.formatted.elm b/tests/test-files/transform/Elm-0.19/ListExports.formatted.elm index 0118396b2..6972cf427 100644 --- a/tests/test-files/transform/Elm-0.19/ListExports.formatted.elm +++ b/tests/test-files/transform/Elm-0.19/ListExports.formatted.elm @@ -3,6 +3,7 @@ module ListExports exposing , X , Y(..) , b, c + , p, q ) {-| @@ -28,6 +29,10 @@ type Y | Y2 +q = + 4 + + a = 1 @@ -38,3 +43,7 @@ b = c = 3 + + +p = + 5