Fix new credo warnings

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-26 14:30:46 +01:00
parent 52e624bb88
commit 51afec1856
20 changed files with 77 additions and 72 deletions

View File

@@ -57,8 +57,7 @@ defmodule Mobilizon.Service.Address do
name: if(defined?(postal_code), do: "#{description} (#{postal_code})", else: description),
alternative_name:
[locality, country]
|> Enum.filter(& &1)
|> Enum.filter(&(&1 != description))
|> Enum.filter(&(&1 && &1 != description))
|> Enum.join(", ")
}
end

View File

@@ -46,10 +46,9 @@ defmodule Mobilizon.Service.CleanOrphanMedia do
[from: "posts_medias", param: "media_id"],
[from: "comments_medias", param: "media_id"]
]
|> Enum.map(fn [from: from, param: param] ->
|> Enum.map_join(" UNION ", fn [from: from, param: param] ->
"SELECT 1 FROM #{from} WHERE #{from}.#{param} = m0.id"
end)
|> Enum.join(" UNION ")
|> (&"NOT EXISTS(#{&1})").()
@spec find_media(Keyword.t()) :: list(list(Media.t()))

View File

@@ -41,7 +41,7 @@ defmodule Mobilizon.Service.Export.Participants.CSV do
|> Repo.stream()
|> Stream.map(&to_list/1)
|> NimbleCSV.RFC4180.dump_to_iodata()
|> (fn stream -> Stream.concat([Enum.join(columns(), ","), "\n"], stream) end).()
|> add_header_column()
|> Stream.each(fn line -> IO.write(file, line) end)
|> Stream.run()
@@ -63,6 +63,10 @@ defmodule Mobilizon.Service.Export.Participants.CSV do
end
end
defp add_header_column(stream) do
Stream.concat([Enum.join(columns(), ","), "\n"], stream)
end
@spec save_csv_upload(String.t(), String.t(), Event.t()) ::
{:ok, Export.t()} | {:error, atom() | Ecto.Changeset.t()}
defp save_csv_upload(full_path, filename, %Event{id: event_id, title: title}) do

View File

@@ -39,7 +39,7 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
|> Events.participant_for_event_export_query(Keyword.get(options, :roles, []))
|> Repo.all()
|> Enum.map(&to_list/1)
|> (fn data -> Enum.concat([columns()], data) end).()
|> add_header_columns()
|> generate_ods()
File.write!(full_path, content)
@@ -62,6 +62,10 @@ defmodule Mobilizon.Service.Export.Participants.ODS do
end
end
defp add_header_columns(data) do
Enum.concat([columns()], data)
end
defp generate_ods(data) do
data
|> Jason.encode!()

View File

@@ -15,6 +15,8 @@ defmodule Mobilizon.Service.Formatter do
alias Mobilizon.Web.Endpoint
# https://github.com/rrrene/credo/issues/912
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/

View File

@@ -56,8 +56,6 @@ defmodule Mobilizon.Service.Workers.BuildSearch do
end
defp get_tags_string(%Event{tags: tags}) do
tags
|> Enum.map(& &1.title)
|> Enum.join(" ")
Enum.map_join(tags, " ", & &1.title)
end
end

View File

@@ -77,12 +77,16 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
) do
event_uuid
|> Events.get_event_by_uuid_with_preload()
|> (fn %Event{organizer_actor: %Actor{id: actor_id}} -> [actor_id] end).()
|> organizer_actor_id()
|> users_from_actor_ids(Keyword.fetch!(options, :author_id))
end
defp users_to_notify(_, _), do: []
defp organizer_actor_id(%Event{organizer_actor: %Actor{id: actor_id}}) do
[actor_id]
end
@spec users_from_actor_ids(list(), integer() | String.t()) :: list(Users.t())
defp users_from_actor_ids(actor_ids, author_id) do
actor_ids