Skip to content

Commit bfe2c9c

Browse files
authored
Merge pull request #31 from mroth/fb/28
Format code and lint in CI
2 parents 3ab89de + 1ac0a35 commit bfe2c9c

File tree

9 files changed

+142
-145
lines changed

9 files changed

+142
-145
lines changed

.github/workflows/tests.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,31 @@ jobs:
99
name: Ex${{matrix.elixir}}/OTP${{matrix.otp}}
1010
strategy:
1111
matrix:
12-
elixir: ["1.15.8", "1.16.3", "1.17.3", "1.18.2"]
13-
otp: ["25.3.2", "26.2.5", "27.2.4"]
14-
exclude:
15-
- elixir: "1.15.8"
16-
otp: "27.2.4"
17-
- elixir: "1.16.3"
18-
otp: "27.2.4"
12+
include:
13+
- elixir: "1.15"
14+
otp: "25"
15+
- elixir: "1.18"
16+
otp: "27"
17+
lint: true
1918
steps:
2019
- uses: actions/checkout@v4
2120
- uses: erlef/setup-beam@v1
2221
with:
2322
otp-version: ${{matrix.otp}}
2423
elixir-version: ${{matrix.elixir}}
25-
- run: mix deps.get
26-
- run: mix compile --warnings-as-errors
27-
- run: mix test
24+
- name: Install dependencies
25+
run: mix deps.get
26+
27+
- name: Compile
28+
run: mix compile --warnings-as-errors
29+
30+
- name: Run tests
31+
run: mix test
32+
33+
- name: checks that the mix.lock file has no unused deps
34+
run: mix deps.unlock --check-unused
35+
if: ${{ matrix.lint }}
36+
37+
- name: check if files are already formatted
38+
run: mix format --check-formatted
39+
if: ${{ matrix.lint }}

lib/exmoji.ex

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@ defmodule Exmoji do
1919
vendor_data_file = "lib/vendor/emoji-data/emoji.json"
2020
@external_resource vendor_data_file
2121

22-
rawfile = File.read! vendor_data_file
23-
rawdata = Jason.decode! rawfile, keys: :atoms
24-
emoji_chars = for char <- rawdata do
25-
%EmojiChar{
26-
name: char.name,
27-
unified: char.unified,
28-
variations: char.variations,
29-
short_name: char.short_name,
30-
short_names: char.short_names,
31-
text: char.text
32-
}
33-
end
34-
@emoji_chars emoji_chars
22+
rawfile = File.read!(vendor_data_file)
23+
rawdata = Jason.decode!(rawfile, keys: :atoms)
24+
25+
emoji_chars =
26+
for char <- rawdata do
27+
%EmojiChar{
28+
name: char.name,
29+
unified: char.unified,
30+
variations: char.variations,
31+
short_name: char.short_name,
32+
short_names: char.short_names,
33+
text: char.text
34+
}
35+
end
3536

37+
@emoji_chars emoji_chars
3638

3739
@doc """
38-
Returns a list of all #{Enum.count @emoji_chars} Emoji characters as `EmojiChar`.
40+
Returns a list of all #{Enum.count(@emoji_chars)} Emoji characters as `EmojiChar`.
3941
"""
4042
def all, do: @emoji_chars
4143

@@ -51,7 +53,6 @@ defmodule Exmoji do
5153
@all_variant_cache Enum.filter(@emoji_chars, &EmojiChar.variant?/1)
5254
def all_with_variants, do: @all_variant_cache
5355

54-
5556
@doc """
5657
Returns a list of all known Emoji characters rendered as Unicode bitstrings.
5758
@@ -67,13 +68,13 @@ defmodule Exmoji do
6768
case Keyword.get(opts, :include_variants, false) do
6869
false ->
6970
Enum.map(@emoji_chars, &EmojiChar.render/1)
71+
7072
true ->
7173
Enum.map(@emoji_chars, &EmojiChar.chars/1)
72-
|> List.flatten
74+
|> List.flatten()
7375
end
7476
end
7577

76-
7778
@doc """
7879
Returns a list of all known codepoints representing Emoji characters.
7980
@@ -83,14 +84,14 @@ defmodule Exmoji do
8384
def codepoints(opts \\ []) do
8485
case Keyword.get(opts, :include_variants, false) do
8586
false ->
86-
Enum.map(@emoji_chars, &(&1.unified))
87+
Enum.map(@emoji_chars, & &1.unified)
88+
8789
true ->
8890
Enum.map(@emoji_chars, &EmojiChar.codepoint_ids/1)
89-
|> List.flatten
91+
|> List.flatten()
9092
end
9193
end
9294

93-
9495
@doc """
9596
Finds any `EmojiChar` that contains given string in its official name.
9697
@@ -107,24 +108,22 @@ defmodule Exmoji do
107108
"""
108109
def find_by_name(name) do
109110
name = String.upcase(name)
110-
Enum.filter( @emoji_chars, &(String.contains?(&1.name, name)) )
111+
Enum.filter(@emoji_chars, &String.contains?(&1.name, name))
111112
end
112113

