From 94a87319f771ca891df70c15ae02e2e309daa585 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 22 Aug 2019 12:17:32 +0200 Subject: [PATCH] Rewrite functions of List.Extra into our own module This is to remove a dependency from the project --- elm.json | 3 +- src/Lint/Fix.elm | 4 +-- src/Lint/Rule.elm | 4 +-- src/Lint/Test/ErrorMessage.elm | 6 ++-- src/ListExtra.elm | 61 ++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 src/ListExtra.elm diff --git a/elm.json b/elm.json index c78fa3cb..427358c3 100644 --- a/elm.json +++ b/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": {} -} +} \ No newline at end of file diff --git a/src/Lint/Fix.elm b/src/Lint/Fix.elm index 024e5533..d0eb4a34 100644 --- a/src/Lint/Fix.elm +++ b/src/Lint/Fix.elm @@ -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) diff --git a/src/Lint/Rule.elm b/src/Lint/Rule.elm index f88bfd6e..ed93e0f1 100644 --- a/src/Lint/Rule.elm +++ b/src/Lint/Rule.elm @@ -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 ) diff --git a/src/Lint/Test/ErrorMessage.elm b/src/Lint/Test/ErrorMessage.elm index 088841cc..30905059 100644 --- a/src/Lint/Test/ErrorMessage.elm +++ b/src/Lint/Test/ErrorMessage.elm @@ -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 diff --git a/src/ListExtra.elm b/src/ListExtra.elm new file mode 100644 index 00000000..4901e5f7 --- /dev/null +++ b/src/ListExtra.elm @@ -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_