Giter Site home page Giter Site logo

shufo / vscode-blade-formatter Goto Github PK

View Code? Open in Web Editor NEW
4.0K 9.0 30.0 8.16 MB

An opinionated Blade file formatter for VSCode

Home Page: https://marketplace.visualstudio.com/items?itemName=shufo.vscode-blade-formatter

License: MIT License

JavaScript 5.42% TypeScript 94.58%
laravel vscode vscode-extension formatter

vscode-blade-formatter's Introduction

CI Visual Studio Marketplace Installs Visual Studio Marketplace Downloads Visual Studio Marketplace Version Visual Studio Marketplace Rating

vscode-blade-formatter

An opinionated Blade file formatter for VSCode. Marketplace page is here.

You can also format programmatically with the same syntax using the blade-formatter that this extension relies on.

Features

  • Automatically indent markup inside directives
  • Automatically add spacing to blade template markers
  • PHP 8 support (null safe operator, named arguments) 🐘
  • PSR-2 support (format inside directives)
  • Automatically sort Tailwind CSS classes with respect of tailwind.config.js

Screencast

Screencast

Extension Settings

setting description default
Blade Formatter: format Enabled Whether it enables or not true
Blade Formatter: format Indent Size An indent size 4
Blade Formatter: format Wrap Line Length The length of line wrap size 120
Blade Formatter: format Wrap Attributes The way to wrap attributes. [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] auto
Blade Formatter: format Wrap Attributes Min Attrs 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 2
Blade Formatter: format Sort Tailwind Css Classes Sort Tailwind CSS classes automatically false
Blade Formatter: format Sort HTML Attributes Sort HTML Attributes in the specified order. [none | alphabetical | code-guide | idiomatic | vuejs] none
Blade Formatter: format Indent Inner Html Indent <head> and <body> sections in html. false
Blade Formatter: format use Tabs Use tab as indentation character false
Blade Formatter: format Custom Html Attributes Order Comma separated custom HTML attributes order. e.g. id, data-.+, class, name. To enable this you must specify sort html attributes option as custom. You can use regex for attribute names. none
Blade Formatter: format No Multiple Empty Lines Collapses multiple blank lines into a single blank line. false
Blade Formatter: format No PHP Syntax Check Disable PHP Syntax check. Enabling this will suppress syntax error reporing. ""
Blade Formatter: format No Single Quote Use double quotes instead of single quotes for php expression. false
Blade Formatter: Dont Show New Version Message If set to 'true', the new version message won't be shown anymore. false

Configuration file: .bladeformatterrc.json or .bladeformatterrc

To configure settings per project, put .bladeformatterrc.json or .bladeformatterrc to your project root will vscode-blade-formatter treat it as setting files.

Configuration file will like below:

{
    "indentSize": 4,
    "wrapAttributes": "auto",
    "wrapAttributesMinAttrs": 2,
    "wrapLineLength": 120,
    "endWithNewLine": true,
    "noMultipleEmptyLines": false,
    "useTabs": false,
    "sortTailwindcssClasses": true,
    "sortHtmlAttributes": "none",
    "noPhpSyntaxCheck": false,
    "noSingleQuote": false
}

Ignoring Files: .bladeignore

To exclude files from formatting, create a .bladeignore file in the root of your project. .bladeignore uses gitignore syntax

