synchronal / pages

MIT License
9 stars 1 forks source link

typespec issues with attr, data, text, and tid functions in Pages.Html #1

Closed eahanson closed 2 years ago

eahanson commented 2 years ago

The attr, data, text, and tid functions' typespecs specify binary() | [binary()] as return values which causes dialyzer to fail sometimes.

I like the scoping feature; here's a possible solution: have :all be the default scope, and only send the scope option when it is :first or :first!:

@spec attr(html(), attr(), query()) :: [binary()]
def attr(html, attr, query), do: # returns all

@spec attr(html(), attr(), scope(), query()) :: binary()
def attr(html, attr, scope, query) when scope in [:first, :first!], do: # returns the first

(This would be a breaking change.)

Relatedly, we might want to update the fun() typespec on find so that it specifies a list as output. (I think that would be (Floki.html_tree() -> [binary()]).)

sax commented 2 years ago

This seems no longer relevant, because there are separate functions, and they have moved to https://github.com/synchronal/html_query