We were doing this in most places thanks to this change in eslint-config-liferay, but there were a few places where we didn't enforce blank lines because ESLint and Prettier disagree about comments at the beginning and end of blocks, classes, arrays, objects etc.
Brian would like us to handle those "few places" too, so after thinking about it for a bit, I realized that it is actually quite easy because:
We already have this post-Prettier hook in place in liferay-npm-scripts that allows us to override Prettier if needed.
We don't need to make a custom lint rule for it; we can just use the existing "lines-around-comment" rule that ESLint provides, appropriately configured.
This doesn't fundamentally undermine the main mission of Prettier, which is to wrap lines, because inserting/removing blank lines never changes line width.
I'm feeling pretty lucky that I used all those crazy Unicode sentinels when I implemented JSP formatting, because it means that we can ignore all the temporary placeholder comments that get inserted into the source code so that Prettier can parse it. eg.
and when we round-trip back to JSP again, it would be:
<c:if test="<% blah() %>">
stuff();
</c:if>
which is obviously not what we want. Luckily for us, we can configure ESLint to ignore the "crazy Unicode stuff", and that means we don't mangle any of our JSP.
Test plan: Run on liferay-portal, producing this diff.
This is a relatively simple change and as you can see in the test plan, works fine in liferay-portal, so I'm just going to merge it, now that CI is green.
We were doing this in most places thanks to this change in eslint-config-liferay, but there were a few places where we didn't enforce blank lines because ESLint and Prettier disagree about comments at the beginning and end of blocks, classes, arrays, objects etc.
Brian would like us to handle those "few places" too, so after thinking about it for a bit, I realized that it is actually quite easy because:
I'm feeling pretty lucky that I used all those crazy Unicode sentinels when I implemented JSP formatting, because it means that we can ignore all the temporary placeholder comments that get inserted into the source code so that Prettier can parse it. eg.
gets transformed into (something like):
to make it into valid JS. Now, with this change, Prettier + ESLint would want to inject blank lines:
and when we round-trip back to JSP again, it would be:
which is obviously not what we want. Luckily for us, we can configure ESLint to ignore the "crazy Unicode stuff", and that means we don't mangle any of our JSP.
Test plan: Run on liferay-portal, producing this diff.
Closes: https://github.com/liferay/liferay-npm-tools/issues/444