feat: add template validation and static analysis #104#105
feat: add template validation and static analysis #104#105Ananya-vastare wants to merge 1 commit into
Conversation
Signed-off-by: Ananya Vastare <116643029+Ananya-vastare@users.noreply.github.com>
3ae7eda to
30c21df
Compare
|
@ekarademir @jamieshorten @dselman @martinhalford please look into this pr thank you |
|
Thanks for the contribution! However, this approach doesn't align with the project's design philosophy. The Accord Project libraries are designed so that validation is handled by Concerto (specifically A few issues with the current approach:
If you're interested in validation improvements, I'd suggest looking at how Concerto validation is used elsewhere in the codebase — the goal would be to leverage existing Concerto capabilities rather than adding a parallel validation system. This comment was generated by AI on behalf of @mttrbrts. |
|
Thanks for the feedback — that makes sense, and I see the issue with duplicating Concerto’s responsibilities. I’ve updated the approach to align with the design philosophy:
So now:
Let me know if you'd like me to align further with how other parts of the codebase are handling Concerto validation — happy to adjust. |
|
@Ananya-vastare Did you forget to push a new commit with the changes described in your message? |
There was a problem hiding this comment.
Pull request overview
Adds an initial TemplateValidator intended to statically analyze TemplateMark templates against provided data/model inputs to report missing variables and unused fields (Issue #104), plus a basic Jest test and dependency updates.
Changes:
- Introduces
src/TemplateValidator.tswith avalidate()API returning errors/warnings. - Adds
test/TemplateValidator.test.tsfor missing-variable detection. - Updates dependencies/lockfile (including adding
@accordproject/template-engine).
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/TemplateValidator.ts |
New validator implementation for missing/unused variable analysis. |
test/TemplateValidator.test.ts |
New unit test covering missing variable detection. |
package.json |
Dependency formatting + adds @accordproject/template-engine. |
package-lock.json |
Lockfile updates reflecting dependency changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "@accordproject/concerto-util": "3.25.7", | ||
| "@accordproject/markdown-common": "0.17.2", | ||
| "@accordproject/markdown-template": "0.17.2", | ||
| "@accordproject/template-engine": "^2.8.0", |
| export interface ValidationResult { | ||
| errors: string[]; | ||
| warnings: string[]; | ||
| } | ||
|
|
| const variableRegex = /{{\s*([a-zA-Z0-9_]+)\s*}}/g; | ||
|
|
||
| const foundVariables = new Set<string>(); | ||
| let match; |
| // find variables like {{variable}} | ||
| const variableRegex = /{{\s*([a-zA-Z0-9_]+)\s*}}/g; | ||
|
|
|
|
||
| // check if variables exist in model | ||
| foundVariables.forEach(variable => { | ||
| if (!(variable in model)) { |
| static validate(template: string, model: Record<string, any>): ValidationResult { | ||
|
|
| expect(result.errors[0]).toContain("age"); | ||
|
|
||
| }); | ||
|
|
| @@ -0,0 +1,20 @@ | |||
| import { TemplateValidator } from '../src/TemplateValidator'; | |||
|
|
||
| describe('TemplateValidator', () => { | ||
|
|
||
| it('should detect missing variables', () => { |
#104
This feature introduces a validation step for TemplateMark templates before rendering.
It performs static analysis to detect missing variables referenced in the template and fields defined in the data model but unused in the template.
The goal is to improve developer experience by catching template errors early in the development process.
This validation helps ensure better consistency between TemplateMark templates and their associated Concerto data models.