Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint rule to check that generated files are up to date with templ files #1007

Open
behzade opened this issue Dec 1, 2024 · 1 comment
Open

Comments

@behzade
Copy link

behzade commented Dec 1, 2024

I was wondering if it's possible to set up a lint job to check if the templ generate has been ran on the project after changes to it and they are in sync with the go files. Current issue is some developers might forget to run the command and incomplete changes might get merged into repository.

@a-h
Copy link
Owner

a-h commented Dec 2, 2024

In the templ repo itself, we have a CI check.

We run templ generate without version headers, because we change the templ version every commit, but you can probably just run templ generate.

templ generate -include-version=false

Then, we check to see if the git repo is dirty after re-running the generate. If no changes have been made to the templ files, or the version of templ, there shouldn't be.

git diff --exit-code

I'm pretty sure people have discussed adding something like a --dry-run or check flag before, but can't remember where it ended up. It could be that we decided that, at the time, it was enough.

A simpler version might be to have a git hook that checks that if .templ files are dirty, the .templ.go files are dirty too, although, that wouldn't ensure that dirty files are actually up-to-date.

Since it's so fast to generate templ files, another option would be to have a pre-commit hook that runs templ generate.

Those last two would be documentation updates only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants