prettier / prettier/plugin-php

Improper body indentation for split inline tags

Open
#1,668 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied PHP input with the listed Prettier and PHP plugin configuration, then trace how split inline tags and their embedded expressions are formatted. Done means the split expressions use consistent indentation, with the chosen behavior covered by a regression case for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.