|
It can be quite tedious getting a Jinja template to the point where the whitespace it generates passes strict linters and autoformatters like How are people generally dealing with this? Creating a autoformatter pre-commit hook that runs Jinja on-the-fly on each file to make sure the Jinja macros are not interfering with target language constructs would be possible, but the need to "backport" formatting changes to the template probably makes this tricky to get right. I assume one could also just ignore the problem and always run the autoformatter on generated code, |
Replies: 1 comment 6 replies
That's exactly how I'm doing it. My templates include pre-commit, and I maintain a rather comprehensive test suite using pytest to check generated projects (mostly files/directories and contents), and at least one test is a full integration test that installs dependencies, runs the generated project's test suite, and runs pre-commit on the generated project. I can't imagine how a linter could properly deal with Jinja-templated files. |
That's exactly how I'm doing it. My templates include pre-commit, and I maintain a rather comprehensive test suite using pytest to check generated projects (mostly files/directories and contents), and at least one test is a full integration test that installs dependencies, runs the generated project's test suite, and runs pre-commit on the generated project. I can't imagine how a linter could properly deal with Jinja-templated files.