Enforces that certain module prefixes, e.g. Data, can only import modules from outside your codebase
Any module in our codebase can import from Data.* modules in your codebase
module Page exposing (Page)
import Data.Animal
import Data.Thing.GadgetBut ideally, code written in src/Data/**/*.elm and src/Data.elm cannot import from other modules
in the codebase, including other Data.* modules (except if they are "parent-child" modules, e.g.
Data.Animal and Data.Animal.Dog)
to check against your src/Data using this rule
npx elm-review --template choonkeat/only-import-outside/example/reviewif you're happy with that (or you don't have a src/Data to try against), then proceed below to install and setup
First, setup elm-review if you haven't
npx elm-review initInstall this package inside ./review sub directory
cd review
elm install choonkeat/only-import-outsideadd a OnlyImportOutside.rule to your config
module ReviewConfig exposing (config)
import OnlyImportOutside
import Review.Rule exposing (Rule)
config : List Rule
config =
[ OnlyImportOutside.rule
{ constrainedModulePrefixes = [ "Data" ]
, allowedModulePrefixes = [ "Extra" ] -- for illustration only; you can leave it `[]`
}
]module Data.Animal.Dog exposing (Dog)
import Data.AnimalAcceptable since it's importing parent module (in terms of directory hierarchy)
module Data.Thing exposing (Thing)
import Data.Thing.GadgetAcceptable since it's importing child module (in terms of directory hierarchy)
module Data.Thing exposing (Thing)
import Extra.TimeAcceptable since Extra.Time is allowed through allowedModulePrefixes = [ "Extra" ]
module Data.Wrong exposing (Wrong)
import Data.Animal
import Data.Thing
import Pagewill get rejected with these errors:
-- ELM-REVIEW ERROR ------------------------------------ src/Data/Wrong.elm:12:1
OnlyImportFromOutside: Cannot `import Data.Animal` from `module Data.Wrong`
12| import Data.Animal
^^^^^^^^^^^^^^^^^^
13| import Data.Thing
──────────────────────────────────────────────────────── src/Data/Wrong.elm:13:1
OnlyImportFromOutside: Cannot `import Data.Thing` from `module Data.Wrong`
12| import Data.Animal
13| import Data.Thing
^^^^^^^^^^^^^^^^^
14| import Page
──────────────────────────────────────────────────────── src/Data/Wrong.elm:14:1
OnlyImportFromOutside: Cannot `import Page` from `module Data.Wrong`
13| import Data.Thing
14| import Page
^^^^^^^^^^^
I found 3 errors in 1 file.