Skip to content

Commit 6a19004

Browse files
NSHkrNSHkr
authored andcommitted
mix format
1 parent 01ef276 commit 6a19004

File tree

6 files changed

+61
-49
lines changed

6 files changed

+61
-49
lines changed

lib/json_remedy/context/context_values.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,20 @@ defmodule JsonRemedy.Context.ContextValues do
5959
# Invalid contexts
6060
{from, _to} when from not in @valid_contexts -> false
6161
{_from, to} when to not in @valid_contexts -> false
62-
6362
# Valid transitions from root
6463
{:root, :object_key} -> true
6564
{:root, :array} -> true
6665
{:root, _} -> false
67-
6866
# Valid transitions from object_key
6967
{:object_key, :object_value} -> true
7068
{:object_key, :object_key} -> true
7169
{:object_key, :array} -> true
7270
{:object_key, _} -> false
73-
7471
# Valid transitions from object_value
7572
{:object_value, :object_key} -> true
7673
{:object_value, :object_value} -> true
7774
{:object_value, :array} -> true
7875
{:object_value, _} -> false
79-
8076
# Valid transitions from array
8177
{:array, :object_key} -> true
8278
{:array, :array} -> true
@@ -136,7 +132,13 @@ defmodule JsonRemedy.Context.ContextValues do
136132
end
137133

138134
def context_allows_repair?(:array, repair_type) do
139-
repair_type in [:comma_fix, :bracket_fix, :boolean_normalization, :null_normalization, :quote_normalization]
135+
repair_type in [
136+
:comma_fix,
137+
:bracket_fix,
138+
:boolean_normalization,
139+
:null_normalization,
140+
:quote_normalization
141+
]
140142
end
141143

142144
def context_allows_repair?(:root, repair_type) do

lib/json_remedy/context/json_context.ex

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ defmodule JsonRemedy.Context.JsonContext do
6868
"""
6969
@spec push_context(t(), context_value()) :: t()
7070
def push_context(%__MODULE__{} = context, new_context) do
71-
%{context |
72-
current: new_context,
73-
stack: [context.current | context.stack]
74-
}
71+
%{context | current: new_context, stack: [context.current | context.stack]}
7572
end
7673

7774
@doc """
@@ -95,10 +92,7 @@ defmodule JsonRemedy.Context.JsonContext do
9592
end
9693

9794
def pop_context(%__MODULE__{stack: [head | tail]} = context) do
98-
%{context |
99-
current: head,
100-
stack: tail
101-
}
95+
%{context | current: head, stack: tail}
10296
end
10397

10498
@doc """
@@ -116,10 +110,7 @@ defmodule JsonRemedy.Context.JsonContext do
116110
"""
117111
@spec enter_string(t(), String.t()) :: t()
118112
def enter_string(%__MODULE__{} = context, delimiter) do
119-
%{context |
120-
in_string: true,
121-
string_delimiter: delimiter
122-
}
113+
%{context | in_string: true, string_delimiter: delimiter}
123114
end
124115

125116
@doc """
@@ -137,10 +128,7 @@ defmodule JsonRemedy.Context.JsonContext do
137128
"""
138129
@spec exit_string(t()) :: t()
139130
def exit_string(%__MODULE__{} = context) do
140-
%{context |
141-
in_string: false,
142-
string_delimiter: nil
143-
}
131+
%{context | in_string: false, string_delimiter: nil}
144132
end
145133

