The Barista explores every Latte (file) for strict quality, helps with Latte 2 to 3 upgrade

Overview

The Barista makes Your Perfectly Tasty Latte

Do you drink Latte with your templates?

Get it from Barista that knows his job:

  • explore Latte via node visitors
  • upgrade Latte 2 to 3
  • lint your Latte files with context of your project

Lint Your Files with Custom Macros and Filters

Native latte linter does not understand the context of your project. If you use custom macros or filters, it will be falsely reported as missing. The Barista Linter fixes this.

To get context aware Latte, we have to provide it via custom PHP file. This file must return the Latte\Engine from your project. Create e.g. tests/latte-provider.php with following content:

use App\DI\ContainerFactory;
use Nette\Bridges\ApplicationLatte\LatteFactory

$containerFactory = new ContainerFactory();
$container = $containerFactory->create();

/** @var LatteFactory $latteFactory */
$latteFactory = $container->getByType(LatteFactory::class);
return $latteFactory->create();

Create barista.neon in your root and configure parameter:

parameters:
    latteProviderFile: "tests/latte-provider.php"

Then run linting command on your paths:

vendor/bin/barista lint templates/some-file.latte

Then linter knows about all your macros and functions and reports only real bugs!

Comments
  • Crash without PHPUnit installed

    Crash without PHPUnit installed

    Running vendor/bin/barista analyze app in a Nette project that does not use PHPUnit (nette/tester is okay) crashes:

    Fatal error: Uncaught Error: Class "PHPUnit\Framework\TestCase" not found in /home/jtojnar/Projects/eudyptes/vendor/barista/barista/src/Testing/Macro/AbstractMacroTest.php:22
    Stack trace:
    #0 /home/jtojnar/Projects/eudyptes/vendor/composer/ClassLoader.php(571): include()
    #1 /home/jtojnar/Projects/eudyptes/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/home/jtojnar/P...')
    #2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Barista\\Testing...')
    #3 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Extensions/SearchExtension.php(97): class_exists('Barista\\Testing...')
    #4 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Extensions/SearchExtension.php(72): Nette\DI\Extensions\SearchExtension->findClasses(Object(stdClass))
    #5 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Compiler.php(241): Nette\DI\Extensions\SearchExtension->loadConfiguration()
    #6 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Compiler.php(211): Nette\DI\Compiler->processExtensions()
    #7 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerLoader.php(119): Nette\DI\Compiler->compile()
    #8 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerLoader.php(81): Nette\DI\ContainerLoader->generate('Container_55cc0...', Array)
    #9 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerLoader.php(44): Nette\DI\ContainerLoader->loadFile('Container_55cc0...', Array)
    #10 /home/jtojnar/Projects/eudyptes/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(274): Nette\DI\ContainerLoader->load(Array, Array)
    #11 /home/jtojnar/Projects/eudyptes/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(252): Nette\Bootstrap\Configurator->loadContainer()
    #12 /home/jtojnar/Projects/eudyptes/vendor/barista/barista/src/DI/BaristaContainerFactory.php(32): Nette\Bootstrap\Configurator->createContainer()
    #13 /home/jtojnar/Projects/eudyptes/vendor/barista/barista/bin/barista.php(31): Barista\DI\BaristaContainerFactory->create(Array)
    #14 /home/jtojnar/Projects/eudyptes/vendor/barista/barista/bin/barista(4): require('/home/jtojnar/P...')
    #15 /home/jtojnar/Projects/eudyptes/vendor/bin/barista(117): include('/home/jtojnar/P...')
    #16 {main}
      thrown in /home/jtojnar/Projects/eudyptes/vendor/barista/barista/src/Testing/Macro/AbstractMacroTest.php on line 22
    
    opened by jtojnar 17
  • Analyze: Cannot redeclare block 'content' in `TemplateParser.php`

    Analyze: Cannot redeclare block 'content' in `TemplateParser.php`

    Running analyze on nette’s example project, I get the following error:

    $ vendor/bin/barista analyze app/ -vvv
    
     ! [NOTE] Analying 7 files...                                                                                           
    
    
    In TemplateParser.php line 377:
                                                      
      [Latte\CompileException]                        
      Cannot redeclare block 'content' (at column 1)  
                                                      
    
    Exception trace:
      at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:377
     Latte\Compiler\TemplateParser->checkBlockIsUnique() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php:54
     Latte\Essential\Nodes\BlockNode::create() at n/a:n/a
     Generator->valid() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:176
     Latte\Compiler\TemplateParser->parseLatteStatement() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:112
     Latte\Compiler\TemplateParser->inTextResolve() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php:58
     Latte\Compiler\TemplateParserHtml->inTextResolve() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:90
     Latte\Compiler\TemplateParser->parseFragment() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:71
     Latte\Compiler\TemplateParser->parse() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/LatteParser/LatteParser.php:52
     Barista\LatteParser\LatteParser->parseCode() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/LatteParser/LatteParser.php:47
     Barista\LatteParser\LatteParser->parseFile() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/Analyzer/LatteAnalyzer.php:24
     Barista\Analyzer\LatteAnalyzer->run() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/Command/AnalyzeCommand.php:34
     Barista\Command\AnalyzeCommand->execute() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Command/Command.php:291
     Symfony\Component\Console\Command\Command->run() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Application.php:998
     Symfony\Component\Console\Application->doRunCommand() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Application.php:299
     Symfony\Component\Console\Application->doRun() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Application.php:171
     Symfony\Component\Console\Application->run() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/bin/barista.php:34
     require() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/bin/barista:4
     include() at /home/jtojnar/Projects/repro/barista-3/vendor/bin/barista:117
    
    analyze <paths>...
    
    opened by jtojnar 3
  • {layout} must be placed in template head (at column 1)

    {layout} must be placed in template head (at column 1)

    Similar to #4 there seems to be some caching going on as the error seems to happen when a file contains {layout} macro if it is not the first checked file:

    $ vendor/bin/barista analyze app/ -vvvv
    
    Analyzing 9 files...
    ====================
    
    /home/jtojnar/Projects/repro/barista-3/app/Presenters/templates/Homepage/bar.latte
    /home/jtojnar/Projects/repro/barista-3/app/Presenters/templates/Homepage/foo.latte
    
    In ExtendsNode.php line 35:
                                                              
      [Latte\CompileException]                                
      {layout} must be placed in template head (at column 1)  
                                                              
    
    Exception trace:
      at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php:35
     Latte\Essential\Nodes\ExtendsNode::create() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:174
     Latte\Compiler\TemplateParser->parseLatteStatement() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:112
     Latte\Compiler\TemplateParser->inTextResolve() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php:58
     Latte\Compiler\TemplateParserHtml->inTextResolve() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:90
     Latte\Compiler\TemplateParser->parseFragment() at /home/jtojnar/Projects/repro/barista-3/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php:71
     Latte\Compiler\TemplateParser->parse() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/LatteParser/LatteParser.php:55
     Barista\LatteParser\LatteParser->parseCode() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/LatteParser/LatteParser.php:47
     Barista\LatteParser\LatteParser->parseFile() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/Analyzer/LatteAnalyzer.php:28
     Barista\Analyzer\LatteAnalyzer->run() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/src/Command/AnalyzeCommand.php:34
     Barista\Command\AnalyzeCommand->execute() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Command/Command.php:291
     Symfony\Component\Console\Command\Command->run() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Application.php:998
     Symfony\Component\Console\Application->doRunCommand() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Application.php:299
     Symfony\Component\Console\Application->doRun() at /home/jtojnar/Projects/repro/barista-3/vendor/symfony/console/Application.php:171
     Symfony\Component\Console\Application->run() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/bin/barista.php:34
     require() at /home/jtojnar/Projects/repro/barista-3/vendor/barista/barista/bin/barista:4
     include() at /home/jtojnar/Projects/repro/barista-3/vendor/bin/barista:117
    
    analyze <paths>...
    

    Repro: https://github.com/jtojnar/repro/tree/d9eb52ae4cce6d95a062a71c3de13a5bcfce2706/barista-3

    opened by jtojnar 0
  • Analyze crashes on trying to create app’s presenter

    Analyze crashes on trying to create app’s presenter

    Running vendor/bin/barista analyze in my Nette project using 08fa2df crashes with the following error:

    Fatal error: Uncaught Nette\DI\ServiceCreationException: Service 'application.1' (type of App\Presenters\DashboardPresenter): Service of type App\Model\HelperLoader required by $helperLoader in App\Presenters\BasePresenter::__construct() not found. Did you add it to configuration file? in /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Resolver.php:650
    Stack trace:
    #0 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Resolver.php(577): Nette\DI\Resolver::autowireArgument(Object(ReflectionParameter), Object(Closure))
    #1 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Resolver.php(232): Nette\DI\Resolver::autowireArguments(Object(ReflectionMethod), Array, Object(Closure))
    #2 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Definitions/ServiceDefinition.php(226): Nette\DI\Resolver->completeStatement(Object(Nette\DI\Definitions\Statement))
    #3 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Resolver.php(168): Nette\DI\Definitions\ServiceDefinition->complete(Object(Nette\DI\Resolver))
    #4 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerBuilder.php(332): Nette\DI\Resolver->completeDefinition(Object(Nette\DI\Definitions\ServiceDefinition))
    #5 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Compiler.php(275): Nette\DI\ContainerBuilder->complete()
    #6 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Compiler.php(212): Nette\DI\Compiler->processBeforeCompile()
    #7 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerLoader.php(119): Nette\DI\Compiler->compile()
    #8 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerLoader.php(81): Nette\DI\ContainerLoader->generate('Container_55cc0...', Array)
    #9 /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/ContainerLoader.php(44): Nette\DI\ContainerLoader->loadFile('Container_55cc0...', Array)
    #10 /home/jtojnar/Projects/eudyptes/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(274): Nette\DI\ContainerLoader->load(Array, Array)
    #11 /home/jtojnar/Projects/eudyptes/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(252): Nette\Bootstrap\Configurator->loadContainer()
    #12 /home/jtojnar/Projects/eudyptes/vendor/barista/barista/src/DI/BaristaContainerFactory.php(32): Nette\Bootstrap\Configurator->createContainer()
    #13 /home/jtojnar/Projects/eudyptes/vendor/barista/barista/bin/barista.php(31): Barista\DI\BaristaContainerFactory->create(Array)
    #14 /home/jtojnar/Projects/eudyptes/vendor/barista/barista/bin/barista(4): require('/home/jtojnar/P...')
    #15 /home/jtojnar/Projects/eudyptes/vendor/bin/barista(117): include('/home/jtojnar/P...')
    #16 {main}
      thrown in /home/jtojnar/Projects/eudyptes/vendor/nette/di/src/DI/Resolver.php on line 650
    

    Initially reported in #2.

    opened by jtojnar 11
  • Allow upgrading unquoted strings with interpolation

    Allow upgrading unquoted strings with interpolation

    Upgrading to Latte 2.11, I get the following deprecation:

    Expression 'show#mail$mail->id' should be wrapped in double quotes.
    

    It would be nice if this could upgrade these as suggested by David:

    <a n:href="show#mail$mail->id $mail->root->id, tree => true">Zobrazit ve stromu</a>
    ---
    <a n:href='"show#mail{$mail->id}" $mail->root->id, tree => true'>Zobrazit ve stromu</a>
    

    Similarly for a component with multiplier:

    <p n:snippet="participator-$meeting->id">{control participator-$meeting->id}</p>
    --
    <p n:snippet='"participator-{$meeting->id}"'>{control "participator-{$meeting->id}"}</p>
    
    opened by jtojnar 2
