Skip to content

devops: keep linting latte through our own engine, dresscode's parser reads only php #233

Open

Description

@landsman

The Latte check is the one part of cli/lint.php that cannot become a dresscode rule, so it needs a home of its own once $_REQUEST and // language= move out as rules. This follows #232.

Why it cannot be a rule

dresscode parses PHP and nothing else (its docs: the grammar "is PHP and nothing else"). A rule gets a PHP syntax tree, and a .latte file does not produce one. It is not on dresscode's file list either way, since the config selects PHP files.

Why not the stock latte-lint

app/vendor/bin/latte-lint ships with Latte and is the obvious replacement, but it builds its own engine. On app/src, with Latte as locked today:

app/src/Assets/busy.latte:6    Unknown function t() on line 6 at column 74
Error: strip_tags(): Argument #1 ($string) must be of type string, null given

It exits 2 at the first of our 16 templates, so nothing after that gets checked. There are two separate causes:

  • The warning: t(), input_hidden() and input_token() are registered in Desktop\Latte::engine(), and the stock tool does not know them.
  • The crash: probably the same PHP_BINARY trap dresscode's workers hit. The tool's engine calls enablePhpLinter(PHP_BINARY), which here is frankenphp, not a php that understands -l. That comes from reading Linter::createEngine(), not from a test.

Allowing unknown functions would be worse than the crash. The list in engine() is also what a template may call, so a typo like {inputToken()} has to fail here and not on someone's screen.

What to do

Keep new Latte\Tools\Linter(Desktop\Latte::engine())->scanDirectory(). Linting through the engine the app runs means the linter and the app can never disagree about what a template may call.

  • Move it to cli/latte-lint.php when the other two checks have become rules, and have make qa call that instead of cli/lint.php.
  • Drop what only cli/lint.php needs: the syntax check (dresscode reports a syntax error and exits 1, and phpstan fails on one too), and the branch that skips Latte when app/vendor is missing. qa has app/vendor as a prerequisite, and nothing else calls the script, so that branch never runs there.
  • Keep the scan over all of app/, as today, and check it still fails on a deliberately broken template and on an unknown function. A linter that quietly finds nothing looks the same as one that passes.
  • Update CLAUDE.md, which names cli/lint.php.

Not in scope

Compiling templates in make bundle already fails the build on one that does not compile, and make e2e-packaged catches a template the build missed. Those run later and only on a release path, so they do not replace a check in make qa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions