Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 unexpected indent on break directive inside if directive #977

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/formatter/builtin-directives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,4 +867,12 @@ describe("formatter builtin directives test", () => {
sortHtmlAttributes: "idiomatic",
});
});

test("@if-@break structure", async () => {
const content = ["@if ($user)", " @break", "@endif"].join("\n");

const expected = ["@if ($user)", " @break", "@endif", ""].join("\n");

await util.doubleFormatCheck(content, expected);
});
});
7 changes: 7 additions & 0 deletions src/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable class-methods-use-this */

import detectIndent from "detect-indent";

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Module '"/Users/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 3 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Module '"D:/a/blade-formatter/blade-formatter/node_modules/detect-indent/index"' can only be default-imported using the 'esModuleInterop' flag
import _ from "lodash";

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Module '"/Users/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"/home/runner/work/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 4 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Module '"D:/a/blade-formatter/blade-formatter/node_modules/@types/lodash/index"' can only be default-imported using the 'esModuleInterop' flag
import * as vscodeTmModule from "vscode-textmate";
import constants from "./constants";
Expand Down Expand Up @@ -127,6 +127,13 @@
return;
}

// if @break is inside @if, decrement indent after @break
if (_.last(this.stack) === "@if" && token === "@break") {
this.shouldBeIndent = false;

return;
}

if (_.includes(phpKeywordEndTokens, token)) {
if (token === "@break") {
this.decrementIndentLevel();
Expand Down Expand Up @@ -254,7 +261,7 @@
)
) {
this.argumentCheck = {
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unused '@ts-expect-error' directive.

Check failure on line 264 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unused '@ts-expect-error' directive.
unindentOn: optionalStartWithoutEndTokens[token.toLowerCase()],
stack: [],
inString: false,
Expand Down
Loading