Owner
Tomas Votruba
@rectorphp @symplify | "A day without a commit to an open-source is a day wasted." Open-Source for Life ❤️️
Tomas Votruba
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.

?? Yell PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects. Requirement

Zeeshan Ahmad 20 Dec 8, 2018
A WordPress package to nudge users to upgrade their software versions (starting with PHP)

whip A WordPress package to nudge users to upgrade their software versions (starting with PHP) Requirements The following versions of PHP are supporte

Yoast 71 Oct 18, 2022
Upgrade module for PrestaShop

1-Click Upgrade About Upgrade to the latest version of PrestaShop in a few clicks, thanks to this automated method. This module is compatible with all

PrestaShop 84 Dec 29, 2022
Internal Quality Assurance Cell, IQAC Project Data Capturing System.

IQAC-DCS-2021 Added AQAR Directory with template pages! Old Readme Internal Quality Assurance Cell, IQAC Project Data Capturing System. Fork Repo Clon

Kashif Raza 4 Jan 4, 2022
PHP_Depend is an adaptation of the established Java development tool JDepend. This tool shows you the quality of your design in terms of extensibility, reusability and maintainability.

PHP Depend Documentation PHP Depend for enterprise Available as part of the Tidelift Subscription. The maintainers of PHP Depend and thousands of othe