146134
@doc """

lib/json_remedy/utils/char_utils.ex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ defmodule JsonRemedy.Utils.CharUtils do
7979
nil
8080
"""
8181
@spec get_char_at(String.t() | nil, position(), any()) :: any()
82-
def get_char_at(input, position, default) when is_binary(input) and is_integer(position) and position >= 0 do
82+
def get_char_at(input, position, default)
83+
when is_binary(input) and is_integer(position) and position >= 0 do
8384
case String.at(input, position) do
8485
nil -> default
8586
char -> char
@@ -125,7 +126,8 @@ defmodule JsonRemedy.Utils.CharUtils do
125126
"""
126127
@spec skip_to_character(String.t() | nil, String.t() | nil, position()) :: search_result()
127128
def skip_to_character(input, target_char, start_pos)
128-
when is_binary(input) and is_binary(target_char) and is_integer(start_pos) and start_pos >= 0 do
129+
when is_binary(input) and is_binary(target_char) and is_integer(start_pos) and
130+
start_pos >= 0 do
129131
input_length = String.length(input)
130132

131133
if start_pos >= input_length do
@@ -174,15 +176,18 @@ defmodule JsonRemedy.Utils.CharUtils do
174176
"""
175177
@spec skip_whitespaces_at(String.t() | nil, position(), position()) :: position()
176178
def skip_whitespaces_at(input, start_pos, end_pos)
177-
when is_binary(input) and is_integer(start_pos) and is_integer(end_pos)
178-
and start_pos >= 0 and end_pos >= 0 do
179+
when is_binary(input) and is_integer(start_pos) and is_integer(end_pos) and
180+
start_pos >= 0 and end_pos >= 0 do
179181
input_length = String.length(input)
180182
actual_end = min(end_pos, input_length)
181183

182184
skip_whitespace_loop(input, start_pos, actual_end)
183185
end
184186

185-
def skip_whitespaces_at(_input, start_pos, _end_pos) when is_integer(start_pos) and start_pos >= 0, do: start_pos
187+
def skip_whitespaces_at(_input, start_pos, _end_pos)
188+
when is_integer(start_pos) and start_pos >= 0,
189+
do: start_pos
190+
186191
def skip_whitespaces_at(_input, _start_pos, _end_pos), do: 0
187192

188193
@doc """
@@ -265,16 +270,19 @@ defmodule JsonRemedy.Utils.CharUtils do
265270
nil
266271
"""
267272
@spec char_at_position_safe(String.t() | nil, position()) :: char_result()
268-
def char_at_position_safe(input, position) when is_binary(input) and is_integer(position) and position >= 0 do
273+
def char_at_position_safe(input, position)
274+
when is_binary(input) and is_integer(position) and position >= 0 do
269275
String.at(input, position)
270276
end
271277

272278
def char_at_position_safe(_input, _position), do: nil
273279

274280
# Private helper functions
275281

276-
@spec find_character_from_position(String.t(), String.t(), position(), position()) :: search_result()
277-
defp find_character_from_position(input, target_char, pos, input_length) when pos < input_length do
282+
@spec find_character_from_position(String.t(), String.t(), position(), position()) ::
283+
search_result()
284+
defp find_character_from_position(input, target_char, pos, input_length)
285+
when pos < input_length do
278286
case String.at(input, pos) do
279287
^target_char -> pos
280288
_ -> find_character_from_position(input, target_char, pos + 1, input_length)
@@ -288,6 +296,7 @@ defmodule JsonRemedy.Utils.CharUtils do
288296
case String.at(input, pos) do
289297
char when char in [" ", "\t", "\n", "\r", "\f", "\v"] ->
290298
skip_whitespace_loop(input, pos + 1, end_pos)
299+
291300
_ ->
292301
pos
293302
end

test/integration/context_integration_test.exs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ defmodule JsonRemedy.Integration.ContextIntegrationTest do
2727
end
2828

2929
test "string context handling" do
30-
context = JsonContext.new()
30+
context =
31+
JsonContext.new()
3132
|> JsonContext.push_context(:object_value)
3233
|> JsonContext.update_position(5)
3334
|> JsonContext.enter_string("\"")
@@ -108,7 +109,8 @@ defmodule JsonRemedy.Integration.ContextIntegrationTest do
108109
end
109110

110111
test "context system complements existing string detection" do
111-
context = JsonContext.new()
112+
context =
113+
JsonContext.new()
112114
|> JsonContext.enter_string("\"")
113115

114116
# Both should agree when in string
@@ -122,18 +124,20 @@ defmodule JsonRemedy.Integration.ContextIntegrationTest do
122124
context = JsonContext.new()
123125

124126
# Build deep nesting
125-
context = Enum.reduce(1..10, context, fn _i, acc ->
126-
acc
127-
|> JsonContext.push_context(:object_key)
128-
|> JsonContext.push_context(:array)
129-
end)
127+
context =
128+
Enum.reduce(1..10, context, fn _i, acc ->
129+
acc
130+
|> JsonContext.push_context(:object_key)
131+
|> JsonContext.push_context(:array)
132+
end)
130133

