Skip to content

Commit

Permalink
fix: 🐛 wrap line length option does not affect formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Jul 18, 2023
1 parent fdd92c7 commit bf52e7a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
26 changes: 26 additions & 0 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,30 @@ describe('The blade formatter CLI', () => {

expect(cmdResult).toEqual(formatted.toString('utf-8'));
});

test.concurrent('runtime config test (wrap line length)', async () => {
const cmdResult = await cmd.execute(binPath, [
path.resolve('__tests__', 'fixtures', 'runtimeConfig', 'wrapLineLength', 'index.blade.php'),
]);

const formatted = fs.readFileSync(
path.resolve('__tests__', 'fixtures', 'runtimeConfig', 'wrapLineLength', 'formatted.index.blade.php'),
);

expect(cmdResult).toEqual(formatted.toString('utf-8'));
});

test.concurrent('cli argument test (wrap line length)', async () => {
const cmdResult = await cmd.execute(binPath, [
'--wrap-line-length',
'40',
path.resolve('__tests__', 'fixtures', 'runtimeConfig', 'wrapLineLength', 'index.blade.php'),
]);

const formatted = fs.readFileSync(
path.resolve('__tests__', 'fixtures', 'runtimeConfig', 'wrapLineLength', 'formatted.index.blade.php'),
);

expect(cmdResult).toEqual(formatted.toString('utf-8'));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"wrapLineLength": 40
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@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
32 changes: 32 additions & 0 deletions __tests__/fixtures/runtimeConfig/wrapLineLength/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@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
2 changes: 1 addition & 1 deletion src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class Formatter {
this.options = {
...{
noPhpSyntaxCheck: false,
printWidth: constants.defaultPrintWidth,
printWidth: options.wrapLineLength || constants.defaultPrintWidth,
},
...options,
};
Expand Down

0 comments on commit bf52e7a

Please sign in to comment.