Skip to content

Commit 1f304a5

Browse files
authored
Merge pull request #916 from claytonrcarter/fix-php-block-indentation
2 parents 0678078 + 470f503 commit 1f304a5

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

__tests__/formatter.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5417,4 +5417,54 @@ describe('formatter', () => {
54175417

54185418
await util.doubleFormatCheck(content, expected);
54195419
});
5420+
5421+
test('@php blocks respect indent level for deeply indented code (issue #915)', async () => {
5422+
let content = [
5423+
'<div>',
5424+
'<div>',
5425+
'<div>',
5426+
'<div>',
5427+
'<div>',
5428+
'<div>',
5429+
'@php',
5430+
"$percent = $item['historical'] ?? null ? round((100 * ($item['today'] - $item['historical'])) / $item['historical']) : null;",
5431+
'',
5432+
"$color = $percent < 0 ? '#8b0000' : '#006400';",
5433+
'@endphp',
5434+
'</div>',
5435+
'</div>',
5436+
'</div>',
5437+
'</div>',
5438+
'</div>',
5439+
'</div>',
5440+
].join('\n');
5441+
5442+
// this is slightly different than the code presented in #915 because that
5443+
// code was wrapped to 80 columns, but these tests all use 120
5444+
let expected = [
5445+
'<div>',
5446+
' <div>',
5447+
' <div>',
5448+
' <div>',
5449+
' <div>',
5450+
' <div>',
5451+
' @php',
5452+
' $percent =',
5453+
" $item['historical'] ?? null",
5454+
" ? round((100 * ($item['today'] - $item['historical'])) / $item['historical'])",
5455+
' : null;',
5456+
'',
5457+
" $color = $percent < 0 ? '#8b0000' : '#006400';",
5458+
' @endphp',
5459+
' </div>',
5460+
' </div>',
5461+
' </div>',
5462+
' </div>',
5463+
' </div>',
5464+
'</div>',
5465+
``,
5466+
].join('\n');
5467+
5468+
await util.doubleFormatCheck(content, expected);
5469+
});
54205470
});

src/formatter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,7 @@ export default class Formatter {
13011301
} else if (isMultipleStatements) {
13021302
// multiple statments on mult lines
13031303

1304-
const indentLevel = (indent.amount + 1) * this.indentSize;
1305-
1304+
const indentLevel = indent.amount + this.indentSize;
13061305
rawBlock = (
13071306
await util.formatStringAsPhp(`<?php${rawBlock}?>`, {
13081307
...this.options,

0 commit comments

Comments
 (0)