Fix Credo code readability issues

This commit is contained in:
rustra 2020-01-28 20:15:59 +01:00
parent 97651e88e9
commit 3505736705
38 changed files with 63 additions and 58 deletions

View File

@ -10,7 +10,7 @@ defmodule Mobilizon.Federation.ActivityPub do
import Mobilizon.Federation.ActivityPub.Utils import Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.{Actors, Config, Events, Reports, Users, Share} alias Mobilizon.{Actors, Config, Events, Reports, Share, Users}
alias Mobilizon.Actors.{Actor, Follower} alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Events.{Comment, Event, Participant} alias Mobilizon.Events.{Comment, Event, Participant}
alias Mobilizon.Reports.Report alias Mobilizon.Reports.Report

View File

@ -21,7 +21,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
require Logger require Logger
def init() do def init do
# Wait for everything to settle. # Wait for everything to settle.
Process.sleep(1000 * 5) Process.sleep(1000 * 5)
get_actor() get_actor()

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
internal one, and back. internal one, and back.
""" """
alias Mobilizon.Addresses
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event, as: EventModel alias Mobilizon.Events.Event, as: EventModel
alias Mobilizon.Media.Picture alias Mobilizon.Media.Picture

View File

@ -9,11 +9,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Admin.ActionLog alias Mobilizon.Admin.ActionLog
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Events.{Event, Comment} alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Reports.{Note, Report} alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias Mobilizon.Service.Statistics alias Mobilizon.Service.Statistics
alias Mobilizon.Storage.Page alias Mobilizon.Storage.Page
alias Mobilizon.Users.User
alias Mobilizon.Federation.ActivityPub.Relay alias Mobilizon.Federation.ActivityPub.Relay

View File

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
alias Mobilizon.{Actors, Admin, Events} alias Mobilizon.{Actors, Admin, Events}
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Event, Participant, EventParticipantStats} alias Mobilizon.Events.{Event, EventParticipantStats, Participant}
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mobilizon.GraphQL.API alias Mobilizon.GraphQL.API

View File

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
import Mobilizon.Users.Guards import Mobilizon.Users.Guards
alias Mobilizon.{Actors, Config, Users, Events} alias Mobilizon.{Actors, Config, Events, Users}
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User alias Mobilizon.Users.User

View File

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
use Absinthe.Schema.Notation use Absinthe.Schema.Notation
alias Mobilizon.Events.{Event, Comment} alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Reports.{Note, Report} alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.GraphQL.Resolvers.Admin alias Mobilizon.GraphQL.Resolvers.Admin

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.GraphQL.Schema.ReportType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1] import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Reports
alias Mobilizon.GraphQL.Resolvers.Report alias Mobilizon.GraphQL.Resolvers.Report
alias Mobilizon.Reports
@desc "A report object" @desc "A report object"
object :report do object :report do

View File

@ -2,10 +2,12 @@ defmodule Mix.Tasks.Mobilizon.Users.Show do
@moduledoc """ @moduledoc """
Task to display an user details Task to display an user details
""" """
use Mix.Task use Mix.Task
alias Mobilizon.Actors.Actor
alias Mobilizon.Users alias Mobilizon.Users
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mobilizon.Actors.Actor
@shortdoc "Show a Mobilizon user details" @shortdoc "Show a Mobilizon user details"

View File

