msaraiva / exsamples Goto Github PK
View Code? Open in Web Editor NEWInitializes lists of maps, structs or keyword lists using tabular data in Elixir
License: MIT License
Initializes lists of maps, structs or keyword lists using tabular data in Elixir
License: MIT License
The following code:
samples do
:id | :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
1 | "Brazil" | "Real (BRL)" | "Portuguese" | 204451000 | 7.70 | "South America" | "Football" | ~D["1822-09-07"]
end
is formatted like this:
samples do
:id | :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
1
| "Brazil"
| "Real (BRL)"
| "Portuguese"
| 204_451_000
| 7.70
| "South America"
| "Football"
| ~D["1822-09-07"]
end
Here is a test that reproduce the error
test "very long table" do
code = """
samples do
:id | :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
1 | "Brazil" | "Real (BRL)" | "Portuguese" | 204451000 | 7.70 | "South America" | "Football" | ~D["1822-09-07"]
end
"""
assert Samples.FormatterPlugin.format(code, []) == """
samples do
:id | :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
1 | "Brazil" | "Real (BRL)" | "Portuguese" | 204_451_000 | 7.70 | "South America" | "Football" | ~D["1822-09-07"]
end
"""
end
I am suspecting the line_length
to be the cause of this behaviour.
I believe we should override the line_length
to properly render the table. WDYT? ping @msaraiva
I am using this stuff to functionally test api endpoints, and keys there are always strings and not atoms.
Right now I have to Enum.into every sample I use.
Formatting the following code
samples do
:fuel_type | :co2 | :year | :percentage
# 2020
:diesel | 105 | 2020 | 0.069
end
Will result in:
samples do
:fuel_type | :co2 | :year | :percentage
# 2020----
:diesel | 105 | 2020 | 0.069
end
WIth 4 whitespaces after # 2020
. I represented them with -
Here is a test that reproduces the bug:
test "handle comments" do
code = """
samples do
:fuel_type | :co2 | :year | :percentage
# 2020
:diesel | 105 | 2020 | 0.069
:petrol | 110 | 2020 | 0.054
end
"""
assert Samples.FormatterPlugin.format(code, []) == """
samples do
:fuel_type | :co2 | :year | :percentage
# 2020
:diesel | 105 | 2020 | 0.069
:petrol | 110 | 2020 | 0.054
end
"""
end
This is due to the offset we add to the first column
exsamples/lib/formatter_plugin.ex
Lines 122 to 124 in 3722216
A solution could be to pattern match on #
in the walk
function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.