mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-10-27 08:30:30 +03:00
Rewrite functions of List.Extra into our own module
This is to remove a dependency from the project
This commit is contained in:
parent
ddaea22eab
commit
94a87319f7
3
elm.json
3
elm.json
@ -18,10 +18,9 @@
|
||||
"elm-version": "0.19.0 <= v < 0.20.0",
|
||||
"dependencies": {
|
||||
"elm/core": "1.0.2 <= v < 2.0.0",
|
||||
"elm-community/list-extra": "8.2.1 <= v < 9.0.0",
|
||||
"elm-explorations/test": "1.2.2 <= v < 2.0.0",
|
||||
"mgold/elm-nonempty-list": "4.0.1 <= v < 5.0.0",
|
||||
"stil4m/elm-syntax": "7.1.0 <= v < 8.0.0"
|
||||
},
|
||||
"test-dependencies": {}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ module Lint.Fix exposing
|
||||
import Array
|
||||
import Elm.Parser
|
||||
import Elm.Syntax.Range exposing (Range)
|
||||
import List.Extra
|
||||
import ListExtra
|
||||
|
||||
|
||||
|
||||
@ -119,7 +119,7 @@ containRangeCollisions : List Fix -> Bool
|
||||
containRangeCollisions fixes =
|
||||
fixes
|
||||
|> List.map getFixRange
|
||||
|> List.Extra.uniquePairs
|
||||
|> ListExtra.uniquePairs
|
||||
|> List.any (\( a, b ) -> collide a b)
|
||||
|
||||
|
||||
|
@ -583,7 +583,6 @@ module name is `Lint.Rule.NoSomethingElse`).
|
||||
import Elm.Syntax.Module as Module exposing (Module)
|
||||
import Elm.Syntax.Node as Node exposing (Node)
|
||||
import Lint.Rule as Rule exposing (Direction, Error, Rule)
|
||||
import List.Extra
|
||||
|
||||
type alias Context =
|
||||
-- Contains the module name's last part
|
||||
@ -605,7 +604,8 @@ module name is `Lint.Rule.NoSomethingElse`).
|
||||
node
|
||||
|> Node.value
|
||||
|> Module.moduleName
|
||||
|> List.Extra.last
|
||||
|> List.reverse
|
||||
|> List.head
|
||||
in
|
||||
( [], moduleLastName )
|
||||
|
||||
|
@ -21,7 +21,7 @@ module Lint.Test.ErrorMessage exposing
|
||||
|
||||
import Elm.Syntax.Range exposing (Range)
|
||||
import Lint.Rule as Rule exposing (Error)
|
||||
import List.Extra
|
||||
import ListExtra
|
||||
|
||||
|
||||
{-| An expectation for an error. Use [`error`](#error) to create one.
|
||||
@ -395,7 +395,7 @@ positionAsRange sourceCode under position =
|
||||
startColumn : Int
|
||||
startColumn =
|
||||
linesBeforeAndIncludingPosition
|
||||
|> List.Extra.last
|
||||
|> ListExtra.last
|
||||
|> Maybe.withDefault ""
|
||||
|> String.length
|
||||
|> (+) 1
|
||||
@ -415,7 +415,7 @@ positionAsRange sourceCode under position =
|
||||
|
||||
else
|
||||
linesInUnder
|
||||
|> List.Extra.last
|
||||
|> ListExtra.last
|
||||
|> Maybe.withDefault ""
|
||||
|> String.length
|
||||
|> (+) 1
|
||||
|
61
src/ListExtra.elm
Normal file
61
src/ListExtra.elm
Normal file
@ -0,0 +1,61 @@
|
||||
module ListExtra exposing (last, uniquePairs)
|
||||
|
||||
{-| Functions taken from elm-community/list-extra.
|
||||
|
||||
These were used so that we wouldn't have dependency conflicts when
|
||||
elm-community/list-extra would release a new major version.
|
||||
|
||||
|
||||
# List functions
|
||||
|
||||
@docs last, uniquePairs
|
||||
|
||||
|
||||
# Original Copyright notice
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 CircuitHub Inc., Elm Community members
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
-}
|
||||
|
||||
|
||||
last : List a -> Maybe a
|
||||
last items =
|
||||
case items of
|
||||
[] ->
|
||||
Nothing
|
||||
|
||||
[ x ] ->
|
||||
Just x
|
||||
|
||||
_ :: rest ->
|
||||
last rest
|
||||
|
||||
|
||||
uniquePairs : List a -> List ( a, a )
|
||||
uniquePairs xs =
|
||||
case xs of
|
||||
[] ->
|
||||
[]
|
||||
|
||||
x :: xs_ ->
|
||||
List.map (\y -> ( x, y )) xs_ ++ uniquePairs xs_
|
Loading…
Reference in New Issue
Block a user