Skip to content

Commit

Permalink
fix: elixir 17 & 18 compatibility (elixirs#565)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Kapkov <[email protected]>
  • Loading branch information
ypconstante and igas authored Jan 30, 2025
1 parent d13623f commit f3d4808
Show file tree
Hide file tree
Showing 26 changed files with 343 additions and 207 deletions.
68 changes: 16 additions & 52 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
credo:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
Expand All @@ -15,13 +15,18 @@ jobs:
path: _build
- uses: erlef/[email protected]
with:
elixir-version: 1.15.x
elixir-version: 1.17.3
otp-version: 26.x
- run: mix deps.get
- run: mix credo --strict --format=sarif
- run: mix compile
- run: mix credo suggest --format=sarif --mute-exit-status > credo.sarif
- name: Upload SARIF
uses: github/codeql-action/[email protected]
with:
sarif_file: credo.sarif

# dialyzer:
# runs-on: ${{ matrix.os || 'ubuntu-20.04' }}
# runs-on: ${{ matrix.os || 'ubuntu-24.04' }}

# steps:
# - uses: actions/[email protected]
Expand Down Expand Up @@ -53,7 +58,7 @@ jobs:
# - run: mix dialyzer --format github

test:
runs-on: ${{ matrix.os || 'ubuntu-20.04' }}
runs-on: ${{ matrix.os || 'ubuntu-24.04' }}
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
Expand All @@ -70,50 +75,9 @@ jobs:
fail-fast: false
matrix:
include:
- elixir: 1.11.x
otp: 21.x
os: ubuntu-20.04
- elixir: 1.11.x
otp: 22.x
os: ubuntu-20.04
- elixir: 1.11.x
otp: 23.x
os: ubuntu-20.04
- elixir: 1.12.x
otp: 22.x
os: ubuntu-20.04
- elixir: 1.12.x
otp: 23.x
os: ubuntu-20.04
- elixir: 1.12.x
otp: 24.x
os: ubuntu-20.04
- elixir: 1.13.x
otp: 22.x
os: ubuntu-20.04
- elixir: 1.13.x
otp: 23.x
os: ubuntu-20.04
- elixir: 1.13.x
otp: 24.x
os: ubuntu-20.04
- elixir: 1.14.x
otp: 23.x
os: ubuntu-20.04
- elixir: 1.14.x
otp: 24.x
os: ubuntu-20.04
- elixir: 1.14.x
otp: 25.x
os: ubuntu-20.04
- elixir: 1.15.x
otp: 24.x
os: ubuntu-20.04
- elixir: 1.15.x
otp: 25.x
os: ubuntu-20.04
# Something changed in otp 26 for seed and single test started producing failures
# it does not affect functionality, only CI
# - elixir: 1.15.x
# otp: 26.x
# os: ubuntu-20.04
- elixir: 1.16.x
otp: 26.x
- elixir: 1.17.x
otp: 27.x
- elixir: 1.18.x
otp: 27.x
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format.

### Added

- Test with Elixir 1.16 and 1.17 on CI [[@ypconstante](https://github.com/ypconstante)]
- Test with OTP 26 and 27 on CI [[@ypconstante](https://github.com/ypconstante)]

### Changed

### Deprecated
Expand All @@ -19,6 +22,7 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format.
### Fixed

- Fix compile and runtime warnings on Elixir 1.17 [[@ypconstante](https://github.com/ypconstante)]
- `Faker.Internet.slug` and `Faker.Markdown.markdown/0` results won't change between Elixir versions [[@ypconstante](https://github.com/ypconstante)]

### Security

Expand Down
6 changes: 6 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Config

if Mix.env() == :dev do
config :mix_test_watch,
clear: true
end
8 changes: 8 additions & 0 deletions lib/faker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ defmodule Faker do
Application.get_env(:faker, :random_module).random_bytes(total)
end

@doc """
Returns a shuffled enum.
"""
@spec shuffle(Enum.t()) :: list()
def shuffle(enum) do
Application.get_env(:faker, :random_module).shuffle(enum)
end

defmacro localize(function) do
quote do
def unquote(function)() do
Expand Down
4 changes: 2 additions & 2 deletions lib/faker/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ defmodule Faker.File do
~w(video/mpeg video/mp4 video/ogg video/quicktime video/webm video/x-matroska video/x-ms-wmv video/x-flv)
}

@categories_extensions Map.keys(@extensions)
@categories_mimes Map.keys(@mimes)
@categories_extensions @extensions |> Map.keys() |> Enum.sort()
@categories_mimes @mimes |> Map.keys() |> Enum.sort()

@doc """
Returns a random file extension
Expand Down
8 changes: 4 additions & 4 deletions lib/faker/fruit/en.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ defmodule Faker.Fruit.En do
@doc """
Returns a fruit.
## Examples
iex> Faker.Fruit.En.fruit
iex> Faker.Fruit.En.fruit()
"Kiwano"
iex> Faker.Fruit.En.fruit
iex> Faker.Fruit.En.fruit()
"Sugarcane"
iex> Faker.Fruit.En.fruit
iex> Faker.Fruit.En.fruit()
"Pineapple"
iex> Faker.Fruit.En.fruit
iex> Faker.Fruit.En.fruit()
"Lemon"
"""
@spec fruit() :: String.t()
Expand Down
8 changes: 4 additions & 4 deletions lib/faker/fruit/pt_br.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ defmodule Faker.Fruit.PtBr do
## Examples
iex> Faker.Fruit.PtBr.fruit
iex> Faker.Fruit.PtBr.fruit()
"Fruta-do-conde"
iex> Faker.Fruit.PtBr.fruit
iex> Faker.Fruit.PtBr.fruit()
"Bergamota"
iex> Faker.Fruit.PtBr.fruit
iex> Faker.Fruit.PtBr.fruit()
"Quixaba"
iex> Faker.Fruit.PtBr.fruit
iex> Faker.Fruit.PtBr.fruit()
"Amora"
"""
@spec fruit() :: String.t()
Expand Down
8 changes: 4 additions & 4 deletions lib/faker/gov/it.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ defmodule Faker.Gov.It do
## Examples
iex> Faker.Gov.It.fiscal_id
iex> Faker.Gov.It.fiscal_id()
"ELRCEA64C50A918F"
iex> Faker.Gov.It.fiscal_id
iex> Faker.Gov.It.fiscal_id()
"ZSLNKH22M34H480J"
iex> Faker.Gov.It.fiscal_id
iex> Faker.Gov.It.fiscal_id()
"OCPCVO90M50F353I"
iex> Faker.Gov.It.fiscal_id
iex> Faker.Gov.It.fiscal_id()
"PQYRFX94R54C681K"
"""
@spec fiscal_id() :: binary()
Expand Down
16 changes: 8 additions & 8 deletions lib/faker/gov/us.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ defmodule Faker.Gov.Us do
## Examples
iex> Faker.Gov.Us.ssn
iex> Faker.Gov.Us.ssn()
"838-84-5749"
iex> Faker.Gov.Us.ssn
iex> Faker.Gov.Us.ssn()
"719-41-8674"
iex> Faker.Gov.Us.ssn
iex> Faker.Gov.Us.ssn()
"213-54-3766"
iex> Faker.Gov.Us.ssn
iex> Faker.Gov.Us.ssn()
"379-09-6851"
"""
@spec ssn() :: String.t()
Expand All @@ -37,13 +37,13 @@ defmodule Faker.Gov.Us do
## Examples
iex> Faker.Gov.Us.ein
iex> Faker.Gov.Us.ein()
"04-0389586"
iex> Faker.Gov.Us.ein
iex> Faker.Gov.Us.ein()
"07-8027034"
iex> Faker.Gov.Us.ein
iex> Faker.Gov.Us.ein()
"41-6859447"
iex> Faker.Gov.Us.ein
iex> Faker.Gov.Us.ein()
"83-6106581"
"""
@spec ein() :: String.t()
Expand Down
24 changes: 12 additions & 12 deletions lib/faker/industry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ defmodule Faker.Industry do
## Examples
iex> Faker.Industry.industry
iex> Faker.Industry.industry()
"Oil & Gas"
iex> Faker.Industry.industry
iex> Faker.Industry.industry()
"Basic Materials"
iex> Faker.Industry.industry
iex> Faker.Industry.industry()
"Consumer Services"
iex> Faker.Industry.industry
iex> Faker.Industry.industry()
"Health Care"
"""
@spec industry() :: String.t()
Expand All @@ -28,13 +28,13 @@ defmodule Faker.Industry do
## Examples
iex> Faker.Industry.super_sector
iex> Faker.Industry.super_sector()
"Automobiles & Parts"
iex> Faker.Industry.super_sector
iex> Faker.Industry.super_sector()
"Banks"
iex> Faker.Industry.super_sector
iex> Faker.Industry.super_sector()
"Automobiles & Parts"
iex> Faker.Industry.super_sector
iex> Faker.Industry.super_sector()
"Health Care"
"""
@spec super_sector() :: String.t()
Expand All @@ -45,13 +45,13 @@ defmodule Faker.Industry do
## Examples
iex> Faker.Industry.sector
iex> Faker.Industry.sector()
"Food & Drug Retailers"
iex> Faker.Industry.sector
iex> Faker.Industry.sector()
"Banks"
iex> Faker.Industry.sector
iex> Faker.Industry.sector()
"Software & Computer Services"
iex> Faker.Industry.sector
iex> Faker.Industry.sector()
"Media"
"""
@spec sector() :: String.t()
Expand Down
24 changes: 12 additions & 12 deletions lib/faker/industry/en.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ defmodule Faker.Industry.En do
## Examples
iex> Faker.Industry.En.industry
iex> Faker.Industry.En.industry()
"Oil & Gas"
iex> Faker.Industry.En.industry
iex> Faker.Industry.En.industry()
"Basic Materials"
iex> Faker.Industry.En.industry
iex> Faker.Industry.En.industry()
"Consumer Services"
iex> Faker.Industry.En.industry
iex> Faker.Industry.En.industry()
"Health Care"
"""
@spec industry() :: String.t()
Expand All @@ -38,13 +38,13 @@ defmodule Faker.Industry.En do
## Examples
iex> Faker.Industry.En.super_sector
iex> Faker.Industry.En.super_sector()
"Automobiles & Parts"
iex> Faker.Industry.En.super_sector
iex> Faker.Industry.En.super_sector()
"Banks"
iex> Faker.Industry.En.super_sector
iex> Faker.Industry.En.super_sector()
"Automobiles & Parts"
iex> Faker.Industry.En.super_sector
iex> Faker.Industry.En.super_sector()
"Health Care"
"""
@spec super_sector() :: String.t()
Expand Down Expand Up @@ -75,13 +75,13 @@ defmodule Faker.Industry.En do
## Examples
iex> Faker.Industry.En.sector
iex> Faker.Industry.En.sector()
"Food & Drug Retailers"
iex> Faker.Industry.En.sector
iex> Faker.Industry.En.sector()
"Banks"
iex> Faker.Industry.En.sector
iex> Faker.Industry.En.sector()
"Software & Computer Services"
iex> Faker.Industry.En.sector
iex> Faker.Industry.En.sector()
"Media"
"""
@spec sector() :: String.t()
Expand Down
8 changes: 4 additions & 4 deletions lib/faker/industry/hy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ defmodule Faker.Industry.Hy do
## Examples
iex> Faker.Industry.Hy.industry
iex> Faker.Industry.Hy.industry()
"Հյուրընկալություն"
iex> Faker.Industry.Hy.industry
iex> Faker.Industry.Hy.industry()
"Բժշկական Գործունեություն"
iex> Faker.Industry.Hy.industry
iex> Faker.Industry.Hy.industry()
"Վենչուրային և Մասնավոր Կապիտալ"
iex> Faker.Industry.Hy.industry
iex> Faker.Industry.Hy.industry()
"Էներգետիկա"
"""
@spec industry() :: String.t()
Expand Down
8 changes: 4 additions & 4 deletions lib/faker/internet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ defmodule Faker.Internet do
## Examples
iex> Faker.Internet.slug()
"sint-deleniti-consequatur-ut"
"deleniti-sint-consequatur-ut"
iex> Faker.Internet.slug()
"sit_et"
"cumque_sit_aut_expedita"
iex> Faker.Internet.slug(["foo", "bar"])
"foo-bar"
"foo_bar"
iex> Faker.Internet.slug(["foo", "bar"], ["."])
"foo.bar"
"""
Expand All @@ -313,7 +313,7 @@ defmodule Faker.Internet do
@spec slug([String.t()], [String.t()]) :: String.t()
def slug(words, glue) do
words
|> Enum.take_random(length(words))
|> Faker.shuffle()
|> Enum.join(pick(glue))
|> String.downcase()
end
Expand Down
Loading

0 comments on commit f3d4808

Please sign in to comment.