plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Improper body indentation for split inline tags

Open ncovercash opened this issue 3 years ago • 1 comments

Prettier 2.2.1

PHP Plugin 0.16.1

{
	"printWidth": 100,
	"useTabs": true,
	"semi": true,
	"quoteProps": "consistent",
	"trailingComma": "all",
	"phpVersion": "7.4",
	"braceStyle": "1tbs"
}

Input:

<div>
	<p> some html </p>
	<div>
		<p>some more html with an inline element <?= htmlspecialchars("test") ?> and another inline element <?= htmlspecialchars("test") ?> with even more <?= htmlspecialchars("test") ?></p>
	</div>
</div>

Output:

<div>
	<p> some html </p>
	<div>
		<p>some more html with an inline element <?= htmlspecialchars(
  	"test",
  ) ?> and another inline element <?= htmlspecialchars(
 	"test",
 ) ?> with even more <?= htmlspecialchars("test") ?></p>
	</div>
</div>

Expected behavior:

This is an issue of opinion so there are multiple solutions here, however, I think everyone would agree that all the parts should be indented the same (or at least identically).

image

The two htmlspecialchars that got split have different amounts of indentation on their closing parenthesis. Additionally, I would argue that the entire block should be indented the same, even if it produced something weird like:

		<p>some more html with an inline element <?= htmlspecialchars(
		  	"test",
		) ?> and another inline element <?= htmlspecialchars(
		 	"test",
		) ?> with even more <?= htmlspecialchars("test") ?></p>

(which is weird HTML with the <p> being on the same line of a multi-line body, however, this is a PHP prettier plugin, not HTML).

ncovercash avatar Mar 15 '21 02:03 ncovercash

I noticed that same with Prettier 2.7.1 and Prettier PHP 0.18.9: It looks to me as if the spaces added at the beginning of each line should actually be tabs. Indentation works correctly with spaces enabled instead of tabs.

nilshoerrmann avatar Jul 18 '22 15:07 nilshoerrmann