113-
114114
@doc """
115115
Find all `EmojiChar` that match substring in any of their associated short
116116
name keywords.
117117
"""
118118
def find_by_short_name(sname) do
119119
target = String.downcase(sname)
120-
Enum.filter( @emoji_chars, &(matches_short_name(&1, target)) )
120+
Enum.filter(@emoji_chars, &matches_short_name(&1, target))
121121
end
122122

123123
defp matches_short_name(%EmojiChar{} = ec, target) do
124-
Enum.any?( ec.short_names, &(String.contains?(&1, target)) )
124+
Enum.any?(ec.short_names, &String.contains?(&1, target))
125125
end
126126

127-
128127
@doc """
129128
Finds an `EmojiChar` based on its short name keyword.
130129
@@ -133,27 +132,27 @@ defmodule Exmoji do
133132
a keyword.
134133
"""
135134
def from_short_name(sname) do
136-
sname |> String.downcase |> _from_short_name
135+
sname |> String.downcase() |> _from_short_name
137136
end
138137

139138
for ec <- @emoji_chars, sn <- ec.short_names do
140-
defp _from_short_name( unquote(sn) ), do: unquote(Macro.escape(ec))
139+
defp _from_short_name(unquote(sn)), do: unquote(Macro.escape(ec))
141140
end
142-
defp _from_short_name(_), do: nil
143141

142+
defp _from_short_name(_), do: nil
144143

145144
@doc """
146145
Finds a specific `EmojiChar` based on the unified codepoint ID.
147146
"""
148147
def from_unified(uid) do
149-
uid |> String.upcase |> _from_unified
148+
uid |> String.upcase() |> _from_unified
150149
end
151150

152151
for ec <- @emoji_chars, cp <- EmojiChar.codepoint_ids(ec) do
153-
defp _from_unified( unquote(cp) ), do: unquote(Macro.escape(ec))
152+
defp _from_unified(unquote(cp)), do: unquote(Macro.escape(ec))
154153
end
155-
defp _from_unified(_), do: nil
156154

155+
defp _from_unified(_), do: nil
157156

158157
@doc """
159158
Convert a unified ID directly to its bitstring glyph representation.
@@ -167,11 +166,10 @@ defmodule Exmoji do
167166
def unified_to_char(uid) do
168167
uid
169168
|> String.split("-")
170-
|> Enum.map( &(String.to_integer(&1, 16)) )
171-
|> List.to_string
169+
|> Enum.map(&String.to_integer(&1, 16))
170+
|> List.to_string()
172171
end
173172

174-
175173
@doc """
176174
Convert a native bitstring glyph to its unified codepoint ID.
177175
@@ -189,16 +187,15 @@ defmodule Exmoji do
189187
"""
190188
def char_to_unified(char) do
191189
char
192-
|> String.codepoints
190+
|> String.codepoints()
193191
|> Enum.map(&padded_hex_string/1)
194192
|> Enum.join("-")
195-
|> String.upcase
193+
|> String.upcase()
196194
end
195+
197196
# produce a string representation of the integer value of a codepoint, in hex
198197
# this should be zero-padded to a minimum of 4 digits
199-
defp padded_hex_string(<< cp_int_value :: utf8 >>) do
198+
defp padded_hex_string(<<cp_int_value::utf8>>) do
200199
cp_int_value |> Integer.to_string(16) |> String.pad_leading(4, "0")
201200
end
202-
203-
204201
end

lib/exmoji/emoji_char.ex

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ defmodule Exmoji.EmojiChar do
2222
It also contains a few helper functions to deal with this data type.
2323
"""
2424

25-
defstruct [
26-
name: nil,
27-
unified: nil,
28-
variations: [],
29-
short_name: nil,
30-
short_names: [],
31-
text: nil
32-
]
25+
defstruct name: nil,
26+
unified: nil,
27+
variations: [],
28+
short_name: nil,
29+
short_names: [],
30+
text: nil
3331

3432
alias Exmoji.EmojiChar
3533

