Skip to content

Commit

Permalink
feat: 🎸 option wrapAttributesMinAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Dec 31, 2023
1 parent 1ef2c7c commit 114c2ba
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
],
"markdownDescription": "The way to wrap attributes"
},
"bladeFormatter.format.wrapAttributesMinAttrs": {
"type": "number",
"default": 2,
"markdownDescription": "Minimum number of html tag attributes for force wrap attribute options. Wrap the first attribute only if `force-expand-multiline` is specified in wrap attributes"
},
"bladeFormatter.format.useTabs": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function activate(context: ExtensionContext) {
indentSize: extConfig.indentSize,
wrapLineLength: extConfig.wrapLineLength,
wrapAttributes: extConfig.wrapAttributes,
wrapAttributesMinAttrs: extConfig.wrapAttributesMinAttrs,
useTabs: extConfig.useTabs,
sortTailwindcssClasses: extConfig.sortTailwindcssClasses,
sortHtmlAttributes: extConfig.sortHtmlAttributes ?? "none",
Expand Down
2 changes: 2 additions & 0 deletions src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface RuntimeConfig {
indentSize?: number;
wrapLineLength?: number;
wrapAttributes?: WrapAttributes;
wrapAttributesMinAttrs?: number;
endWithNewline?: boolean;
useTabs?: boolean;
sortTailwindcssClasses?: boolean;
Expand Down Expand Up @@ -54,6 +55,7 @@ export function readRuntimeConfig(filePath: string): RuntimeConfig | undefined {
"preserve-aligned",
],
},
wrapAttributesMinAttrs: { type: "int32" },
endWithNewline: { type: "boolean" },
useTabs: { type: "boolean" },
sortTailwindcssClasses: { type: "boolean" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"wrapAttributesMinAttrs": 0,
"wrapAttributes": "force-expand-multiline"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@extends('frontend.layouts.app')
@section('head')
@endsection
@section('title') foo
@endsection
@section('content')
<section
id="content"
>
<div
class="container mod-users-pd-h"
>
<div
class="pf-user-header"
>
<div></div>
<p>@lang('users.index')</p>
</div>
<div
class="pf-users-branch"
>
<ul
class="pf-users-branch__list"
>
@foreach ($tree as $users)
<li>
<img
src="{{ asset('img/frontend/icon/branch-arrow.svg') }}"
alt="branch_arrow"
>
{{ link_to_route('frontend.users.user.show', $users['name'], $users['_id']) }}
</li>
@endforeach
</ul>
<div
class="pf-users-branch__btn"
>
@can('create', App\Models\User::class)
{!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!}
@endcan
</div>
</div>
</div>
</section>
@endsection
@section('footer')
@stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@extends('frontend.layouts.app')
@section('head')
@endsection
@section('title') foo
@endsection
@section('content')
<section id="content">
<div class="container mod-users-pd-h">
<div class="pf-user-header">
<div></div>
<p>@lang('users.index')</p>
</div>
<div class="pf-users-branch">
<ul class="pf-users-branch__list">
@foreach($tree as $users)
<li>
<img src="{{ asset("img/frontend/icon/branch-arrow.svg") }}" alt="branch_arrow">
{{ link_to_route('frontend.users.user.show',$users["name"],$users['_id']) }}
</li>
@endforeach
</ul>
<div class="pf-users-branch__btn">
@can('create', App\Models\User::class)
{!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!}
@endcan
</div>
</div>
</div>
</section>
@endsection
@section('footer')
@stop

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@extends('frontend.layouts.app')
@section('head')
@endsection
@section('title') foo
@endsection
@section('content')
<section
id="content"
>
<div
class="container mod-users-pd-h"
>
<div
class="pf-user-header"
>
<div></div>
<p>@lang('users.index')</p>
</div>
<div
class="pf-users-branch"
>
<ul
class="pf-users-branch__list"
>
@foreach ($tree as $users)
<li>
<img
src="{{ asset('img/frontend/icon/branch-arrow.svg') }}"
alt="branch_arrow"
>
{{ link_to_route('frontend.users.user.show', $users['name'], $users['_id']) }}
</li>
@endforeach
</ul>
<div
class="pf-users-branch__btn"
>
@can('create', App\Models\User::class)
{!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!}
@endcan
</div>
</div>
</div>
</section>
@endsection
@section('footer')
@stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@extends('frontend.layouts.app')
@section('head')
@endsection
@section('title') foo
@endsection
@section('content')
<section id="content">
<div class="container mod-users-pd-h">
<div class="pf-user-header">
<div></div>
<p>@lang('users.index')</p>
</div>
<div class="pf-users-branch">
<ul class="pf-users-branch__list">
@foreach($tree as $users)
<li>
<img src="{{ asset("img/frontend/icon/branch-arrow.svg") }}" alt="branch_arrow">
{{ link_to_route('frontend.users.user.show',$users["name"],$users['_id']) }}
</li>
@endforeach
</ul>
<div class="pf-users-branch__btn">
@can('create', App\Models\User::class)
{!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!}
@endcan
</div>
</div>
</div>
</section>
@endsection
@section('footer')
@stop

33 changes: 33 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ suite("Extension Test Suite", () => {
);
});

test("Should format file with runtime config / wrapAttributesMinAttrs", async function (this: any) {
this.timeout(20000);
await formatSameAsBladeFormatter(
"withConfig/wrapAttributesMinAttrs/index.blade.php",
"withConfig/wrapAttributesMinAttrs/formatted.index.blade.php",
);
});

test("Should format file without runtime config / wrapAttributesMinAttrs", async function (this: any) {
this.timeout(20000);

const config = vscode.workspace.getConfiguration(
"bladeFormatter.format",
);
await config.update("sortHtmlAttributes", "custom", true);
await config.update(
"wrapAttributesMinAttrs",
0,
true,
);
await config.update(
"wrapAttributes",
"force-expand-multiline",
true,
);

await formatSameAsBladeFormatter(
"withoutConfig/wrapAttributesMinAttrs/index.blade.php",
"withoutConfig/wrapAttributesMinAttrs/formatted.index.blade.php",
);
});


test("Should format file with runtime config / wrapLineLength", async function (this: any) {
this.timeout(20000);
await formatSameAsBladeFormatter(
Expand Down

0 comments on commit 114c2ba

Please sign in to comment.