profile
viewpoint
Paul Statezny paulstatezny @ucbi Phoenix, AZ https://paulstat.com I'm a software developer specializing in full-stack web development.

paulstatezny/elm-local-storage-ports 18

Generic Elm ports for interacting with LocalStorage

paulstatezny/decisive 9

The elegant, free Eisenhower Matrix app

paulstatezny/elm-phoenix-websocket-ports 9

Generic Elm ports for interacting with the Phoenix framework via websocket

paulstatezny/elm-dom-ports 5

Generic Elm ports for interacting with the DOM

paulstatezny/live-view-back-button 2

Testing out using the back button with Phoenix LiveView

paulstatezny/angular-decisive 1

The elegant, free Eisenhower Matrix app

paulstatezny/angular-dry-scope 1

Bringing functional UI paradigms to Angular 1.

paulstatezny/elm-router 1

Create a website with many small Elm applications, powered by reusable Elm ports from NPM.

mattludwigs/lunch-and-learn-reason-todo 0

Practice app to learn ReasonML and ReasonReact with a lunch crew

paulstatezny/advent-of-code-2017 0

Solutions to exercises from http://adventofcode.com/2017

issue commentsurface-ui/surface_formatter

Interoperability with other Formatter Plugins

@maennchen I haven't communicated with anyone myself at this point. Would you be willing to initiate a conversation about it? 🙂

maennchen

comment created time in 4 days

issue commentsurface-ui/surface_formatter

Interoperability with other Formatter Plugins

@maennchen This seems like it might be a missing feature in Elixir 1.13's Formatter Plugins. 🤔

Feels odd that it would be the responsibility of a specialized formatter to be aware of other formatters.

maennchen

comment created time in 14 days

issue commentsurface-ui/surface_formatter

Formatter indents lines further on every run

Thanks for reporting this @maennchen , I'll take a look!

maennchen

comment created time in 14 days

pull request commentsurface-ui/surface

keep single line and empty inputs intact

Thanks for your contribution @rubysolo !

rubysolo

comment created time in 18 days

PullRequestReviewEvent

push eventsurface-ui/surface_formatter

Solomon White

commit sha fa289425933a1e421d9ad5c633048bff32c103d7

keep single-line and empty inputs intact

view details

Solomon White

commit sha 7dd3f4eb49bd8334fe4848b4e3edf3411dc36f1e

improve trailing newline detection and rename option

view details

Solomon White

commit sha 2e2537db2962c030b291d7fb557e1d0b5dc1e934

refactor to simpler code

view details

Paul Statezny

commit sha 424cc78c299a0e98d0aeeaca5f6c1cfad855be84

Merge pull request #57 from rubysolo/single-line-inputs

view details

push time in 18 days

PR merged surface-ui/surface_formatter

keep single-line and empty inputs intact

Currently, the formatter unconditionally adds a final newline to the formatted nodes, which breaks empty and single-line inputs.

Empty example:

# input
  def render(assigns) do
    ~F"""
    """
  end

# expected output -- no change from input

# actual output (extra newline inserted)
  def render(assigns) do
    ~F"""

    """
  end

Single-line example:

# input
  def render(assigns) do
    ~F{<CheckmarkIcon />}
  end

# expected output -- no change from input

# actual output (extra newline inserted)
  def render(assigns) do
    ~F{<CheckmarkIcon />
}
  end

This PR fixes both of the above cases.

+41 -6

1 comment

3 changed files

rubysolo

pr closed time in 18 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentsurface-ui/surface_formatter

keep single-line and empty inputs intact

 defmodule Surface.Formatter.Phases.FinalNewline do-  @moduledoc "Add a newline after all of the nodes"+  @moduledoc "Add a newline after all of the nodes if one was present on the original input"    @behaviour Surface.Formatter.Phase -  def run(nodes, _opts) do-    nodes ++ [:newline]+  # special case for empty heredocs+  def run([:indent], _opts), do: []++  def run(nodes, opts) do+    suffix =+      opts+      |> Keyword.get(:trailing_newline_on_input, false)+      |> final_newline()++    nodes ++ suffix   end++  defp final_newline(true), do: [:newline]+  defp final_newline(_), do: []

This wouldn't materially change the code, but I'm thinking something like this would be clearer/cleaner.

  def run(nodes, opts) do
    if Keyword.get(opts, :trailing_newline_on_input) do
      nodes ++ [:newline]
    else
      nodes
    end
  end

What do you think?

rubysolo

comment created time in 18 days

PullRequestReviewEvent

Pull request review commentsurface-ui/surface_formatter

