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: 🐛 unnecessary indent in raw php directive #874

Merged
merged 2 commits into from
Oct 9, 2023
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
2 changes: 1 addition & 1 deletion __tests__/fixtures/formatted.raw_php_block.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@foreach ($users as $user)
@php
$users = $_GET;

foreach ($users as $key1 => $value) {
if (is_array($value)) {
foreach ($value as $key2 => $value2) {
Expand Down
26 changes: 26 additions & 0 deletions __tests__/fixtures/snapshots/php_block_directive.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
------------------------------------options----------------------------------------
{}
------------------------------------content----------------------------------------
@php
use Eagle\Utilities\Dates\TimeZone;
// assert blank line will not be indented

$timezone_options =
['' => ''] +
TimeZone::create()
->format('tz-label')
->countryCodePriority('US')
->get();
@endphp
------------------------------------expected----------------------------------------
@php
use Eagle\Utilities\Dates\TimeZone;
// assert blank line will not be indented

$timezone_options =
['' => ''] +
TimeZone::create()
->format('tz-label')
->countryCodePriority('US')
->get();
@endphp
4 changes: 4 additions & 0 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { sortClasses } from '@shufo/tailwindcss-class-sorter';
import Aigle from 'aigle';
import detectIndent from 'detect-indent';

Check failure on line 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 5 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 5 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 5 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 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.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 5 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 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.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 5 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 { sortAttributes } from 'html-attribute-sorter';
import beautify, { JSBeautifyOptions } from 'js-beautify';

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

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

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

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

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

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

Check failure on line 7 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/js-beautify/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 7 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/js-beautify/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 7 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/js-beautify/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

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

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

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

Check failure on line 7 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/js-beautify/index"' can only be default-imported using the 'esModuleInterop' flag

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

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

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

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

Check failure on line 7 in src/formatter.ts

View workflow job for this annotation

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

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

Check failure on line 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 8 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 8 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 8 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 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.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 8 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 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.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 8 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.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 xregexp from 'xregexp';
import { formatPhpComment } from './comment';
Expand Down Expand Up @@ -37,25 +37,25 @@
import * as vsctm from './vsctm';

export default class Formatter {
argumentCheck: any;

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 40 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

bladeBraces: any;

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 42 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

bladeComments: any;

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 44 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

bladeDirectives: any;

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 46 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

htmlAttributes: Array<string>;

currentIndentLevel: number;

diffs: any;

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 52 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

indentCharacter: any;

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

indentSize: any;

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 56 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

inlineDirectives: any;

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

Check warning on line 58 in src/formatter.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected any. Specify a different type

conditions: any;

Expand Down Expand Up @@ -1357,6 +1357,10 @@
return prefixForEnd + line;
}

if (line.length === 0) {
return line;
}

return prefix + line;
})
.join('\n')
Expand Down
Loading