From c26f33a3bb4a93bd42647b6b41d578c61643a2a4 Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Sun, 4 Aug 2024 20:50:03 +0300 Subject: [PATCH 1/8] Warn when missing semicolons --- lib/live_view_native/swiftui/rules_parser.ex | 15 ++- .../swiftui/rules_parser/modifiers.ex | 1 + .../swiftui/rules_parser/parser.ex | 26 ++++-- .../swiftui/rules_parser/parser/context.ex | 15 +-- .../swiftui/rules_parser/parser/error.ex | 93 ++++++++++--------- .../swiftui/rules_parser/tokens.ex | 13 +++ .../swiftui/rules_parser_test.exs | 77 +++++++++++++++ 7 files changed, 176 insertions(+), 64 deletions(-) diff --git a/lib/live_view_native/swiftui/rules_parser.ex b/lib/live_view_native/swiftui/rules_parser.ex index 3062ea296..f16a5335a 100644 --- a/lib/live_view_native/swiftui/rules_parser.ex +++ b/lib/live_view_native/swiftui/rules_parser.ex @@ -3,12 +3,14 @@ defmodule LiveViewNative.SwiftUI.RulesParser do alias LiveViewNative.SwiftUI.RulesParser.Modifiers alias LiveViewNative.SwiftUI.RulesParser.Parser + require Logger def parse(rules, opts \\ []) do file = Keyword.get(opts, :file) || "" module = Keyword.get(opts, :module) || "" line = Keyword.get(opts, :line) || 1 variable_context = Keyword.get(opts, :variable_context, Elixir) + expect_semicolons? = Keyword.get(opts, :expect_semicolons?, false) context = opts @@ -16,6 +18,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser do |> Map.put_new(:file, file) |> Map.put_new(:source_line, line) |> Map.put_new(:module, module) + |> Map.put_new(:expect_semicolons?, expect_semicolons?) |> Map.put_new( :annotations, Application.get_env(:live_view_native_stylesheet, :annotations, false) @@ -35,10 +38,12 @@ defmodule LiveViewNative.SwiftUI.RulesParser do |> Parser.error_from_result() case result do - {:ok, [output], _unconsumed = "", _context, _current_line_and_offset, _} -> + {:ok, [output], warnings} -> + log_warnings(warnings, file) output - {:ok, output, _unconsumed = "", _context, _current_line_and_offset, _} -> + {:ok, output, warnings} -> + log_warnings(warnings, file) output {:error, message, _unconsumed, _context, {line, _}, _} -> @@ -48,4 +53,10 @@ defmodule LiveViewNative.SwiftUI.RulesParser do line: line end end + + def log_warnings(warnings, file) do + for {message, {line, _}, _offset} <- warnings do + IO.warn(message, line: line, file: file) + end + end end diff --git a/lib/live_view_native/swiftui/rules_parser/modifiers.ex b/lib/live_view_native/swiftui/rules_parser/modifiers.ex index 9b2341927..8eb1ca30a 100644 --- a/lib/live_view_native/swiftui/rules_parser/modifiers.ex +++ b/lib/live_view_native/swiftui/rules_parser/modifiers.ex @@ -283,6 +283,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Modifiers do ignore_whitespace() |> concat(modifier_name()) |> concat(modifier_brackets.(nested: false)) + |> expect_semicolon_or_warn() |> post_traverse({PostProcessors, :to_function_call_ast, []}), export_combinator: true ) diff --git a/lib/live_view_native/swiftui/rules_parser/parser.ex b/lib/live_view_native/swiftui/rules_parser/parser.ex index acea3e863..98c6c3d13 100644 --- a/lib/live_view_native/swiftui/rules_parser/parser.ex +++ b/lib/live_view_native/swiftui/rules_parser/parser.ex @@ -35,8 +35,8 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser do choices ++ if generate_error? do [ - error_parser - |> put_error( + put_error( + error_parser, "Expected one of the following:\n" <> label_from_named_choices(named_choices) <> "\n", show_incorrect_text?: show_incorrect_text? @@ -49,16 +49,19 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser do end def expect(combinator \\ empty(), combinator_2, opts) do - error_parser = Keyword.get(opts, :error_parser, non_whitespace()) - error_message = Keyword.get(opts, :error_message) - generate_error? = Keyword.get(opts, :generate_error?, true) + opts = + opts + |> Keyword.update(:error_parser, non_whitespace(), &(&1 || empty())) + |> Keyword.update(:error_message, "", & &1) + |> Keyword.update(:generate_error?, true, & &1) + |> Keyword.update(:warning, false, & &1) combinator |> concat( - if generate_error? do + if opts[:generate_error?] do choice([ combinator_2, - put_error(error_parser, error_message, opts) + put_error(opts[:error_parser], opts[:error_message], opts) ]) else combinator_2 @@ -150,8 +153,13 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser do {message, position, byte_offset} = Error.context_to_error_message(context) {:error, message, rest, context, position, byte_offset} - result -> - result + {:ok, output, _unconsumed = "", %{context: %Context{} = context}, _, _} -> + warnings = + Enum.map(context.warnings, fn warning -> + Error.context_to_error_message(context, warning) + end) + + {:ok, output, warnings} end end end diff --git a/lib/live_view_native/swiftui/rules_parser/parser/context.ex b/lib/live_view_native/swiftui/rules_parser/parser/context.ex index 0bd5990db..b427f6a58 100644 --- a/lib/live_view_native/swiftui/rules_parser/parser/context.ex +++ b/lib/live_view_native/swiftui/rules_parser/parser/context.ex @@ -8,6 +8,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Context do source: "", source_lines: [], errors: [], + warnings: [], highlight_error: true, # Where in the code does the input start? # Useful for localizing errors when parsing sigil text @@ -45,14 +46,14 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Context do if is_frozen?(context) and not error.forced? do context else - path = [:context, Access.key(:errors)] + path = + if error.is_warning? do + [:context, Access.key(:warnings)] + else + [:context, Access.key(:errors)] + end - {_, context} = - get_and_update_in(context, path, fn - existing_errors -> {[error | existing_errors], [error | existing_errors]} - end) - - context + update_in(context, path, &[error | &1]) end end diff --git a/lib/live_view_native/swiftui/rules_parser/parser/error.ex b/lib/live_view_native/swiftui/rules_parser/parser/error.ex index 9b4a250ae..e0054d3fd 100644 --- a/lib/live_view_native/swiftui/rules_parser/parser/error.ex +++ b/lib/live_view_native/swiftui/rules_parser/parser/error.ex @@ -9,70 +9,64 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Error do :line, :byte_offset, :error_message, - forced?: false + forced?: false, + is_warning?: false ]) def put_error( rest, args, context, - _, - _, - error_message, - opts \\ [] - ) - - def put_error( - rest, - [] = arg, - context, - {line, _offset}, - byte_offset, - error_message, - opts - ) do - # IO.inspect({[], rest, error_message}, label: "error[0]") - - context = - Context.put_new_error(context, rest, %__MODULE__{ - incorrect_text: "", - line: line, - byte_offset: byte_offset, - error_message: error_message, - show_incorrect_text?: Keyword.get(opts, :show_incorrect_text?, false), - forced?: Keyword.get(opts, :force_error?, false) - }) - - {rest, arg, context} - end - - def put_error( - rest, - [matched_text | _] = args, - context, {line, _offset}, byte_offset, error_message, - opts + opts \\ [] ) do - # IO.inspect({matched_text, rest, error_message}, label: "error[0]") + # IO.inspect({args, rest, error_message}, label: "error[0]") + + error = %__MODULE__{ + incorrect_text: List.first(args, ""), + line: line, + byte_offset: byte_offset, + error_message: error_message, + show_incorrect_text?: Keyword.get(opts, :show_incorrect_text?, false), + forced?: Keyword.get(opts, :force_error?, false), + is_warning?: false + } context = - Context.put_new_error(context, rest, %__MODULE__{ - incorrect_text: matched_text, - line: line, - byte_offset: byte_offset, - error_message: error_message, - show_incorrect_text?: Keyword.get(opts, :show_incorrect_text?, false), - forced?: Keyword.get(opts, :force_error?, false) - }) + case opts[:warning] do + true -> + # Always treat error as warning + Context.put_new_error(context, rest, %{error | is_warning?: true}) + + false -> + # Never treat error as warning + Context.put_new_error(context, rest, error) + + nil -> + # Never treat error as warning + Context.put_new_error(context, rest, error) + + warning -> + # The error is an optional warning + # Only log the warning if value in `context[]` is true + if get_in(context, [Access.key(warning)]) == true do + Context.put_new_error(context, rest, %{error | is_warning?: true}) + else + context + end + end {rest, args, context} end def context_to_error_message(context) do [%__MODULE__{} = error | _] = Enum.reverse(context.errors) + context_to_error_message(context, error) + end + def context_to_error_message(context, %__MODULE__{} = error) do error_message = error.error_message line = error.line incorrect_text = error.incorrect_text @@ -144,8 +138,15 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Error do "" end + header = + if error.is_warning? do + "" + else + "Unsupported input:" + end + message = """ - Unsupported input: + #{header} #{line_spacer} | #{lines} #{line_spacer} | diff --git a/lib/live_view_native/swiftui/rules_parser/tokens.ex b/lib/live_view_native/swiftui/rules_parser/tokens.ex index bab7af11c..6bde15ba0 100644 --- a/lib/live_view_native/swiftui/rules_parser/tokens.ex +++ b/lib/live_view_native/swiftui/rules_parser/tokens.ex @@ -113,6 +113,19 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Tokens do combinator |> ignore(optional(whitespace(min: 1))) end + def expect_semicolon_or_warn(combinator) do + combinator + |> concat( + ignore(string(";")) + |> expect( + warning: :expect_semicolons?, + error_message: "Expected a ‘;’", + error_parser: empty(), + show_incorrect_text?: false + ) + ) + end + # @tuple_children [ # parsec(:nested_attribute), # atom(), diff --git a/test/live_view_native/swiftui/rules_parser_test.exs b/test/live_view_native/swiftui/rules_parser_test.exs index e256103c9..452d0543d 100644 --- a/test/live_view_native/swiftui/rules_parser_test.exs +++ b/test/live_view_native/swiftui/rules_parser_test.exs @@ -1,5 +1,6 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do use ExUnit.Case + import ExUnit.CaptureIO alias LiveViewNative.SwiftUI.RulesParser def parse(input, opts \\ []) do @@ -7,6 +8,7 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do file: Keyword.get(opts, :file), module: Keyword.get(opts, :module), line: Keyword.get(opts, :line), + expect_semicolons?: Keyword.get(opts, :expect_semicolons?, false), context: %{ annotations: Keyword.get(opts, :annotations, false) } @@ -382,6 +384,7 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do input = ~s{rotationEffect(gesture_state(:rotate, .rotation, defaultValue: .zero))} output = {:rotationEffect, [], [{:__gesture_state__, [], [:rotate, {:., [], [nil, :rotation]}, [defaultValue: {:., [], [nil, :zero]}]]}]} + assert parse(input) == output end end @@ -454,6 +457,80 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do assert String.trim(error.description) == error_prefix end + test "warn when missing semicolons" do + input = "blue() red()" + + logs = + capture_io(:stderr, fn -> + assert parse(input, expect_semicolons?: true) + end) + + assert logs =~ + """ + warning:#{" "} + | + 1 | blue()‎ red() + | ^ + | + + Expected a ‘;’ + """ + + assert logs =~ + """ + warning:#{" "} + | + 1 | blue() red()‎ + | ^ + | + + Expected a ‘;’ + """ + + input = """ + blue() + red() + green() + """ + + logs = + capture_io(:stderr, fn -> + assert parse(input, expect_semicolons?: true) + end) + + assert logs =~ + """ + warning:#{" "} + | + 1 | blue()‎ + | ^ + | + + Expected a ‘;’ + """ + assert logs =~ + """ + warning:#{" "} + | + 2 | red()‎ + | ^ + | + + Expected a ‘;’ + """ + + assert logs =~ + """ + warning:#{" "} + | + 3 | green()‎ + | ^ + | + + Expected a ‘;’ + """ + end + test "invalid modifier name" do input = "1(.red)" From 5fe9a2275523954492d6995309afd3262036b955 Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Sun, 4 Aug 2024 22:59:37 +0300 Subject: [PATCH 2/8] Show error --- lib/live_view_native/swiftui/rules_parser.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/live_view_native/swiftui/rules_parser.ex b/lib/live_view_native/swiftui/rules_parser.ex index f16a5335a..f3b517191 100644 --- a/lib/live_view_native/swiftui/rules_parser.ex +++ b/lib/live_view_native/swiftui/rules_parser.ex @@ -11,6 +11,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser do line = Keyword.get(opts, :line) || 1 variable_context = Keyword.get(opts, :variable_context, Elixir) expect_semicolons? = Keyword.get(opts, :expect_semicolons?, false) + expect_semicolons? = true context = opts From 37cf4739af3e7fd3687172d0cc86df107bfbecef Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Thu, 8 Aug 2024 15:38:46 +0300 Subject: [PATCH 3/8] Update warnings --- lib/live_view_native/swiftui/rules_parser.ex | 1 - .../swiftui/rules_parser/parser/error.ex | 15 ++++++++++--- .../swiftui/rules_parser_test.exs | 22 +++++-------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/live_view_native/swiftui/rules_parser.ex b/lib/live_view_native/swiftui/rules_parser.ex index f3b517191..f16a5335a 100644 --- a/lib/live_view_native/swiftui/rules_parser.ex +++ b/lib/live_view_native/swiftui/rules_parser.ex @@ -11,7 +11,6 @@ defmodule LiveViewNative.SwiftUI.RulesParser do line = Keyword.get(opts, :line) || 1 variable_context = Keyword.get(opts, :variable_context, Elixir) expect_semicolons? = Keyword.get(opts, :expect_semicolons?, false) - expect_semicolons? = true context = opts diff --git a/lib/live_view_native/swiftui/rules_parser/parser/error.ex b/lib/live_view_native/swiftui/rules_parser/parser/error.ex index e0054d3fd..bb25394e0 100644 --- a/lib/live_view_native/swiftui/rules_parser/parser/error.ex +++ b/lib/live_view_native/swiftui/rules_parser/parser/error.ex @@ -140,18 +140,27 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Error do header = if error.is_warning? do - "" + "#{error_message}#{maybe_but_got}" else "Unsupported input:" end + footer = + if error.is_warning? do + "" + else + """ + + #{error_message}#{maybe_but_got} + """ + end + message = """ #{header} #{line_spacer} | #{lines} #{line_spacer} | - - #{error_message}#{maybe_but_got} + #{footer} """ {message, {source_line, 0}, error.byte_offset} diff --git a/test/live_view_native/swiftui/rules_parser_test.exs b/test/live_view_native/swiftui/rules_parser_test.exs index 452d0543d..e9418c249 100644 --- a/test/live_view_native/swiftui/rules_parser_test.exs +++ b/test/live_view_native/swiftui/rules_parser_test.exs @@ -32,7 +32,7 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do end test "parses modifier function definition with annotation (2)" do - {line, input} = {__ENV__.line,""" + {line, input} = {__ENV__.line + 1,""" font(.largeTitle) bold(true) italic(true) @@ -467,24 +467,20 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do assert logs =~ """ - warning:#{" "} + warning: Expected a ‘;’ | 1 | blue()‎ red() | ^ | - - Expected a ‘;’ """ assert logs =~ """ - warning:#{" "} + warning: Expected a ‘;’ | 1 | blue() red()‎ | ^ | - - Expected a ‘;’ """ input = """ @@ -500,34 +496,28 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do assert logs =~ """ - warning:#{" "} + warning: Expected a ‘;’ | 1 | blue()‎ | ^ | - - Expected a ‘;’ """ assert logs =~ """ - warning:#{" "} + warning: Expected a ‘;’ | 2 | red()‎ | ^ | - - Expected a ‘;’ """ assert logs =~ """ - warning:#{" "} + warning: Expected a ‘;’ | 3 | green()‎ | ^ | - - Expected a ‘;’ """ end From 06e7bf505257223cc55182c6aeb0d1814cd44a7a Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Thu, 8 Aug 2024 15:38:53 +0300 Subject: [PATCH 4/8] Update dependencies --- mix.exs | 3 +-- mix.lock | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 9e5774ade..d5ebe579f 100644 --- a/mix.exs +++ b/mix.exs @@ -54,8 +54,7 @@ defmodule LiveViewNative.SwiftUI.MixProject do {:makeup_json, "~> 0.1.0", only: [:docs, :test]}, {:makeup_eex, ">= 0.1.1"}, {:floki, ">= 0.30.0", only: :test}, - {:live_view_native, "~> 0.3.0-rc.3"}, - {:live_view_native_stylesheet, "~> 0.3.0-rc.3", only: :test}, + {:live_view_native_stylesheet, github: "liveview-native/live_view_native_stylesheet", branch: "main", only: :test}, {:live_view_native_test, github: "liveview-native/live_view_native_test", branch: "main", only: :test}, {:nimble_parsec, "~> 1.3"} ] diff --git a/mix.lock b/mix.lock index a876c30db..0f88b8da0 100644 --- a/mix.lock +++ b/mix.lock @@ -7,8 +7,8 @@ "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [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", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, "floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, - "live_view_native": {:hex, :live_view_native, "0.3.0-rc.3", "0d8519d35b4e4d4ffc1f9b417790cc67b51e07275581aba27e55fea5a4727650", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.20.10", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0.4", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.5", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.5", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "cfd30580073265358b66537340eb6e738718dc7c5778e6784c5c16e90ddc18b8"}, - "live_view_native_stylesheet": {:hex, :live_view_native_stylesheet, "0.3.0-rc.3", "7fbee1e1e28627652ece7ed43d4cf341cb4bfe8c7dca3c29ced67cb695c16a46", [:mix], [{:live_view_native, "~> 0.3.0-rc.3", [hex: :live_view_native, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e1f6afe1755c5b3999d943763d8e0436c27fbcd655814883d0213fae72d47cdf"}, + "live_view_native": {:git, "https://github.com/liveview-native/live_view_native.git", "0c9d98c1633c422ac8b90e6ca9bfee91d112973e", [branch: "main"]}, + "live_view_native_stylesheet": {:git, "https://github.com/liveview-native/live_view_native_stylesheet.git", "05639ca9bb530dc16bbd5dc65cffe3d8014c82c2", [branch: "main"]}, "live_view_native_test": {:git, "https://github.com/liveview-native/live_view_native_test.git", "539ae931fa3936f3ee2f73ffa11f7100fe6554db", [branch: "main"]}, "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, "makeup_eex": {:hex, :makeup_eex, "0.1.2", "93a5ef3d28ed753215dba2d59cb40408b37cccb4a8205e53ef9b5319a992b700", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.16 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_html, "~> 0.1.0 or ~> 1.0", [hex: :makeup_html, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "6140eafb28215ad7182282fd21d9aa6dcffbfbe0eb876283bc6b768a6c57b0c3"}, From 6f777484cc81ddeeda6eaf57dae28de7ac03640b Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Thu, 8 Aug 2024 15:42:37 +0300 Subject: [PATCH 5/8] Refactor --- lib/live_view_native/swiftui/rules_parser/parser/error.ex | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/live_view_native/swiftui/rules_parser/parser/error.ex b/lib/live_view_native/swiftui/rules_parser/parser/error.ex index bb25394e0..ed47d6ded 100644 --- a/lib/live_view_native/swiftui/rules_parser/parser/error.ex +++ b/lib/live_view_native/swiftui/rules_parser/parser/error.ex @@ -22,8 +22,6 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Error do error_message, opts \\ [] ) do - # IO.inspect({args, rest, error_message}, label: "error[0]") - error = %__MODULE__{ incorrect_text: List.first(args, ""), line: line, @@ -48,10 +46,10 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Error do # Never treat error as warning Context.put_new_error(context, rest, error) - warning -> + optional_warning_key -> # The error is an optional warning # Only log the warning if value in `context[]` is true - if get_in(context, [Access.key(warning)]) == true do + if get_in(context, [Access.key(optional_warning_key)]) == true do Context.put_new_error(context, rest, %{error | is_warning?: true}) else context From 771afcc54fee41ec6f55da87cfd6323a63f5acba Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Thu, 8 Aug 2024 15:45:33 +0300 Subject: [PATCH 6/8] Emit warnings in order of occurrence --- lib/live_view_native/swiftui/rules_parser.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/live_view_native/swiftui/rules_parser.ex b/lib/live_view_native/swiftui/rules_parser.ex index f16a5335a..b3678b495 100644 --- a/lib/live_view_native/swiftui/rules_parser.ex +++ b/lib/live_view_native/swiftui/rules_parser.ex @@ -55,7 +55,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser do end def log_warnings(warnings, file) do - for {message, {line, _}, _offset} <- warnings do + for {message, {line, _}, _offset} <- Enum.reverse(warnings) do IO.warn(message, line: line, file: file) end end From b17493bb10df84800888cd91716849a0ee6f0bf0 Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Thu, 8 Aug 2024 15:47:01 +0300 Subject: [PATCH 7/8] Restore `live_view_native` dependency definition --- mix.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/mix.exs b/mix.exs index d5ebe579f..0cbb2e7a3 100644 --- a/mix.exs +++ b/mix.exs @@ -54,6 +54,7 @@ defmodule LiveViewNative.SwiftUI.MixProject do {:makeup_json, "~> 0.1.0", only: [:docs, :test]}, {:makeup_eex, ">= 0.1.1"}, {:floki, ">= 0.30.0", only: :test}, + {:live_view_native, github: "liveview-native/live_view_native", branch: "main"}, {:live_view_native_stylesheet, github: "liveview-native/live_view_native_stylesheet", branch: "main", only: :test}, {:live_view_native_test, github: "liveview-native/live_view_native_test", branch: "main", only: :test}, {:nimble_parsec, "~> 1.3"} From 6129156c5d2a8403967524b21a82f3326dd51848 Mon Sep 17 00:00:00 2001 From: Nduati Kuria <012nkuria@gmail.com> Date: Fri, 9 Aug 2024 14:44:59 +0300 Subject: [PATCH 8/8] Trim warnings --- lib/live_view_native/swiftui/rules_parser/parser/error.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/live_view_native/swiftui/rules_parser/parser/error.ex b/lib/live_view_native/swiftui/rules_parser/parser/error.ex index ed47d6ded..7c75dfd04 100644 --- a/lib/live_view_native/swiftui/rules_parser/parser/error.ex +++ b/lib/live_view_native/swiftui/rules_parser/parser/error.ex @@ -161,6 +161,6 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Parser.Error do #{footer} """ - {message, {source_line, 0}, error.byte_offset} + {String.trim(message), {source_line, 0}, error.byte_offset} end end