From c42d34b2ec2dacd9a038f721f7a817ee43cc0a4f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 05:37:33 +0100 Subject: [PATCH] [Credo] fix Credo.Check.Readability.MaxLineLength --- lib/pleroma/captcha/captcha.ex | 2 +- lib/pleroma/clippy.ex | 4 ++-- lib/pleroma/formatter.ex | 1 + lib/pleroma/plugs/oauth_plug.ex | 1 + lib/pleroma/reverse_proxy.ex | 10 ++++++---- lib/pleroma/uploaders/s3.ex | 3 ++- lib/pleroma/user.ex | 4 +++- lib/pleroma/web/activity_pub/activity_pub.ex | 6 ++++-- .../web/activity_pub/mrf/keyword_policy.ex | 15 ++++++++------- lib/pleroma/web/controller_helper.ex | 3 ++- lib/pleroma/web/endpoint.ex | 1 + lib/pleroma/web/media_proxy/media_proxy.ex | 3 ++- lib/pleroma/web/metadata/opengraph.ex | 2 +- lib/pleroma/web/metadata/twitter_card.ex | 3 ++- lib/pleroma/web/push/subscription.ex | 4 ++-- test/web/instances/instances_test.exs | 3 ++- test/web/twitter_api/twitter_api_test.exs | 1 + 17 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index cecb5b5a7..f105cbb25 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -73,7 +73,7 @@ def handle_call({:validate, token, captcha, answer_data}, _from, state) do secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") - # If the time found is less than (current_time - seconds_valid), then the time has already passed. + # If the time found is less than (current_time-seconds_valid) then the time has already passed # Later we check that the time found is more than the presumed invalidatation time, that means # that the data is still valid and the captcha can be checked seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]) diff --git a/lib/pleroma/clippy.ex b/lib/pleroma/clippy.ex index 1a1606a23..bd20952a6 100644 --- a/lib/pleroma/clippy.ex +++ b/lib/pleroma/clippy.ex @@ -92,8 +92,8 @@ def puts(text_or_lines) do # surrond one/five line clippy with blank lines around to not fuck up the layout # - # yes this fix sucks but it's good enough, have you ever seen a release of windows wihtout some butched - # features anyway? + # yes this fix sucks but it's good enough, have you ever seen a release of windows + # without some butched features anyway? lines = if length(lines) == 1 or length(lines) == 5 do [""] ++ lines ++ [""] diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 048c032ed..1e4ede3f2 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Formatter do @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ @link_regex ~r{((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+}ui + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength @auto_linker_config hashtag: true, hashtag_handler: &Pleroma.Formatter.hashtag_handler/4, diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 6130c4570..5888d596a 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -38,6 +38,7 @@ defp fetch_user_and_token(token) do preload: [user: user] ) + # credo:disable-for-next-line Credo.Check.Readability.MaxLineLength with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do {:ok, user, token_record} end diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index a25b5ea4e..6298b92f4 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -3,10 +3,12 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ReverseProxy do - @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range) + @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since) ++ + ~w(if-unmodified-since if-none-match if-range range) @resp_cache_headers ~w(etag date last-modified cache-control) @keep_resp_headers @resp_cache_headers ++ - ~w(content-type content-disposition content-encoding content-range accept-ranges vary) + ~w(content-type content-disposition content-encoding content-range) ++ + ~w(accept-ranges vary) @default_cache_control_header "public, max-age=1209600" @valid_resp_codes [200, 206, 304] @max_read_duration :timer.seconds(30) @@ -282,8 +284,8 @@ defp build_resp_cache_headers(headers, _opts) do headers has_cache? -> - # There's caching header present but no cache-control -- we need to explicitely override it to public - # as Plug defaults to "max-age=0, private, must-revalidate" + # There's caching header present but no cache-control -- we need to explicitely override it + # to public as Plug defaults to "max-age=0, private, must-revalidate" List.keystore(headers, "cache-control", 0, {"cache-control", "public"}) true -> diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index 0038ba01f..e7de3f3e0 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -6,7 +6,8 @@ defmodule Pleroma.Uploaders.S3 do @behaviour Pleroma.Uploaders.Uploader require Logger - # The file name is re-encoded with S3's constraints here to comply with previous links with less strict filenames + # The file name is re-encoded with S3's constraints here to comply with previous + # links with less strict filenames def get_file(file) do config = Pleroma.Config.get([__MODULE__]) bucket = Keyword.fetch!(config, :bucket) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index dbb568ca0..1ce9882f6 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -30,6 +30,7 @@ defmodule Pleroma.User do @primary_key {:id, Pleroma.FlakeId, autogenerate: true} + # credo:disable-for-next-line Credo.Check.Readability.MaxLineLength @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ @strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/ @@ -435,7 +436,8 @@ def get_by_ap_id(ap_id) do Repo.get_by(User, ap_id: ap_id) end - # This is mostly an SPC migration fix. This guesses the user nickname (by taking the last part of the ap_id and the domain) and tries to get that user + # This is mostly an SPC migration fix. This guesses the user nickname by taking the last part + # of the ap_id and the domain and tries to get that user def get_by_guessed_nickname(ap_id) do domain = URI.parse(ap_id).host name = List.last(String.split(ap_id, "/")) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 337dc0173..fb8fe1ca2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -170,7 +170,8 @@ def create(%{to: to, actor: actor, context: context, object: object} = params) d additional ), {:ok, activity} <- insert(create_data, local), - # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info + # Changing note count prior to enqueuing federation task in order to avoid + # race conditions on updating user.info {:ok, _actor} <- increase_note_count_if_public(actor, activity), :ok <- maybe_federate(activity) do {:ok, activity} @@ -320,7 +321,8 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru "deleted_activity_id" => activity && activity.id }, {:ok, activity} <- insert(data, local), - # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info + # Changing note count prior to enqueuing federation task in order to avoid + # race conditions on updating user.info {:ok, _actor} <- decrease_note_count_if_public(user, object), :ok <- maybe_federate(activity) do {:ok, activity} diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex index 5fdc03414..25d5f9cd3 100644 --- a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -45,13 +45,14 @@ defp check_ftl_removal( defp check_replace(%{"object" => %{"content" => content, "summary" => summary}} = message) do {content, summary} = - Enum.reduce(Pleroma.Config.get([:mrf_keyword, :replace]), {content, summary}, fn {pattern, - replacement}, - {content_acc, - summary_acc} -> - {String.replace(content_acc, pattern, replacement), - String.replace(summary_acc, pattern, replacement)} - end) + Enum.reduce( + Pleroma.Config.get([:mrf_keyword, :replace]), + {content, summary}, + fn {pattern, replacement}, {content_acc, summary_acc} -> + {String.replace(content_acc, pattern, replacement), + String.replace(summary_acc, pattern, replacement)} + end + ) {:ok, message diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 5915ea40e..4d6192db0 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -6,7 +6,8 @@ defmodule Pleroma.Web.ControllerHelper do use Pleroma.Web, :controller def oauth_scopes(params, default) do - # Note: `scopes` is used by Mastodon — supporting it but sticking to OAuth's standard `scope` wherever we control it + # Note: `scopes` is used by Mastodon — supporting it but sticking to + # OAuth's standard `scope` wherever we control it Pleroma.Web.OAuth.parse_scopes(params["scope"] || params["scopes"], default) end diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 3eed047ca..697b1bc3a 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -26,6 +26,7 @@ defmodule Pleroma.Web.Endpoint do from: :pleroma, only: ~w(index.html static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc) + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength ) # Code reloading can be explicitly enabled under the diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index 39a725a69..3bd2affe9 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -19,7 +19,8 @@ def url(url) do else secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base] - # Must preserve `%2F` for compatibility with S3 (https://git.pleroma.social/pleroma/pleroma/issues/580) + # Must preserve `%2F` for compatibility with S3 + # https://git.pleroma.social/pleroma/pleroma/issues/580 replacement = get_replacement(url, ":2F:") # The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice. diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index cafb8134b..357b80a2d 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -88,7 +88,7 @@ defp build_attachments(%{data: %{"attachment" => attachments}}) do # TODO: Add additional properties to objects when we have the data available. # Also, Whatsapp only wants JPEG or PNGs. It seems that if we add a second og:image - # object when a Video or GIF is attached it will display that in the Whatsapp Rich Preview. + # object when a Video or GIF is attached it will display that in Whatsapp Rich Preview. case media_type do "audio" -> [ diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index a0be383e5..040b872e7 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -97,7 +97,8 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do | acc ] - # TODO: Need the true width and height values here or Twitter renders an iFrame with a bad aspect ratio + # TODO: Need the true width and height values here or Twitter renders an iFrame with + # a bad aspect ratio "video" -> [ {:meta, [property: "twitter:card", content: "player"], []}, diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index c90bd2bda..da301fbbc 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -82,8 +82,8 @@ def delete_if_exists(user, token) do end # Some webpush clients (e.g. iOS Toot!) use an non urlsafe base64 as an encoding for the key. - # However, the web push rfs specify to use base64 urlsafe, and the `web_push_encryption` library we use - # requires the key to be properly encoded. So we just convert base64 to urlsafe base64. + # However, the web push rfs specify to use base64 urlsafe, and the `web_push_encryption` library + # we use requires the key to be properly encoded. So we just convert base64 to urlsafe base64. defp ensure_base64_urlsafe(string) do string |> String.replace("+", "-") diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs index 2530c09fe..f0d84edea 100644 --- a/test/web/instances/instances_test.exs +++ b/test/web/instances/instances_test.exs @@ -102,7 +102,8 @@ test "returns error status on non-binary input" do end end - # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 should be tested in implementation-specific tests + # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 + # should be tested in implementation-specific tests describe "set_unreachable/1" do test "returns error status on non-binary input" do assert {:error, _} = Instances.set_unreachable(nil) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 1eb8f77d2..c8dd3fd7a 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -472,6 +472,7 @@ test "fetches a user by uri" do # Also fetches the feed. # assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength end end end