keep single-line and empty inputs intact

 defmodule Surface.Formatter do   """   @spec format_string!(String.t(), list(option)) :: String.t()   def format_string!(string, opts \\ []) do+    trailing_whitespace =+      case Regex.run(~r/\s+$/, string) do

I think we want to check if there's a trailing newline, not just any trailing whitespace.

In the current form, this:

~F{<div />    }

would be formatted as this:

~F{<div />
}

But if we change the regex as such:

    trailing_newline =
      case Regex.run(~r/\n\s+$/, string) do

then it will be formatted as

~F{<div />}

which I think makes more sense. What do you think?

rubysolo

comment created time in 18 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentsurface-ui/surface_formatter

keep single-line and empty inputs intact

 defmodule Surface.Formatter do   """   @spec format_string!(String.t(), list(option)) :: String.t()   def format_string!(string, opts \\ []) do+    trailing_whitespace =+      case Regex.run(~r/\s+$/, string) do+        [match] -> match+        nil -> nil+      end+     parsed =       string       |> String.trim()       |> Surface.Compiler.Parser.parse!(translator: Surface.Formatter.NodeTranslator) -    # Ensure the :indent option is set-    opts = Keyword.put_new(opts, :indent, 0)+    # Ensure the :indent and :trailing_newline_on_input options are set+    opts =+      opts+      |> Keyword.put_new(:indent, 0)+      |> Keyword.put_new(:trailing_newline_on_input, !is_nil(trailing_whitespace))

Can we call this :trailing_newline for brevity? Also, I think we want Keyword.put, not Keyword.put_new.

I don't think we want them to be able to pass this option. I think it should be an internal-only opt.

     |> Keyword.put(:trailing_newline, !is_nil(trailing_whitespace))
rubysolo

comment created time in 18 days

create barnchpaulstatezny/credo

branch : sigils-with-triple-quotes

created branch time in 22 days

delete branch paulstatezny/credo

delete branch : sigils-with-triple-quotes

delete time in a month

issue commentsurface-ui/surface_formatter

non-self-closable HTML tags are formatted to become self-closed tags

@ndac-todoroki Excellent! No trouble at all; thank you for raising the issue. Now we've double checked and ruled out that this could be a problem. 🙂

ndac-todoroki

comment created time in a month

issue commentsurface-ui/surface_formatter

non-self-closable HTML tags are formatted to become self-closed tags

For reference, here's the test that demonstrates that this is an intentional design choice. (It uses a component, but applies to HTML elements for the reasons described above.)

https://github.com/surface-ui/surface_formatter/blob/v0.7.4/test/surface/formatter_test.exs#L404-L418

ndac-todoroki

comment created time in a month

issue commentsurface-ui/surface_formatter

non-self-closable HTML tags are formatted to become self-closed tags

@ndac-todoroki Thanks for opening an issue!

Unless I'm mistaken, Surface/LiveView will render <div></div> if your Surface code is <div />.

Therefore, HTML tags with no contents can be collapsed in Surface code into a single self-closed ("void") element, and they will emit the same exact HTML. This is why the formatter chooses to make those tags self-closing.

ndac-todoroki

comment created time in a month

pull request commentsurface-ui/surface_formatter

keep single-line and empty inputs intact

Hi @rubysolo! Thanks for contributing this PR.

As you've probably guessed, this is a known behavior and hasn't been a priority to change yet. But I think your suggestion makes sense.

Give me a few days to review the code and think about it. Thanks again!

rubysolo

comment created time in a month

pull request commentrrrene/credo

Detect end of ~A""" style sigils correctly when searching for config comments

I see that 4 of 5 CI runs failed, but it appears unrelated to this PR. (Perhaps they failed on master when I branched?)

Let me k ow if you want me to do anything to remedy this @rrrene. Thanks again!

paulstatezny

comment created time in a month

pull request commentsurface-ui/surface

Merge bugfixes from surface_formatter 0.7.3 and 0.7.4

I added a commit with a patch from v0.7.4. The problem scenario is described here. Thanks @maennchen!

paulstatezny

comment created time in a month

issue commentsurface-ui/surface_formatter

FunctionClauseError in Surface.Formatter.Phases.Render.quoted_strings_with_newlines/1

Patched and released in v0.7.4.

@maennchen Thanks for making this quick and easy with all of the information and links you provided. 🤝 It was very helpful that Hygeia is open source as I was able to pull it and test the fix directly. 🙂 🚀

maennchen

comment created time in a month

push eventsurface-ui/surface

Paul Statezny

commit sha ec59deab3c2d347186e7546aef4812e4f2fc19d4

Handle arbitrary expressions when checking for newlines in strings

view details

push time in a month

created tagsurface-ui/surface_formatter

tagv0.7.4

created time in a month

push eventsurface-ui/surface_formatter

Paul Statezny

commit sha d59f7189144335d43f87d3f547fc3411bcba2713

v0.7.4

view details

push time in a month

delete branch surface-ui/surface_formatter

delete branch : 55-arbitrary-code-in-expressions

delete time in a month

push eventsurface-ui/surface_formatter

Paul Statezny

commit sha a3e11d67be5cafdd017ea4db6afd836523fc62d9

#55: Handle arbitrary expressions when checking for newlines in strings

view details

Paul Statezny

commit sha 0256267262150404b9a3e4748323d29a6b7ca5ba

Merge pull request #56 from surface-ui/55-arbitrary-code-in-expressions Handle arbitrary expressions when checking for newlines in strings

view details

push time in a month

more