on master help sign in
add error message about file naming conventions
efb63caEvan Czaplicki
builder/src/Reporting/Exit.hs+48
@@ -41,6 +41,8 @@ import qualified Data.NonEmptyList as NE
41import qualified Network.HTTP.Client as HTTP
41import qualified Network.HTTP.Client as HTTP
42import qualified Network.HTTP.Types.Header as HTTP
42import qualified Network.HTTP.Types.Header as HTTP
43import qualified Network.HTTP.Types.Status as HTTP
43import qualified Network.HTTP.Types.Status as HTTP
44+import qualified System.FilePath as FP
45+import System.FilePath ((</>), (<.>))
44
46
45import qualified Elm.Constraint as C
47import qualified Elm.Constraint as C
46import qualified Elm.Magnitude as M
48import qualified Elm.Magnitude as M
@@ -1713,6 +1715,7 @@ data BuildProjectProblem
1713 | BP_WithAmbiguousSrcDir FilePath FilePath FilePath
1715 | BP_WithAmbiguousSrcDir FilePath FilePath FilePath
1714 | BP_MainPathDuplicate FilePath FilePath
1716 | BP_MainPathDuplicate FilePath FilePath
1715 | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
1717 | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
1718+ | BP_MainNameInvalid FilePath FilePath [String]
1716 | BP_CannotLoadDependencies
1719 | BP_CannotLoadDependencies
1717 | BP_Cycle ModuleName.Raw [ModuleName.Raw]
1720 | BP_Cycle ModuleName.Raw [ModuleName.Raw]
1718 | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
1721 | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
@@ -1790,6 +1793,24 @@ toProjectProblemReport projectProblem =
1790 "Try changing to a different module name in one of them!"
1793 "Try changing to a different module name in one of them!"
1791 ]
1794 ]
1792
1795
1796+ BP_MainNameInvalid givenPath srcDir pathSegments ->
1797+ Help.report "UNEXPECTED FILE NAME" Nothing
1798+ "I am having trouble with this file name:"
1799+ [ D.indent 4 $ D.red $ D.fromChars givenPath
1800+ , D.reflow $
1801+ "I found it in your " ++ FP.addTrailingPathSeparator srcDir ++ " directory\
1802+ \ which is good, but I expect all of the files in there to use the following\
1803+ \ module naming convention:"
1804+ , toModuleNameConventionTable srcDir [ "Main", "HomePage", "Http.Helpers" ]
1805+ , D.reflow $
1806+ "Notice that the names always start with capital letters! Can you make your file\
1807+ \ use this naming convention?"
1808+ , D.toSimpleNote $
1809+ "Having a strict naming convention like this makes it a lot easier to find\
1810+ \ things in large projects. If you see a module imported, you know where to look\
1811+ \ for the corresponding file every time!"
1812+ ]
1813+
1793 BP_CannotLoadDependencies ->
1814 BP_CannotLoadDependencies ->
1794 corruptCacheReport
1815 corruptCacheReport
1795
1816
@@ -1845,6 +1866,33 @@ toProjectProblemReport projectProblem =
1845 ]
1866 ]
1846
1867
1847
1868
1869+toModuleNameConventionTable :: FilePath -> [String] -> D.Doc
1870+toModuleNameConventionTable srcDir names =
1871+ let
1872+ toPair name =
1873+ ( name
1874+ , srcDir </> map (\c -> if c == '.' then FP.pathSeparator else c) name <.> "elm"
1875+ )
1876+
1877+ namePairs = map toPair names
1878+ nameWidth = maximum (11 : map (length . fst) namePairs)
1879+ pathWidth = maximum ( 9 : map (length . snd) namePairs)
1880+
1881+ padded width str =
1882+ str ++ replicate (width - length str) ' '
1883+
1884+ toRow (name, path) =
1885+ D.fromChars $
1886+ "| " ++ padded nameWidth name ++ " | " ++ padded pathWidth path ++ " |"
1887+
1888+ bar =
1889+ D.fromChars $
1890+ "+-" ++ replicate nameWidth '-' ++ "-+-" ++ replicate pathWidth '-' ++ "-+"
1891+ in
1892+ D.indent 4 $ D.vcat $
1893+ [ bar, toRow ("Module Name", "File Path"), bar ] ++ map toRow namePairs ++ [ bar ]
1894+
1895+
1848
1896
1849-- GENERATE
1897-- GENERATE
1850
1898