@@ -43,13 +41,15 @@ defmodule Exmoji.EmojiChar do
4341
Emoji characters that contain a possible variant.
4442
"""
4543
def render(ec, options \\ [variant_encoding: true])
44+
4645
def render(ec, variant_encoding: false) do
4746
Exmoji.unified_to_char(ec.unified)
4847
end
48+
4949
def render(ec, variant_encoding: true) do
5050
case variant?(ec) do
51-
true -> Exmoji.unified_to_char( variant(ec) )
52-
false -> Exmoji.unified_to_char( ec.unified )
51+
true -> Exmoji.unified_to_char(variant(ec))
52+
false -> Exmoji.unified_to_char(ec.unified)
5353
end
5454
end
5555

@@ -64,7 +64,7 @@ defmodule Exmoji.EmojiChar do
6464
all possible values to match against when searching for the emoji in a string
6565
representation.
6666
"""
67-
def chars(%EmojiChar{}=emojichar) do
67+
def chars(%EmojiChar{} = emojichar) do
6868
codepoint_ids(emojichar)
6969
|> Enum.map(&Exmoji.unified_to_char/1)
7070
end
@@ -114,7 +114,6 @@ defmodule Exmoji.EmojiChar do
114114
If there is no variant-encoding for a character, returns nil.
115115
"""
116116
def variant(%EmojiChar{variations: variations}) do
117-
List.first variations
117+
List.first(variations)
118118
end
119-
120119
end

lib/exmoji/scanner.ex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Exmoji.Scanner do
3535
#
3636
# Thus it is kept as public so we can compare it in test...
3737
fbs_pattern = Exmoji.chars(include_variants: true) |> Enum.join("|")
38-
@fbs_regexp Regex.compile!( "(?:#{fbs_pattern})" )
38+
@fbs_regexp Regex.compile!("(?:#{fbs_pattern})")
3939
@doc false
4040
def rscan(str) do
4141
Regex.scan(@fbs_regexp, str)
@@ -67,20 +67,21 @@ defmodule Exmoji.Scanner do
6767

6868
# first we sort all known char glyphs by reverse bitsize, so we can use the
6969
# bigger binary patterns first when defining our pattern match functions.
70-
sorted_chars = Enum.sort(
71-
Exmoji.chars(include_variants: true),
72-
&(&1 > &2)
73-
)
70+
sorted_chars =
71+
Enum.sort(
72+
Exmoji.chars(include_variants: true),
73+
&(&1 > &2)
74+
)
7475

7576
# define functions that pattern match against each emojichar binary at head.
7677
for glyph <- sorted_chars do
77-
defp _bscan(<< unquote(glyph), tail::binary >>, acc) do
78+
defp _bscan(<<unquote(glyph), tail::binary>>, acc) do
7879
_bscan(tail, [unquote(glyph) | acc])
7980
end
8081
end
82+
8183
# if nothing is found, cut the head off and move on.
82-
defp _bscan(<< _head::utf8, tail::binary >>, acc), do: _bscan(tail, acc)
84+
defp _bscan(<<_head::utf8, tail::binary>>, acc), do: _bscan(tail, acc)
8385
# when we reach the end, return reversed accumulator.
8486
defp _bscan(<<>>, acc), do: Enum.reverse(acc)
85-
8687
end

mix.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ defmodule Exmoji.Mixfile do
2020

2121
defp package do
2222
[
23-
description: "Emoji encoding swiss army knife for dealing with Unicode "
24-
<> "and other gotchas.",
25-
maintainers: ["Matthew Rothenberg <mroth@mroth.info>"],
23+
description:
24+
"Emoji encoding swiss army knife for dealing with Unicode " <>
25+
"and other gotchas.",
26+
maintainers: ["Matthew Rothenberg <mroth@mroth.info>", "Fabian Becker <halfdan@xnorfz.de>"],
2627
licenses: ["MIT"],
2728
links: %{
2829
"GitHub" => @source_url

mix.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
%{
22
"benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [:mix], [], "hexpm", "23f27cbc482cbac03fc8926441eb60a5e111759c17642bac005c3225f5eb809d"},
3-
"certifi": {:hex, :certifi, "2.8.0", "d4fb0a6bb20b7c9c3643e22507e42f356ac090a1dcea9ab99e27e0376d695eba", [:rebar3], [], "hexpm", "6ac7efc1c6f8600b08d625292d4bbf584e14847ce1b6b5c44d983d273e1097ea"},
43
"earmark": {:hex, :earmark, "1.4.47", "7e7596b84fe4ebeb8751e14cbaeaf4d7a0237708f2ce43630cfd9065551f94ca", [:mix], [], "hexpm", "3e96bebea2c2d95f3b346a7ff22285bc68a99fbabdad9b655aa9c6be06c698f8"},
54
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
65
"ex_doc": {:hex, :ex_doc, "0.37.3", "f7816881a443cd77872b7d6118e8a55f547f49903aef8747dbcb345a75b462f9", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "e6aebca7156e7c29b5da4daa17f6361205b2ae5f26e5c7d8ca0d3f7e18972233"},
76
"excoveralls": {:hex, :excoveralls, "0.18.5", "e229d0a65982613332ec30f07940038fe451a2e5b29bce2a5022165f0c9b157e", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "523fe8a15603f86d64852aab2abe8ddbd78e68579c8525ae765facc5eae01562"},
8-
"hackney": {:hex, :hackney, "1.18.0", "c4443d960bb9fba6d01161d01cd81173089686717d9490e5d3606644c48d121f", [:rebar3], [{:certifi, "~>2.8.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "9afcda620704d720db8c6a3123e9848d09c87586dc1c10479c42627b905b5c5e"},
9-
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
107
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
118
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
129
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
1310
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
14-
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
15-
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
1611
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
17-
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
18-
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
19-
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
2012
}

0 commit comments

Comments
 (0)