Hi there. Got a new one for you. This was introduced sometime in the past ~ month (after the bleeding edge release that was active around June 12).
This example is a bit long, but there are various different changes within it that affect indentation in different ways, so I was unable to easily simplify it down any further. My hope is that you can debug the formatter and find possibly multiple errors by making the changes suggested in the code itself.
<?php
function example() {
if (true) { // removing this wrapping "if" statement reduces the error-indent by one
function foo() {
if (true) {
?>
<!--
removing lines from the end-php directly above to the start-php directly
below causes indentation to be fixed
-->
<?php
}
}
function bar() {
?>
<div class="top">
<div class="second">
<div class="third">
<div class="fourth">
<a href="<?php echo "removing this php block fixes indentation but only up to the next start php block"; ?>"
target="_blank"
class="lots of classes because tailwind lol which forces this line to wrap when auto formatting">
</a>
</div><!--fourth-->
<?php if (true): ?>
<!-- removing the if-block fixes indentation for this div stack -->
<?php endif; ?>
</div><!--third-->
</div><!--second-->
<?php
// removing this php block reduces the "erroneous" indent by one tab
include_once(__DIR__ . '/file.php');
?>
<script type="text/javascript">
(function ($) {
$(".class").click(function (event) {
var id = <?php echo "removing this php block fixes indentation for the script"; ?>;
doSomething(id);
});
})(jQuery);
</script>
</div><!--top-->
<?php
}
}
}
If you've been curious how I'm hitting all these messy cases, it's in the process of cleaning up a large code base that's written like this 😅. The auto-formatting has been a godsend for reviewing the diffs as I slowly improve things, but when updates cause things like this it has the opposite effect 🙁
(often times, once I'm able to track down which lines affect the auto-formatter adversely, I'm able to tweak them to work around the problem, but I report it so that you can improve the extension. That happens to be the case here; instead of the giant if (true) { /* a bunch of stuff */ }
blocks, I was able to use early returns: if (false) return;