Comments (1)
We are seeing the same thing in our project, and I believe I've tracked it down to a mismatch in expected return types in this try/catch block:
prettier-plugin-erb/lib/formatter.js
Lines 19 to 26 in 613fc24
What happens is embedTextToDoc(...)
returns a string instead of a Doc
, so the formattedExpression.parts.pop()
always fails. However the `formattedExpression variable has now been overwritten.
In the case where embedTextToDoc
added line breaks to a long line, this leads to a mismatch between formattedExpression
and expression
; formattedExpression
is a multi-line expression, but expression
is not, so indentedLines
ends up as a single element array in this block:
prettier-plugin-erb/lib/formatter.js
Lines 28 to 44 in 613fc24
That leads to an empty spacesNumber
array, a call to Math.min() //=> Infinity
and the error seen above.
Here's an expression that can be used to trigger that behaviour:
<%= call_a_method :any_method, "it really does not matter which one", as_long_as(the_line: "is very very long"), it_will: "fail" %>
As for fixing it, replacing line 22 with formattedExpression = formattedExpression.trim()
works for me.
from prettier-plugin-erb.
Related Issues (20)
- Incorrect treatment of <%== %> in html.erb files
- Migrate to Prettier v3 HOT 3
- Ruby not formatted if it opens a block
- Please consider marking this library as deprecated HOT 2
- Fails to parse an erb multiline comment with quotes inside HOT 1
- Enabling formatOnSave for VS Code HOT 5
- Should exit with non-zero status on error
- Multiline-comment lines containing a colon are indented with each formatter run HOT 2
- Weird formatting on <i> tags with ERB (e.g. used for icons) HOT 3
- Invalid erb output for long blocks HOT 2
- Issues with leading dash in embedded ruby block HOT 2
- Why add whitespace between % and # in comments? HOT 2
- Ruby expressions are getting replaced with <eext> HOT 16
- Handle 2.3 prettier changes HOT 6
- render tag <%=%> replaced with [object Object] when used in img tag HOT 16
- Support file extension .html+*.erb for rails and viewcomponent variants
- <% %> Delete HOT 7
- TypeError: formattedExpression.trim is not a function HOT 9
- Incorrect output </eext8><br/> HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-plugin-erb.