Skip to content

Commit 3f501d9

Browse files
committed
Elm is complaining about name convention
A module must be CamelCase, a module line must come **before** the comments (documentation), and removing some files that Elm creates.
1 parent 82221e7 commit 3f501d9

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

Diff for: elm-in-action/.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
__ANKI__
1+
__ANKI__
2+
3+
# elm-package generated files
4+
elm-stuff
5+
# elm-repl generated files
6+
repl-temp-*

Diff for: elm-in-action/02/notes/notes.elm

+65-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,33 @@
55

66
-- 2.1.1
77

8-
-- HTML is shorthand for "virtual DOM node"
8+
-- Filename conventions --
9+
-- Although I prefer lisp's (kebab-case ...), in Elm you
10+
-- MUST be `CamelCase`. Variables should also be `camelCase`.
11+
-- : @ https://en.wikipedia.org/wiki/Camel_case
12+
-- : @ https://elmprogramming.com/constant.html
13+
-- : @ http://tinyurl.com/programming-cases
14+
--
15+
-- : 🚫 `src/photo-groove.elm` wrong naming convention
16+
-- : I expect all files follow module naming convention:
17+
--
18+
-- | Module name | File Path |
19+
-- |--------------|--------------------|
20+
-- | Main | ./Main.elm |
21+
-- | HomePage | ./HomePage |
22+
-- | Http.Helpers | ./Http/Helpers.elm |
23+
24+
25+
-- Documentation and comments --
26+
--
27+
-- Module declaration _must come before_ `module` statement.
28+
-- Repeat! DO NOT put comments before `module` statement:
29+
--
30+
-- : @ https://package.elm-lang.org/help/documentation-format
31+
32+
33+
-- Working with the Document Object Model (DOM)
34+
-- HTML is shorthand for "virtual DOM node" ...
935
-- : We generally don't use `node` directly, but use the HTML elements
1036
-- such as `img`, `button`, so on.
1137
-- : The following two lines are equivalent:
@@ -17,6 +43,7 @@ node "img" [ src "logo.png" ] []
1743
-- fall back on `node` only when no alternative is available.
1844

1945
-- Commas --
46+
-- Commas first takes some getting used to, but ...
2047
-- : 🚫 Beware of mistakes!
2148
-- : It's best to have commas at the start of the line, as lines can be mistaken
2249
-- for syntactically valid Elm code — but NOT the code you intended to write.
@@ -35,3 +62,40 @@ rules = [
3562
]
3663

3764
-- Instead of 3 distinct lines.
65+
-- : instead of calling `rule` 3 times, with one argument,
66+
-- the second call to `rule` is receiving 3 arguments.
67+
68+
rules = [
69+
rule "Do not ..."
70+
rule "Do NOT" -- I'm missing a comma!
71+
, rule "No eating ..."
72+
]
73+
74+
-- The above commas first is easier to check mistakes.
75+
76+
77+
-- More on the DOM structure --
78+
-- The PhotoGroove module will render a basic DOM
79+
--
80+
-- : The functions that create elements — in this case, div, h1, and img
81+
-- take exactly _two arguments_ in all cases:
82+
--
83+
-- 1. A list of attributes (or an empty `[]` list)
84+
h1 [] [ text "Photo Groove" ]
85+
-- 2. A list of _child DOM nodes_ (or an empty `[]` list)
86+
img [ src "1.jpeg" ] []
87+
-- : If an element has neither attributes nor children?
88+
br [] []
89+
90+
91+
-- Qualified -vs- unqualified style
92+
--
93+
-- `String.filter` (qualified style)
94+
-- : Uses the module's name here and now.
95+
--
96+
-- `import HTML exposing (div, h1, img, text)` allows for:
97+
-- : Using `div` instead of `Html.div`
98+
-- (this is an unqualified style.)
99+
--
100+
-- We can use unqualified style when we _expose_ the module.
101+
-- It imports the module, and exposes `Html.function`

Diff for: elm-in-action/02/src/photo-groove.elm renamed to elm-in-action/02/src/PhotoGroove.elm

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module PhotoGroove exposing (main)
2+
13
{-| Beginning our Elm app:
24
Photo Groove!
35
@@ -15,10 +17,7 @@
1517
: Only exposed values can be accessed by other modules.
1618
As a general rule, it's best for our modules to expose
1719
_as little as possible_.
18-
|-}
19-
20-
-- #1
21-
module PhotoGroove exposing (main)
20+
-}
2221

2322
-- #2
2423
import Html exposing (div, h1, img, text)
@@ -34,3 +33,6 @@ view model =
3433
, img [ src "http://elm-in-action.com/3.jpeg" ] []
3534
]
3635
]
36+
37+
main =
38+
view "no model yet"

0 commit comments

Comments
 (0)