From 1d52bfeb81d866bb1e42b81c983af6f68d4c3164 Mon Sep 17 00:00:00 2001 From: Justin Tormey Date: Mon, 27 Jul 2020 12:46:26 -0500 Subject: [PATCH] Fix formatting --- lib/linkify/parser.ex | 6 +++--- test/linkify_test.exs | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 9669844..759007e 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -189,7 +189,7 @@ defmodule Linkify.Parser do buffer |> String.split(url) |> Enum.intersperse(link_url(url, opts)) - |> (if opts[:iodata], do: & &1, else: & Enum.join(&1)).() + |> if(opts[:iodata], do: & &1, else: &Enum.join(&1)).() end else :nomatch @@ -336,13 +336,13 @@ defmodule Linkify.Parser do defp link(buffer, opts, user_acc) do opts_list = Map.to_list(opts) - Enum.reduce_while @types, {buffer, user_acc}, fn type, _ -> + Enum.reduce_while(@types, {buffer, user_acc}, fn type, _ -> if {type, true} in opts_list do check_and_link_reducer(type, buffer, opts, user_acc) else {:cont, {buffer, user_acc}} end - end + end) end defp check_and_link_reducer(type, buffer, opts, user_acc) do diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 3216b38..c92e9fa 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -14,7 +14,13 @@ defmodule LinkifyTest do test "default link safe iodata" do assert Linkify.link_safe("google.com") == - [[{:safe, [""]}, "google.com", {:safe, ""}]] + [ + [ + {:safe, [""]}, + "google.com", + {:safe, ""} + ] + ] end test "does on link existing links" do @@ -37,8 +43,17 @@ defmodule LinkifyTest do test "all kinds of links iodata" do text = "hello google.com https://ddg.com user@email.com irc:///mIRC" - expected = - ["hello", " ", ["", "google.com", ""], " ", ["", "https://ddg.com", ""], " ", ["", "user@email.com", ""], " ", ["", "irc:///mIRC", ""]] + expected = [ + "hello", + " ", + ["", "google.com", ""], + " ", + ["", "https://ddg.com", ""], + " ", + ["", "user@email.com", ""], + " ", + ["", "irc:///mIRC", ""] + ] assert Linkify.link_to_iodata(text, email: true, @@ -53,7 +68,15 @@ defmodule LinkifyTest do test "class attribute iodata" do assert Linkify.link_to_iodata("google.com", class: "linkified") == - [["", "google.com", ""]] + [ + [ + "", + "google.com", + "" + ] + ] end test "rel attribute" do @@ -63,7 +86,15 @@ defmodule LinkifyTest do test "rel attribute iodata" do assert Linkify.link_to_iodata("google.com", rel: "noopener noreferrer") == - [["", "google.com", ""]] + [ + [ + "", + "google.com", + "" + ] + ] end test "rel as function" do