# Ignore email templates
resources/views/email/**

Disabling format in file

To disable formatting in your file, you can use blade comments in the following format:

{{-- blade-formatter-disable --}}
    {{ $foo }}
    {{ $bar }}
{{-- blade-formatter-enable --}}

To disable formatting on a specific line, you can use comment in the following format:

{{-- blade-formatter-disable-next-line --}}
    {{ $foo }}

To disable formatting for an entire file, put a {{-- blade-formatter-disable --}} comment at the beginning of the file:

{{-- blade-formatter-disable --}}

{{ $foo }}

TODO

  • Add more option for HTML formatting rules
  • Add option for PHP formatting rules
  • Automate package publishing flow
  • Integration test

Release Notes

see CHANGELOG.md

Related Projects

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Development

$ yarn install
$ cp .env.example .env # set your app insight key
$ yarn run watch # watch changes

Testing

$ yarn install
$ cp .env.example .env # set your app insight key
$ yarn run compile
$ yarn run test

Sponsors

Contributors

shufo
Shuhei Hayashibara
slovenianGooner
SlovenianGooner
yaegassy
Yaegassy
notdian
Null
1cbyc
Isaac Emmanuel
j3j5
Julio J. Foulquie

LICENSE

MIT

Data and telemetry

This extension collects usage data and sends it to Azure Application Insight to improve extension. This extension respects the telemetry.enableTelemetry setting.

To opt out, please set the telemetry.enableTelemetry setting to false. Learn more in FAQ.

vscode-blade-formatter's People

Contributors

1cbyc avatar dependabot[bot] avatar github-actions[bot] avatar j3j5 avatar notdian avatar renovate[bot] avatar shufo avatar sloveniangooner avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-blade-formatter's Issues

issues

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

Error

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Context (Environment)

Detailed Description

Possible Implementation

format shortcut

Is it possible to implement a format shortcut?
I'd like to use the extension with no "format Enabled", and use a shortcut (Shift+Alt+F or similar) to format the current file.

fetch problams

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

formation Erro

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

php format

Hi there,

Would it be possible to format code between php directive (@php ... @endphp) with php formatter ?
sometimetimes usefull, exemple for a multi-array $template var in wordpress gutenberg block..
a bit hard to read when flated, as blade-formatter remove the "manual" indent/format on save.

{{--
  Title: Section featuredImg + 2cols
  Category: lalibellule
  Icon: admin-comments
  Keywords: section columns image
  Mode: preview
  SupportsMode: false
  SupportsMultiple: true
  SupportsInnerBlocks: true
--}}
@php
$template = [
[ 'core/columns', ['className' => 'l-SiteRow l-SiteRow--332'], [
['core/column', ['className' => 'l-SiteCol'], [
['cgb/block-fib']
]],
[ 'core/column', ['className' => 'l-SiteCol'],[
[ 'core/paragraph', [ 'placeholder' => 'Entrer du contenu...' ] ],
]],
[ 'core/column', ['className' => 'l-SiteCol'],[
[ 'core/paragraph', [ 'placeholder' => 'Entrer du contenu...' ] ],
]],
]]
];
@endphp

<section data-{{ $block['id'] }} class="l-SectionCols">
  <InnerBlocks template="<?= esc_attr( wp_json_encode($template)) ?>" />
</section>

Anyway, thank you for the best blade formatter out there !
Best.

vscode blade formatter error

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

Can not format blade: "Check if temp is too complicated or not"

Template


@extends('layouts/app')

@section('content')
    @if ($x)
        asdasd
    @endif
@endsection

Context (Environment)

Can't format blade: something goes wrong. Please check if template is too complicated or not. Or simplify template might solves issue.

  • write your environment

try to format

update1: it happens when I set the "bladeFormatter.format.wrapAttributes" to "force-expand-multiline",

update2: after a file formatted once, all attempts to format throws this error! no matter what is the wrapAttribute value

Error "Cannot invoke loadWASM more than once." when saving blade file

Template

<div>
    <tr class="flex flex-col items-start md:table-row justify-center mb-10
        sm:hover:bg-gray-100">
        <td class="whitespace-no-wrap w-full">
            <div class="bg-blue-100 inline-block py-1 px-2 text-xs md:hidden rounded">Title</div>
            <div class="items-center py-3 px-6">
                <div class="text-sm font-medium text-gray-900">
                    {{ $vacancy->title }}
                </div>
            </div>
        </td>
        <td class="whitespace-now-rap w-full">
            <div class="bg-blue-100 inline-block py-1 px-2 text-xs md:hidden rounded">Status</div>
            <div class="items-center py-3 px-6">
                <x-badges.error>Disabled</x-badges.error>
            </div>
        </td>
        <td class="whitespace-no-wrap w-full">
            <div class="bg-blue-100 inline-block py-1 px-2 text-xs md:hidden rounded">Subscription period</div>
            <div class="items-center py-3 px-6">
                <div class="text-sm font-medium text-gray-900 whitespace-nowrap">
                    @empty($vacancy->subscription)
                        No subscription
                    @else
                        {{ $vacancy->subscription }}
                    @endempty
                </div>
            </div>
        </td>
        <td class="whitespace-no-wrap w-full">
            <div class="bg-blue-100 inline-block py-1 px-2 text-xs md:hidden rounded">Created At</div>
            <div class="items-center py-3 px-6">
                <div class="text-sm font-medium text-gray-900 whitespace-nowrap">
                    {{ $vacancy->created_at->format('d.m.Y h:i:s') }}
                </div>
            </div>
        </td>
        <td class="flex px-6 py-2 md:py-4 w-full bg-gray-100 md:bg-transparent justify-evenly">

            <button wire:click="cloneVacancy({{ $vacancy->id }})" class="inline-block cursor-pointer p-1 border border-transparent transition duration-500 ease-in-out hover:border-green-400 text-green-500 rounded mr-2 focus:bg-green-400 focus:outline-none focus:text-white" title="Clone vacancy">
                <svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
                </svg>
            </button>

            <button wire:click="redirectToVacancyEditForm" class="inline-block cursor-pointer p-1 text-indigo-500 focus:text-white focus:outline-none focus:bg-indigo-400 border border-transparent transition duration-500 ease-in-out hover:border-indigo-400 rounded mr-2" title="Edit vacancy">
                <svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
                    stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                </svg>
            </button>

            @if ($confirmDelete == $vacancy->id)
                <button wire:click="removeVacancy" class="inline-block cursor-pointer text-white bg-red-400 focus:text-red-400 focus:border-red-400 focus:outline-none focus:bg-transparent py-1 px-2 border border-red-400 transition duration-500 ease-in-out text-base font-semibold hover:border-red-500 hover:bg-red-500 rounded" title="Confirm delete">
                    Sure?
                </button>
            @else
                <button wire:click="$emitUp('confirmVacancyDelete', {{ $vacancy->id }})" class="inline-block cursor-pointer text-red-500 focus:text-white focus:outline-none focus:bg-red-400 p-1 border border-transparent transition duration-500 ease-in-out hover:border-red-400 rounded" title="Delete vacancy">
                    <svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>
            @endif
        </td>
    </tr>
</div>

Context (Environment)

Environment: Development

Description

When saving the item.blade.php file I get the error "Cannot invoke loadWASM more than once". I use Laravel 8 with Jetstream.

error formater in function old()

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Context (Environment)

Detailed Description

Possible Implementation

Blade não está formatando

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

Unwanted Line Breaks In Script

I use "force aligned" as the wrap attribute and the code down below

<script> var values = {!!json_encode($data['values']) !!}; </script>
is formatted into

<script>
var values = {
!!json_encode($data['values']) !!
};
</script>

and obviously, it causes an error.

Strips existing code

Tried this on a couple of blade templates and it stripped everything up to the first blade marker {{. One had some HTML first and the other was a mix of HTML and PHP.

error

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

Blade directives mixed in with script tags causes formatter to fail

Template

@push('scripts')
    <script src="{{ asset('backend/plugins/dropzone/dropzone.min.js') }}"></script>
    <script>
        Dropzone.options.gallery = {
            url: "...",
            previewTemplate: $("#preview-template").html(),
            dictDefaultMessage: "Drop files here or click to select",
            addRemoveLinks: true,
            uploadMultiple: true,
            maxFilesize: 2,
            filesizeBase: 1024,
            acceptedFiles: "image/jpg,image/jpeg,image/png",
            init: function () {
                this.renderExistingServerFiles = function(files, fileUrls , response){
                    for (const file in files) {
                        if (Object.hasOwnProperty.call(files, file)) {
                            const element = files[file];
                            
                            this.files.push(element);
                            this.displayExistingFile(element, fileUrls[file], null, null, true);
                            this.emit("processing", element);
                            this.emit("complete", element);
                        }
                    }
                    this.emit("successmultiple", files, response, false);
                }

                @isset($item->images)
                    let files = [];
                    let fileUrls = [];
                    let response = { status:"success", fileHashes: [], imageIds: []};
                    @foreach($item->images as $image)
                        @php
                            $imageUrl = asset('img/'.$image->image_hash);
                            $imagePath = public_path('img/'.$image->image_hash);
                            $imageMime = File::mimeType($imagePath);
                            $imageSize = File::size($imagePath);
                            $imageName = File::name($imagePath);
                        @endphp

                        files.push(
                            {
                                processing: true,
                                accepted: true,
                                name: "{{ $imageName }}",
                                size: {{ $imageSize }},
                                type: '{{ $imageMime }}',
                                status: Dropzone.SUCCESS,
                            },
                        );
                        
                        fileUrls.push("{{ $imageUrl }}")
                        response.fileHashes.push("{{ $image->image_hash }}")
                        response.imageIds.push("{{ $image->id }}")
                    @endforeach
                    this.renderExistingServerFiles(files, fileUrls, response);
                @endisset
            },
        }

    </script>
@endpush

Context (Environment)

  • Standard laravel dev environment

Tell me what should happen

The formatter should be able to format blade code inside script tags.

Description

Blade directives used inside java script tags causes issues with the formatter thereby causing it to fail.

Indent Type Support

Are there any plans to allow users to set indent size? Personally, I prefer tabs to spaces and the extension doesn't seem to inherit the file's preferred spacing method.

Support for beautify.config

Supporting beautify.config would be great:

  "beautify.config": {
    "indent_size": 2,
    "wrap_line_length": 140,
    "wrap_attributes": "force-aligned"
  },

Then it's a perfect extension!

error

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Context (Environment)

Detailed Description

Possible Implementation

Comments keep getting indented on every save or manual format trigger

Template

    <!--
                            Tailwind UI components require Tailwind CSS v1.8 and the @tailwindcss/ui plugin.
                            Read the documentation to get started: https://tailwindui.com/documentation
                            -->

Context (Environment)

OS: Windows 10
VSCode: 1.51.1
V-B-F: 0.6.1

Description

Every time I save, paste or manually apply formatting any comments are indented over and over beyond the 4-space setting.
Changing the "Wrap Attributes" setting does not have an effect.

Comments should only be indented once at the given space/tab setting.

    <!--
        Tailwind UI components require Tailwind CSS v1.8 and the @tailwindcss/ui plugin.
        Read the documentation to get started: https://tailwindui.com/documentation
        -->

Laravel formatter is not working

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

not working

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

not properly work

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

Format complex blade

It's really great to see a fresh new blade formatter eventually, I've been waiting for it for ages, thx for awesome job, man!
Btw, I have quite a complex case of blade code, no blade formatter could process on it correctly. But the code is working fine, however it's a bit ugly. Here it is.

<header class="face <?= isset($face_class) ? $face_class : '' ?>">
  <div class="container d-flex">
    @if (isset($face_class) && $face_class === 'face-narrow')
    <div class="col-md-7 face__wrapper">
      @else
      <div class="col-md-6 face__wrapper">
        @endif
        <h1 class="face__title">{{ $face_title }}</h1>
        @isset ($face_subtitle)
        <p class="face__subtitle">{{ $face_subtitle }}</p>
        @endisset
        @isset ($face_desc)
        <span class="face__text">{!! $face_desc !!}
          @endisset
          @isset ($face_desc_mb_hide)
          <span class="face__text d-none d-lg-inline">&ThinSpace;{!!
            $face_desc_mb_hide !!}</span>
          @endisset
        </span>
        @isset ($face_btn_text)
        <div class="face__button-box">
          <a href="{{ $face_anchor or '#request-form' }}" class="btn_regular"
            onclick="yaCounter.reachGoal('form'); return true;">{{ $face_btn_text }}</a>
          @endisset
          @isset ($clutch)
          <script type="text/javascript"
            src="https://widget.clutch.co/static/js/widget.js">
          </script>
          <div class="face__clutch clutch-widget"
            data-url="https://widget.clutch.co" data-widget-type="2"
            data-height="50" data-clutchcompany-id="861064"
            {{ $clutch === 'dark' ? 'data-darkbg="1"' : '' }}>
          </div>
          @endisset
          @isset ($face_btn_text)
        </div>
        @endisset
      </div>
      @if (isset($face_class) && $face_class === 'face-wide')
      <div class="col-md-7 face__image-box">
        @else
        <div class="col-md-7 col-lg-6 face__image-box">
          @endif
          @isset ($face_image)
          <picture>
            @isset ($face_image_webp)
            <source srcset="{{ $face_image_webp }}" type="image/webp">
            @endisset
            <img class="face__image" src="{{ $face_image }}" alt="Logo">
          </picture>
          @endisset
        </div>
      </div>
</header>

It'd be fantastic if your formatter can handle it someday. You can also notice an error /*escaped*/ after formatting the code.

