Skip to content

Commit 16c9eda

Browse files
committed
chore: Fix linter issues & deprecations
1 parent c7efee0 commit 16c9eda

File tree

18 files changed

+62
-67
lines changed

18 files changed

+62
-67
lines changed

apps/cf/lib/accounts/username_generator.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ defmodule CF.Accounts.UsernameGenerator do
66
@name __MODULE__
77
@username_prefix "NewUser-"
88

9-
def start_link do
9+
def child_spec(opts) do
10+
%{
11+
id: __MODULE__,
12+
start: {__MODULE__, :start_link, [opts]},
13+
type: :worker,
14+
restart: :permanent,
15+
shutdown: 500
16+
}
17+
end
18+
19+
def start_link(_opts \\ []) do
1020
Agent.start_link(
1121
fn ->
1222
Hashids.new(

apps/cf/lib/application.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ defmodule CF.Application do
99
# Define workers and child supervisors to be supervised
1010
children = [
1111
# Other custom supervisors
12-
supervisor(CF.Sources.Fetcher, []),
12+
{CF.Sources.Fetcher, []},
1313
# Misc workers
14-
worker(CF.Accounts.UsernameGenerator, []),
14+
{CF.Accounts.UsernameGenerator, []},
1515
# Sweep tokens from db
16-
worker(Guardian.DB.Token.SweeperServer, [])
16+
{Guardian.DB.Token.SweeperServer, []}
1717
]
1818

1919
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html

apps/cf/lib/errors/errors.ex

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,9 @@ defmodule CF.Errors do
3636
end
3737

3838
@spec do_report(:error | :exit | :throw, any(), [any()], cf_error_params()) :: :ok
39-
def do_report(type, value, stacktrace, params) do
39+
def do_report(type, value, stacktrace, _params) do
4040
# Any call to Sentry, Rollbar, etc. should be done here
4141
Logger.error("[ERROR][#{type}] #{inspect(value)} - #{inspect(stacktrace)}")
4242
:ok
4343
end
44-
45-
defp build_occurence_data(params) do
46-
default_occurrence_data()
47-
|> add_user(params[:user])
48-
|> Map.merge(params[:data] || %{})
49-
end
50-
51-
defp default_occurrence_data() do
52-
%{
53-
"code_version" => CF.Application.version()
54-
}
55-
end
56-
57-
defp add_user(base, nil),
58-
do: base
59-
60-
defp add_user(base, %{id: id, username: username}),
61-
do: Map.merge(base, %{"person" => %{"id" => Integer.to_string(id), "username" => username}})
62-
63-
defp add_user(base, %{id: id}),
64-
do: Map.merge(base, %{"person" => %{"id" => Integer.to_string(id)}})
6544
end

apps/cf/lib/llms/statements_creator.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ defmodule CF.LLMs.StatementsCreator do
5656
end
5757
end
5858

59-
@doc """
60-
Chunk captions everytime we reach the max caption length
61-
"""
59+
# Chunk captions each time we reach the max caption length
6260
defp chunk_captions(captions) do
6361
# TODO: Add last captions from previous batch to preserve context
6462
Enum.chunk_every(captions, @captions_chunk_size)

apps/cf/lib/llms/templates/statements_extractor_user_prompt.eex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"title": "<%= video.id %>"
55
},
66
"captions": <%= captions |> Enum.map(fn caption -> %{
7-
"start": floor(caption["start"]),
8-
"text": String.trim(caption["text"])
7+
start: floor(caption["start"]),
8+
text: String.trim(caption["text"])
99
} end) |> Jason.encode! %>
1010
}
1111
```

apps/cf/lib/sources/fetcher.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ defmodule CF.Sources.Fetcher do
1010

1111
# ---- Public API ----
1212

13-
def start_link() do
13+
def child_spec(opts) do
14+
%{
15+
id: __MODULE__,
16+
start: {__MODULE__, :start_link, [opts]},
17+
type: :worker,
18+
restart: :permanent,
19+
shutdown: 500
20+
}
21+
end
22+
23+
def start_link(_opts \\ []) do
1424
import Supervisor.Spec
1525

1626
Supervisor.start_link(

apps/cf_atom_feed/lib/application.ex

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ defmodule CF.AtomFeed.Application do
44
# See https://hexdocs.pm/elixir/Application.html
55
# for more information on OTP Applications
66
def start(_type, _args) do
7-
import Supervisor.Spec
8-
9-
children = []
107
config = Application.get_env(:cf_atom_feed, CF.AtomFeed.Router)
11-
12-
if config[:cowboy] do
13-
children = [supervisor(CF.AtomFeed.Router, []) | children]
14-
end
8+
children = if config[:cowboy], do: [{CF.AtomFeed.Router, []}], else: []
159

1610
# See https://hexdocs.pm/elixir/Supervisor.html
1711
# for other strategies and supported options

apps/cf_atom_feed/lib/router.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ defmodule CF.AtomFeed.Router do
66
plug(:match)
77
plug(:dispatch)
88

9-
def start_link do
9+
def child_spec(opts) do
10+
%{
11+
id: __MODULE__,
12+
start: {__MODULE__, :start_link, [opts]},
13+
type: :worker,
14+
restart: :permanent,
15+
shutdown: 500
16+
}
17+
end
18+
19+
def start_link(_opts \\ []) do
1020
config = Application.get_env(:cf_atom_feed, CF.AtomFeed.Router)
1121
Logger.info("Running CF.AtomFeed.Router with cowboy on port #{config[:cowboy][:port]}")
1222
Plug.Cowboy.http(CF.AtomFeed.Router, [], config[:cowboy])

apps/cf_graphql/lib/application.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule CF.Graphql.Application do
1111
# Start the PubSub system
1212
{Phoenix.PubSub, name: CF.Graphql.PubSub},
1313
# Start the endpoint when the application starts
14-
supervisor(CF.GraphQLWeb.Endpoint, [])
14+
{CF.GraphQLWeb.Endpoint, []}
1515
]
1616

1717
# See https://hexdocs.pm/elixir/Supervisor.html

apps/cf_rest_api/lib/application.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ defmodule CF.RestApi.Application do
99
# Start the PubSub system
1010
{Phoenix.PubSub, name: CF.RestApi.PubSub},
1111
# Start the endpoint when the application starts
12-
supervisor(CF.RestApi.Endpoint, []),
12+
{CF.RestApi.Endpoint, []},
1313
# Presence to track number of connected users to a channel
14-
supervisor(CF.RestApi.Presence, [])
14+
{CF.RestApi.Presence, []}
1515
]
1616

1717
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html

apps/cf_reverse_proxy/lib/plug.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ defmodule CF.ReverseProxy.Plug do
1111
)
1212

1313
@default_host CF.RestApi.Endpoint
14-
@base_host_regex ~r/^(?<service>rest|graphql|feed)\./
15-
@subdomains %{
16-
"graphql" => CF.GraphQLWeb.Endpoint,
17-
"rest" => CF.RestApi.Endpoint,
18-
"feed" => CF.AtomFeed.Router
19-
}
2014

2115
def init(opts), do: opts
2216

@@ -26,6 +20,13 @@ defmodule CF.ReverseProxy.Plug do
2620
# https://github.com/jesseshieh/master_proxy
2721

2822
if Application.get_env(:cf, :env) == :dev do
23+
@base_host_regex ~r/^(?<service>rest|graphql|feed)\./
24+
@subdomains %{
25+
"graphql" => CF.GraphQLWeb.Endpoint,
26+
"rest" => CF.RestApi.Endpoint,
27+
"feed" => CF.AtomFeed.Router
28+
}
29+
2930
# Dev requests are routed through here
3031
def call(conn, _) do
3132
if conn.request_path == "/status" do

apps/db/lib/db/application.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ defmodule DB.Application do
99

1010
# Define workers and child supervisors to be supervised
1111
children = [
12-
# Starts a worker by calling: DB.Worker.start_link(arg1, arg2, arg3)
13-
# worker(DB.Worker, [arg1, arg2, arg3]),
14-
supervisor(DB.Repo, [])
12+
{DB.Repo, []}
1513
]
1614

1715
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html

apps/db/lib/db_schema/source.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule DB.Schema.Source do
6565
end
6666

6767
defp validate_file_mime_type(:file_mime_type, mime_type) do
68-
if MIME.valid?(mime_type) do
68+
if MIME.extensions(mime_type) != [] do
6969
[]
7070
else
7171
[file_mime_type: "Invalid MIME type"]

apps/db/lib/db_schema/video.ex

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,4 @@ defmodule DB.Schema.Video do
297297
)
298298
end)
299299
end
300-
301-
# Return IDs of videos with at least 3 statements
302-
defp popular_videos_subquery do
303-
Video
304-
|> join(:inner, [v], s in assoc(v, :statements))
305-
|> select([:id])
306-
|> group_by([v], v.id)
307-
|> having([v, s], count(s.id) >= 3)
308-
end
309300
end

apps/db/lib/db_type/flag_reason.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ defmodule DB.Type.FlagReason do
6666
|> Enum.find(fn {_, id} -> id == reason_id end)
6767
|> elem(0)
6868
end
69+
70+
# Implement the embed_as/1 function required by the Ecto.Type behaviour
71+
def embed_as(_), do: :dump
6972
end

apps/db/mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ defmodule DB.Mixfile do
5252
{:burnex, "~> 3.1"},
5353
{:hashids, "~> 2.0"},
5454
{:kaur, "~> 1.1"},
55-
{:mime, "~> 1.2"},
55+
{:mime, "~> 2.0.6"},
5656
{:scrivener_ecto, "~> 2.0"},
5757
{:algoliax, "~> 0.7.1"},
58+
{:httpoison, "~> 2.2"},
5859

5960
# Dev only
6061
{:exsync, "~> 0.2", only: :dev},

apps/db/test/db_schema/speaker_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule DB.Schema.SpeakerTest do
44
alias DB.Schema.Speaker
55

66
@valid_attrs %{
7-
full_name: "#{Faker.Name.first_name()} #{Faker.Name.last_name()}",
7+
full_name: "#{Faker.Person.first_name()} #{Faker.Person.last_name()}",
88
wikidata_item_id: nil
99
}
1010
@invalid_attrs %{}

apps/db/test/support/factory.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule DB.Factory do
2525

2626
def user_factory do
2727
%User{
28-
name: Faker.Name.first_name(),
28+
name: Faker.Person.first_name(),
2929
username: "User-#{random_string(10)}",
3030
email: Faker.Internet.email(),
3131
encrypted_password: "$2b$12$fe55IfCdqNzKp1wMIJDwVeG3f7guOduEE5HS2C9IJyfkuk3avbjQG",
@@ -65,8 +65,8 @@ defmodule DB.Factory do
6565

6666
def speaker_factory do
6767
%Speaker{
68-
full_name: Faker.Name.name(),
69-
title: Faker.Name.title(),
68+
full_name: Faker.Person.name(),
69+
title: Faker.Person.title(),
7070
country: Faker.Address.country_code()
7171
}
7272
end

0 commit comments

Comments
 (0)