@ -92,7 +92,7 @@ defmodule Mobilizon do
defp fallback_options(nil), do: [] defp fallback_options(nil), do: []
defp fallback_options(fallback), do: [fallback: fallback(default: fallback)] defp fallback_options(fallback), do: [fallback: fallback(default: fallback)]
defp internal_actor() do defp internal_actor do
%{ %{
id: :internal_actor_init, id: :internal_actor_init,
start: {Task, :start_link, [&ActivityPub.Relay.init/0]}, start: {Task, :start_link, [&ActivityPub.Relay.init/0]},

View File

@ -7,13 +7,12 @@ defmodule Mobilizon.Actors.Actor do
import Ecto.Changeset import Ecto.Changeset
alias Mobilizon.{Actors, Config, Crypto, Share} alias Mobilizon.{Actors, Config, Crypto, Mention, Share}
alias Mobilizon.Actors.{ActorOpenness, ActorType, ActorVisibility, Follower, Member} alias Mobilizon.Actors.{ActorOpenness, ActorType, ActorVisibility, Follower, Member}
alias Mobilizon.Events.{Event, FeedToken, Comment} alias Mobilizon.Events.{Comment, Event, FeedToken}
alias Mobilizon.Media.File alias Mobilizon.Media.File
alias Mobilizon.Reports.{Note, Report} alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mobilizon.Mention
alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes alias Mobilizon.Web.Router.Helpers, as: Routes

View File

@ -6,31 +6,27 @@ defmodule Mobilizon.Events.Event do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
alias Ecto.Changeset alias Ecto.Changeset
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.{Addresses, Events, Media, Mention}
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Addresses
alias Mobilizon.Events
alias Mobilizon.Events.{ alias Mobilizon.Events.{
Comment, Comment,
EventOptions, EventOptions,
EventParticipantStats,
EventStatus, EventStatus,
EventVisibility, EventVisibility,
JoinOptions, JoinOptions,
EventParticipantStats,
Participant, Participant,
Session, Session,
Tag, Tag,
Track Track
} }
alias Mobilizon.Media
alias Mobilizon.Media.Picture alias Mobilizon.Media.Picture
alias Mobilizon.Mention
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Endpoint

View File

@ -10,7 +10,7 @@ defmodule Mobilizon.Events do
import Mobilizon.Storage.Ecto import Mobilizon.Storage.Ecto
alias Ecto.{Multi, Changeset} alias Ecto.{Changeset, Multi}
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
@ -1078,7 +1078,7 @@ defmodule Mobilizon.Events do
|> Repo.all() |> Repo.all()
end end
def data() do def data do
Dataloader.Ecto.new(Repo, query: &query/2) Dataloader.Ecto.new(Repo, query: &query/2)
end end

View File

@ -6,8 +6,7 @@ defmodule Mobilizon.Mention do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Event alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Events.Comment
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
@type t :: %__MODULE__{ @type t :: %__MODULE__{

View File

@ -4,10 +4,12 @@ defmodule Mobilizon.Share do
""" """
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
alias Mobilizon.Storage.Repo
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Storage.Repo
@type t :: %__MODULE__{ @type t :: %__MODULE__{
uri: String.t(), uri: String.t(),

View File

@ -5,8 +5,8 @@ defmodule Mobilizon.Service.Export.ICalendar do
alias Mobilizon.{Actors, Events, Users} alias Mobilizon.{Actors, Events, Users}
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Events.{Event, FeedToken}
alias Mobilizon.Users.User alias Mobilizon.Users.User
@doc """ @doc """

View File

@ -4,8 +4,8 @@ defmodule Mobilizon.Service.Geospatial.Addok do
""" """
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger require Logger

View File

@ -10,8 +10,8 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
""" """
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger require Logger

View File

@ -8,8 +8,8 @@ defmodule Mobilizon.Service.Geospatial.Mimirsbrunn do
""" """
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger require Logger

View File

@ -4,8 +4,8 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
""" """
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger require Logger

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.Pelias do
""" """
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger require Logger

View File

@ -4,8 +4,8 @@ defmodule Mobilizon.Service.Geospatial.Photon do
""" """
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Provider
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Provider
require Logger require Logger

View File

@ -5,10 +5,11 @@ defmodule Mobilizon.Service.Metadata.Instance do
alias Phoenix.HTML alias Phoenix.HTML
alias Phoenix.HTML.Tag alias Phoenix.HTML.Tag
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Endpoint
def build_tags() do def build_tags do
description = process_description(Config.instance_description()) description = process_description(Config.instance_description())
title = "#{Config.instance_name()} - Mobilizon" title = "#{Config.instance_name()} - Mobilizon"

View File

@ -3,10 +3,11 @@ defmodule Mobilizon.Service.Workers.BuildSearch do
Worker to build search results Worker to build search results
""" """
alias Ecto.Adapters.SQL
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Events.Event alias Mobilizon.Events.Event
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
alias Ecto.Adapters.SQL
use Mobilizon.Service.Workers.Helper, queue: "search" use Mobilizon.Service.Workers.Helper, queue: "search"

View File

@ -3,8 +3,7 @@ defmodule Mobilizon.Web.Email.Checker do
Provides a function to test emails against a "not so bad" regex. Provides a function to test emails against a "not so bad" regex.
""" """
# TODO: simplify me! @email_regex ~r/^[\w.!#$%&*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i
@email_regex ~r/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
@doc """ @doc """
Returns whether the email is valid. Returns whether the email is valid.

View File

@ -15,7 +15,7 @@ defmodule Mobilizon.Web.Email.Event do
alias Mobilizon.Storage.Repo alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mobilizon.Web.{Gettext, Email} alias Mobilizon.Web.{Email, Gettext}
@important_changes [:title, :begins_on, :ends_on, :status] @important_changes [:title, :begins_on, :ends_on, :status]

View File

@ -9,9 +9,9 @@ defmodule Mobilizon.Web.Email.Participation do
import Mobilizon.Web.Gettext import Mobilizon.Web.Gettext
alias Mobilizon.Users.User
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Participant alias Mobilizon.Events.Participant
alias Mobilizon.Users.User
alias Mobilizon.Web.{Email, Gettext} alias Mobilizon.Web.{Email, Gettext}

View File

@ -49,7 +49,7 @@ defmodule Mobilizon.Web.ErrorView do
render("500.html", assigns) render("500.html", assigns)
end end
defp index_file_path() do defp index_file_path do
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html") Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
end end
end end

View File

@ -10,8 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
alias Mobilizon.Federation.ActivityPub.Relay alias Mobilizon.Federation.ActivityPub.Relay
alias Mobilizon.GraphQL.API alias Mobilizon.GraphQL.{AbsintheHelpers, API}
alias Mobilizon.GraphQL.AbsintheHelpers
describe "Resolver: List the action logs" do describe "Resolver: List the action logs" do
@note_content "This a note on a report" @note_content "This a note on a report"

View File

@ -5,9 +5,9 @@ defmodule Mobilizon.ActorsTest do
import Mobilizon.Factory import Mobilizon.Factory
alias Mobilizon.{Actors, Config, Users, Events, Tombstone} alias Mobilizon.{Actors, Config, Events, Tombstone, Users}
alias Mobilizon.Actors.{Actor, Bot, Follower, Member} alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
alias Mobilizon.Events.{Event, Comment} alias Mobilizon.Events.{Comment, Event}
alias Mobilizon.Media.File, as: FileModel alias Mobilizon.Media.File, as: FileModel
alias Mobilizon.Service.Workers alias Mobilizon.Service.Workers
alias Mobilizon.Storage.Page alias Mobilizon.Storage.Page

View File

@ -1,12 +1,14 @@
defmodule Mobilizon.Service.ICalendarTest do defmodule Mobilizon.Service.ICalendarTest do
alias Mobilizon.Service.Export.ICalendar, as: ICalendarService
alias Mobilizon.Events.Event
alias Mobilizon.Addresses.Address
alias ICalendar.Value
use Mobilizon.DataCase use Mobilizon.DataCase
import Mobilizon.Factory import Mobilizon.Factory
alias ICalendar.Value
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event
alias Mobilizon.Service.Export.ICalendar, as: ICalendarService
describe "export an event to ics" do describe "export an event to ics" do
test "export basic infos" do test "export basic infos" do
%Event{} = event = insert(:event) %Event{} = event = insert(:event)

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.AddokTest do
import Mock import Mock
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Addok
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Addok
@httpoison_headers [ @httpoison_headers [
{"User-Agent", {"User-Agent",

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.MapQuestTest do
import Mock import Mock
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.MapQuest
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.MapQuest
@httpoison_headers [ @httpoison_headers [
{"User-Agent", {"User-Agent",

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
import Mock import Mock
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Nominatim
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Nominatim
@httpoison_headers [ @httpoison_headers [
{"User-Agent", {"User-Agent",

View File

@ -6,8 +6,8 @@ defmodule Mobilizon.Service.Geospatial.PhotonTest do
import Mock import Mock
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Service.Geospatial.Photon
alias Mobilizon.Config alias Mobilizon.Config
alias Mobilizon.Service.Geospatial.Photon
@httpoison_headers [ @httpoison_headers [
{"User-Agent", {"User-Agent",

View File

@ -1,10 +1,12 @@
defmodule Mix.Tasks.Mobilizon.ActorsTest do defmodule Mix.Tasks.Mobilizon.ActorsTest do
use Mobilizon.DataCase use Mobilizon.DataCase
alias Mobilizon.Actors.Actor
alias Mix.Tasks.Mobilizon.Actors.Show
import Mobilizon.Factory import Mobilizon.Factory
alias Mix.Tasks.Mobilizon.Actors.Show
alias Mobilizon.Actors.Actor
Mix.shell(Mix.Shell.Process) Mix.shell(Mix.Shell.Process)
@username "someone" @username "someone"

View File

@ -3,9 +3,10 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
import Mobilizon.Factory import Mobilizon.Factory
alias Mix.Tasks.Mobilizon.Users.{Delete, Modify, New, Show}
alias Mobilizon.Users alias Mobilizon.Users
alias Mobilizon.Users.User alias Mobilizon.Users.User
alias Mix.Tasks.Mobilizon.Users.{New, Delete, Show, Modify}
Mix.shell(Mix.Shell.Process) Mix.shell(Mix.Shell.Process)

View File

@ -4,16 +4,18 @@ defmodule Mobilizon.Web.ErrorViewTest do
# Bring render/3 and render_to_string/3 for testing custom views # Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View import Phoenix.View
alias Mobilizon.Web.ErrorView
test "renders 404.html" do test "renders 404.html" do
assert render_to_string(Mobilizon.Web.ErrorView, "404.html", []) =~ assert render_to_string(ErrorView, "404.html", []) =~
"We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue." "We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue."
end end
test "render 500.html" do test "render 500.html" do
assert render_to_string(Mobilizon.Web.ErrorView, "500.html", []) == "Internal server error" assert render_to_string(ErrorView, "500.html", []) == "Internal server error"
end end
test "render any other" do test "render any other" do
assert render_to_string(Mobilizon.Web.ErrorView, "505.html", []) == "Internal server error" assert render_to_string(ErrorView, "505.html", []) == "Internal server error"
end end
end end