PHP_Depend 837 Dec 14, 2022
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

Nuno Maduro 4.4k Jan 4, 2023
This package provides a wrapper for Google Lighthouse to audit the quality of web pages with Laravel.

laravel-google-lighthouse This package is based on octoper/lighthouse-php. This package provides a wrapper for Google Lighthouse to audit the quality

Logiek 5 Jun 1, 2022
Comprehensive Plugin for composer to execute PHP Quality assurance Tools

NOT MAINTANED ANYMORE The development of composer-plugin-qa was dropped in favor of phpqa which is actively maintained. The project use docker and can

Webysther Nunes 25 Apr 30, 2021
Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files

Quality Hook Installer Install an execute script of specify quality tools to your git pre-commit hook, and it executes only for changed files Install

Kay W. 2 Dec 15, 2022
Enhance product data quality and streamline content creation with the Pimcore and ChatGPT integration.

chatgpt-pimcore Enhance product data quality and streamline content creation with the Pimcore and ChatGPT integration. Overview The integration of Pim

Pravin chaudhary 6 Jun 5, 2023
Adds a header to every response to try and twart Google's usage of your site in it's FLoC tracking method.

Laravel No FLoC This package will add the Permissions-Policy: interest-cohort=() to try and twart Google's usage of your site in it's FLoC tracking me

Jean-Philippe Murray 11 Jul 14, 2022
Sanitize and escape every values in your PHP Application

PHP Sanitizer Sanitize and escape every values in your PHP Application. This solution will make PHP developer life easy, very easy and developers woul

Maniruzzaman Akash 10 Oct 2, 2022
Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

JBZoo Toolbox 786 Dec 30, 2022
This module integrates Silverstripe CMS with Google Translate API and then allows content editors to use automatic translation for every translatable field.

Autotranslate This module integrates Silverstripe CMS with Google Translate API and then allows content editors to use automatic translation for every

null 4 Jan 3, 2022
SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someone

SlimJim WHY? SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someo

Jesal Gadhia 100 Apr 22, 2022
A widget that displays a Bible verse every day in the Statamic dashboard

Statamic Widget: Verse of the Day What is it A widget that displays a Bible verse every day in the Statamic dashboard. How to install it Install via c

Michael 2 Jan 27, 2022
This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

DIVE 20 Nov 11, 2022
This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api)

Validator-Class This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api) Requirements A

Barbod 3 Jul 18, 2022
Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda.

Our Wedding Website Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda. ?

Edd Mann 3 Aug 21, 2022