Skip to content

Commit

Permalink
fix: 🐛 tab indent is not used in inline directive
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Aug 7, 2022
1 parent 6211924 commit b212293
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
53 changes: 53 additions & 0 deletions __tests__/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4284,4 +4284,57 @@ describe('formatter', () => {

await util.doubleFormatCheck(content, expected, { sortHtmlAttributes: 'idiomatic' });
});

test('it should use tab for indent inside inline directive', async () => {
const content = [
`<div>`,
` <div>`,
` <div @class([`,
` 'some class',`,
` 'some other class',`,
` 'another class',`,
` 'some class',`,
` 'some other class',`,
` 'another class',`,
` ])></div>`,
` </div>`,
`</div>`,
].join('\n');

const expected = [
`<div>`,
` <div>`,
` <div @class([`,
` 'some class',`,
` 'some other class',`,
` 'another class',`,
` 'some class',`,
` 'some other class',`,
` 'another class',`,
` ])></div>`,
` </div>`,
`</div>`,
``,
].join('\n');

await util.doubleFormatCheck(content, expected, { useTabs: true, indentSize: 1 });

const expected2 = [
`<div>`,
` <div>`,
` <div @class([`,
` 'some class',`,
` 'some other class',`,
` 'another class',`,
` 'some class',`,
` 'some other class',`,
` 'another class',`,
` ])></div>`,
` </div>`,
`</div>`,
``,
].join('\n');

await util.doubleFormatCheck(content, expected2, { useTabs: true, indentSize: 2 });
});
});
6 changes: 5 additions & 1 deletion src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,12 +1583,16 @@ export default class Formatter {
wrapLength = this.wrapLineLength - `func`.length - p1.length - indent.amount;
}

const inside = util
let inside = util
.formatRawStringAsPhp(`func(${p4})`, wrapLength, true)
.replace(/([\n\s]*)->([\n\s]*)/gs, '->')
.replace(/,(\s*?\))/gis, (_match5, p5) => p5)
.trim();

if (this.options.useTabs || false) {
inside = _.replace(inside, new RegExp(`(?<=^ *) `, 'gm'), '\t'.repeat(this.indentSize));
}

if (this.isInline(inside)) {
return `${this.indentRawPhpBlock(indent, `${inside}`)
.replace(/func\((.*)\)/gis, (match: string, p5: string) => p5)
Expand Down

0 comments on commit b212293

Please sign in to comment.