131134
assert JsonContext.context_stack_depth(context) == 20
132135

133136
# Unwind it
134-
context = Enum.reduce(1..20, context, fn _i, acc ->
135-
JsonContext.pop_context(acc)
136-
end)
137+
context =
138+
Enum.reduce(1..20, context, fn _i, acc ->
139+
JsonContext.pop_context(acc)
140+
end)
137141

138142
assert context.current == :root
139143
assert JsonContext.context_stack_depth(context) == 0
@@ -157,8 +161,10 @@ defmodule JsonRemedy.Integration.ContextIntegrationTest do
157161
describe "real-world scenarios" do
158162
test "object parsing context flow" do
159163
# Simulate parsing: {"key": "value", "key2": 42}
160-
context = JsonContext.new()
161-
|> JsonContext.push_context(:object_key) # {
164+
context =
165+
JsonContext.new()
166+
# {
167+
|> JsonContext.push_context(:object_key)
162168
|> JsonContext.update_position(1)
163169

164170
# At key position
@@ -177,7 +183,8 @@ defmodule JsonRemedy.Integration.ContextIntegrationTest do
177183

178184
test "array parsing context flow" do
179185
# Simulate parsing: [1, "string", true]
180-
context = JsonContext.new()
186+
context =
187+
JsonContext.new()
181188
|> JsonContext.push_context(:array)
182189
|> JsonContext.update_position(1)
183190

test/unit/context/context_values_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ defmodule JsonRemedy.Context.ContextValuesTest do
128128
test "returns higher priority for context-specific repairs" do
129129
# Object key context prioritizes key repairs
130130
assert ContextValues.get_repair_priority(:object_key, :unquoted_keys) >
131-
ContextValues.get_repair_priority(:object_key, :boolean_normalization)
131+
ContextValues.get_repair_priority(:object_key, :boolean_normalization)
132132

133133
# Object value context prioritizes value repairs
134134
assert ContextValues.get_repair_priority(:object_value, :boolean_normalization) >
135-
ContextValues.get_repair_priority(:object_value, :unquoted_keys)
135+
ContextValues.get_repair_priority(:object_value, :unquoted_keys)
136136
end
137137

138138
test "returns base priority for unknown repairs" do

test/unit/utils/char_utils_test.exs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ defmodule JsonRemedy.Utils.CharUtilsTest do
8585

8686
test "skips different types of whitespace" do
8787
whitespace_string = " \t\n\r test"
88-
expected_position = 6 # After all whitespace
88+
# After all whitespace
89+
expected_position = 6
8990

90-
assert CharUtils.skip_whitespaces_at(whitespace_string, 0, String.length(whitespace_string)) == expected_position
91+
assert CharUtils.skip_whitespaces_at(whitespace_string, 0, String.length(whitespace_string)) ==
92+
expected_position
9193
end
9294

9395
test "respects end position limit" do
@@ -96,8 +98,11 @@ defmodule JsonRemedy.Utils.CharUtilsTest do
9698
end
9799

98100
test "handles starting from non-zero position" do
99-
assert CharUtils.skip_whitespaces_at("hello world", 5, String.length("hello world")) == 8
100-
assert CharUtils.skip_whitespaces_at("test \t\n end", 4, String.length("test \t\n end")) == 10
101+
assert CharUtils.skip_whitespaces_at("hello world", 5, String.length("hello world")) ==
102+
8
103+
104+
assert CharUtils.skip_whitespaces_at("test \t\n end", 4, String.length("test \t\n end")) ==
105+
10
101106
end
102107

103108
test "returns same position when no whitespace" do
@@ -108,7 +113,8 @@ defmodule JsonRemedy.Utils.CharUtilsTest do
108113
test "handles edge cases" do
109114
assert CharUtils.skip_whitespaces_at("", 0, 0) == 0
110115
assert CharUtils.skip_whitespaces_at(" ", 0, 3) == 3
111-
assert CharUtils.skip_whitespaces_at("hello", 10, 15) == 10 # Out of bounds
116+
# Out of bounds
117+
assert CharUtils.skip_whitespaces_at("hello", 10, 15) == 10
112118
end
113119

114120
test "works with UTF-8 whitespace and content" do

0 commit comments

Comments
 (0)