-
Notifications
You must be signed in to change notification settings - Fork 4
/
NoInconsistentAliases.elm
96 lines (63 loc) · 2.01 KB
/
NoInconsistentAliases.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module NoInconsistentAliases exposing
( rule, config, noMissingAliases
, Config
)
{-|
@docs rule, config, noMissingAliases
@docs Config
-}
import NoInconsistentAliases.Config as Config
import NoInconsistentAliases.Visitor as Visitor
import Review.Rule exposing (Rule)
{-| Ensure consistent use of import aliases throughout your project.
config : List Rule
config =
[ NoInconsistentAliases.config
[ ( "Html.Attributes", "Attr" )
]
|> NoInconsistentAliases.rule
]
-}
rule : Config -> Rule
rule =
Visitor.rule
{-| Provide a list of preferred names to be enforced. If we find any of the given modules imported with a different alias we will report them.
NoInconsistentAliases.config
[ ( "Html.Attributes", "Attr" )
, ( "Json.Decode", "Decode" )
, ( "Json.Encode", "Encode" )
]
|> NoInconsistentAliases.rule
-}
config : List ( String, String ) -> Config
config =
Config.config
{-| Ensure that imports are aliased if a module is used to qualify a function or type, and has a known alias.
NoInconsistentAliases.config
[ ( "Html.Attributes", "Attr" )
]
|> NoInconsistentAliases.noMissingAliases
|> NoInconsistentAliases.rule
## Failure
Here `Html.Attributes` has been used to call `class` and the preferred alias has not been used.
import Html.Attributes
view children =
div [ Html.Attributes.class "container" ] children
## Success
Here `Html.Attributes` has been aliased to `Attr` as expected.
import Html.Attributes as Attr
view children =
div [ Attr.class "container" ] children
## Success
Here `class` has been exposed so the alias is not needed.
import Html.Attributes exposing (class)
view children =
div [ class "container" ] children
-}
noMissingAliases : Config -> Config
noMissingAliases =
Config.noMissingAliases
{-| Configuration for the NoInconsistentAliases rule.
-}
type alias Config =
Config.Config