on master help sign in
add error message about file naming conventions
commitefb63ca381bec191a031e8e8e630294102653fb7 authorEvan Czaplicki <evancz@users.noreply.github.com> dateSat 29 Jun 2019, 17:07 (7 years ago) parent417f615
1 file changed+48
builder/src/Reporting/Exit.hs+48
builder/src/Reporting/Exit.hs+48
@@ -41,6 +41,8 @@ import qualified Data.NonEmptyList as NE
4141import qualified Network.HTTP.Client as HTTP
4242import qualified Network.HTTP.Types.Header as HTTP
4343import qualified Network.HTTP.Types.Status as HTTP
44+import qualified System.FilePath as FP
45+import System.FilePath ((</>), (<.>))
4446
4547import qualified Elm.Constraint as C
4648import qualified Elm.Magnitude as M
@@ -1713,6 +1715,7 @@ data BuildProjectProblem
17131715 | BP_WithAmbiguousSrcDir FilePath FilePath FilePath
17141716 | BP_MainPathDuplicate FilePath FilePath
17151717 | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
1718+ | BP_MainNameInvalid FilePath FilePath [String]
17161719 | BP_CannotLoadDependencies
17171720 | BP_Cycle ModuleName.Raw [ModuleName.Raw]
17181721 | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
@@ -1790,6 +1793,24 @@ toProjectProblemReport projectProblem =
17901793 "Try changing to a different module name in one of them!"
17911794 ]
17921795
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+
17931814 BP_CannotLoadDependencies ->
17941815 corruptCacheReport
17951816
@@ -1845,6 +1866,33 @@ toProjectProblemReport projectProblem =
18451866 ]
18461867
18471868
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+
18481896
18491897-- GENERATE
18501898