unwanted format

Template

** @{{ item.product }} **

** it become @{{ item . product }} **

  • write your environment
  • vs code
  • i am using vue.js inside blade
  • it will not add useless spaces before and after the dot (.) in echo-raw blade
  • it's hard to read

Description

Any other information

Error formating blade

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

some bugs

  • comment formating
{{-- test --}}

becomes

{{-- test
--}}
  • adds extra space b4 variables
 @foreach ($models->groupBy("$sort.name") as $group => $data)

becomes

 @foreach ($models->groupBy(" $sort.name") as $group => $data)
  • arrays with indentation gets flatten
@extends('pages.dashboard.pages', [
    'title' => __('Cards'),
    'sortList' => [
        'name' => __('Name'),
    ]
])

becomes

@extends('pages.dashboard.pages', [
'title' => __('Cards'),
'sortList' => [
'name' => __('Name'),
]
])
  • @php with indentation gets flatten
@php
    $test = 'hello;
@endphp

becomes

@php
$test = 'hello;
@endphp
  • some attributes doesn't get moved to next line ex.style, role, tabindex, aria-*, colspan

vscode error

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

Doesn't work

Hi,

When I save my blade file, nothing happens.

Do we need to configure something ?

Thanks

Text colour changing to white

Template

Text colour is changing to white.

"indent_size": 4,
"wrap_line_length": 120,
"wrap_attributes": "auto"

Colour as provided by theme should be present.

No funciona el formateo en VSCode.

executing the command ALT + SHIFT + F shows the following message VS Code "Cannot invoke loadWASM more than once." and does not do any formatting.

The only thing I did was create a file "thing.blade.php" to start putting the internal structure of the file and when I wanted to format the code VS Code asked me to install a format for blade, so I looked for one and I found this and when I executed the command for format did nothing

Can't format blade files......

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Shows this error: Cannot invoke loadWASM more than once.

Doesn't formate any file.

vscode laravel blade Formatter

Template

Please write your blade template that occurs issues.

Context (Environment)

  • write your environment

Description

Any other informations

error in save

Template

memory allocation.

Context (Environment)

  • ubuntu 20
  • vscode 1.51.1

Description

Any other informations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.