From 114c2ba4ab64b04c7733ab506437e84e224efa7f Mon Sep 17 00:00:00 2001 From: Shuhei Hayashibara Date: Sun, 31 Dec 2023 21:04:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20option=20`wrapAttributes?= =?UTF-8?q?MinAttrs`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 ++ src/extension.ts | 1 + src/runtimeConfig.ts | 2 + .../.bladeformatterrc.json | 4 ++ .../formatted.index.blade.php | 47 +++++++++++++++++++ .../wrapAttributesMinAttrs/index.blade.php | 33 +++++++++++++ .../formatted.index.blade.php | 47 +++++++++++++++++++ .../wrapAttributesMinAttrs/index.blade.php | 33 +++++++++++++ src/test/suite/extension.test.ts | 33 +++++++++++++ 9 files changed, 205 insertions(+) create mode 100644 src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/.bladeformatterrc.json create mode 100644 src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/formatted.index.blade.php create mode 100644 src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/index.blade.php create mode 100644 src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/formatted.index.blade.php create mode 100644 src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/index.blade.php diff --git a/package.json b/package.json index a39af759..df0cfebf 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/extension.ts b/src/extension.ts index bb44e0c1..d891f1ba 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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", diff --git a/src/runtimeConfig.ts b/src/runtimeConfig.ts index fa22069b..760e03c9 100644 --- a/src/runtimeConfig.ts +++ b/src/runtimeConfig.ts @@ -18,6 +18,7 @@ export interface RuntimeConfig { indentSize?: number; wrapLineLength?: number; wrapAttributes?: WrapAttributes; + wrapAttributesMinAttrs?: number; endWithNewline?: boolean; useTabs?: boolean; sortTailwindcssClasses?: boolean; @@ -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" }, diff --git a/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/.bladeformatterrc.json b/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/.bladeformatterrc.json new file mode 100644 index 00000000..5f69e249 --- /dev/null +++ b/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/.bladeformatterrc.json @@ -0,0 +1,4 @@ +{ + "wrapAttributesMinAttrs": 0, + "wrapAttributes": "force-expand-multiline" +} diff --git a/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/formatted.index.blade.php b/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/formatted.index.blade.php new file mode 100644 index 00000000..62a9d4b6 --- /dev/null +++ b/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/formatted.index.blade.php @@ -0,0 +1,47 @@ +@extends('frontend.layouts.app') +@section('head') +@endsection +@section('title') foo +@endsection +@section('content') +
+
+
+
+

@lang('users.index')

+
+
+
    + @foreach ($tree as $users) +
  • + branch_arrow + {{ link_to_route('frontend.users.user.show', $users['name'], $users['_id']) }} +
  • + @endforeach +
+
+ @can('create', App\Models\User::class) + {!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!} + @endcan +
+
+
+
+@endsection +@section('footer') +@stop diff --git a/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/index.blade.php b/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/index.blade.php new file mode 100644 index 00000000..289031df --- /dev/null +++ b/src/test/fixtures/project/withConfig/wrapAttributesMinAttrs/index.blade.php @@ -0,0 +1,33 @@ +@extends('frontend.layouts.app') +@section('head') +@endsection +@section('title') foo +@endsection +@section('content') +
+
+
+
+

@lang('users.index')

+
+
+
    + @foreach($tree as $users) +
  • + branch_arrow + {{ link_to_route('frontend.users.user.show',$users["name"],$users['_id']) }} +
  • + @endforeach +
+
+ @can('create', App\Models\User::class) + {!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!} + @endcan +
+
+
+
+@endsection +@section('footer') +@stop + diff --git a/src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/formatted.index.blade.php b/src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/formatted.index.blade.php new file mode 100644 index 00000000..62a9d4b6 --- /dev/null +++ b/src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/formatted.index.blade.php @@ -0,0 +1,47 @@ +@extends('frontend.layouts.app') +@section('head') +@endsection +@section('title') foo +@endsection +@section('content') +
+
+
+
+

@lang('users.index')

+
+
+
    + @foreach ($tree as $users) +
  • + branch_arrow + {{ link_to_route('frontend.users.user.show', $users['name'], $users['_id']) }} +
  • + @endforeach +
+
+ @can('create', App\Models\User::class) + {!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!} + @endcan +
+
+
+
+@endsection +@section('footer') +@stop diff --git a/src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/index.blade.php b/src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/index.blade.php new file mode 100644 index 00000000..289031df --- /dev/null +++ b/src/test/fixtures/project/withoutConfig/wrapAttributesMinAttrs/index.blade.php @@ -0,0 +1,33 @@ +@extends('frontend.layouts.app') +@section('head') +@endsection +@section('title') foo +@endsection +@section('content') +
+
+
+
+

@lang('users.index')

+
+
+
    + @foreach($tree as $users) +
  • + branch_arrow + {{ link_to_route('frontend.users.user.show',$users["name"],$users['_id']) }} +
  • + @endforeach +
+
+ @can('create', App\Models\User::class) + {!! link_to_route('frontend.users.user.create', __('users.create'), [], ['class' => 'btn']) !!} + @endcan +
+
+
+
+@endsection +@section('footer') +@stop + diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 334fc28d..7b1be148 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -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(