@spwig/theme-validator 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/schemas/theme_manifest_schema.json +7 -65
- package/dist/types/manifest.d.ts +50 -82
- package/dist/types/manifest.d.ts.map +1 -1
- package/dist/types/manifest.js +1 -1
- package/dist/types/manifest.js.map +0 -0
- package/dist/types/validation-result.d.ts +0 -0
- package/dist/types/validation-result.d.ts.map +0 -0
- package/dist/types/validation-result.js +0 -0
- package/dist/types/validation-result.js.map +0 -0
- package/dist/validators/design-tokens-validator.d.ts +16 -0
- package/dist/validators/design-tokens-validator.d.ts.map +1 -1
- package/dist/validators/design-tokens-validator.js +208 -0
- package/dist/validators/design-tokens-validator.js.map +1 -1
- package/dist/validators/manifest-validator.d.ts +0 -0
- package/dist/validators/manifest-validator.d.ts.map +0 -0
- package/dist/validators/manifest-validator.js +0 -0
- package/dist/validators/manifest-validator.js.map +0 -0
- package/dist/validators/theme-validator.d.ts +11 -7
- package/dist/validators/theme-validator.d.ts.map +1 -1
- package/dist/validators/theme-validator.js +110 -84
- package/dist/validators/theme-validator.js.map +1 -1
- package/package.json +1 -1
- package/dist/schemas/component_manifest_schema.json +0 -221
- package/dist/validators/component-validator.d.ts +0 -50
- package/dist/validators/component-validator.d.ts.map +0 -1
- package/dist/validators/component-validator.js +0 -235
- package/dist/validators/component-validator.js.map +0 -1
- package/dist/validators/template-validator.d.ts +0 -34
- package/dist/validators/template-validator.d.ts.map +0 -1
- package/dist/validators/template-validator.js +0 -170
- package/dist/validators/template-validator.js.map +0 -1
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Template Validator
|
|
3
|
-
* Validates Django/Jinja2 template files
|
|
4
|
-
*/
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
|
-
import { createError, createWarning, } from '../types/validation-result.js';
|
|
7
|
-
export class TemplateValidator {
|
|
8
|
-
errors = [];
|
|
9
|
-
warnings = [];
|
|
10
|
-
/**
|
|
11
|
-
* Validate a template file
|
|
12
|
-
*/
|
|
13
|
-
async validate(templatePath) {
|
|
14
|
-
this.errors = [];
|
|
15
|
-
this.warnings = [];
|
|
16
|
-
// Check file exists
|
|
17
|
-
if (!(await this.fileExists(templatePath))) {
|
|
18
|
-
this.errors.push(createError('file_not_found', `Template file does not exist: ${templatePath}`));
|
|
19
|
-
return this.buildResult();
|
|
20
|
-
}
|
|
21
|
-
// Check file is not empty
|
|
22
|
-
const content = await this.readTemplate(templatePath);
|
|
23
|
-
if (!content) {
|
|
24
|
-
return this.buildResult();
|
|
25
|
-
}
|
|
26
|
-
// Basic template syntax checks
|
|
27
|
-
this.checkTemplateSyntax(content, templatePath);
|
|
28
|
-
// Check for common issues
|
|
29
|
-
this.checkCommonIssues(content, templatePath);
|
|
30
|
-
return this.buildResult();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Check file exists
|
|
34
|
-
*/
|
|
35
|
-
async fileExists(filePath) {
|
|
36
|
-
try {
|
|
37
|
-
const stats = await fs.stat(filePath);
|
|
38
|
-
return stats.isFile();
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Read template content
|
|
46
|
-
*/
|
|
47
|
-
async readTemplate(templatePath) {
|
|
48
|
-
try {
|
|
49
|
-
const content = await fs.readFile(templatePath, 'utf-8');
|
|
50
|
-
if (content.trim().length === 0) {
|
|
51
|
-
this.errors.push(createError('empty_template', 'Template file is empty', {
|
|
52
|
-
path: templatePath,
|
|
53
|
-
}));
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
return content;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
if (error instanceof Error) {
|
|
60
|
-
this.errors.push(createError('read_error', `Failed to read template: ${error.message}`, {
|
|
61
|
-
path: templatePath,
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Check basic template syntax
|
|
69
|
-
*/
|
|
70
|
-
checkTemplateSyntax(content, templatePath) {
|
|
71
|
-
const lines = content.split('\n');
|
|
72
|
-
// Check for unclosed tags
|
|
73
|
-
let blockStack = [];
|
|
74
|
-
const blockTags = ['if', 'for', 'block', 'with', 'autoescape', 'spaceless', 'verbatim'];
|
|
75
|
-
lines.forEach((line, index) => {
|
|
76
|
-
const lineNumber = index + 1;
|
|
77
|
-
// Find opening tags
|
|
78
|
-
const openMatches = line.matchAll(/{%\s*(\w+)/g);
|
|
79
|
-
for (const match of openMatches) {
|
|
80
|
-
const tag = match[1];
|
|
81
|
-
if (blockTags.includes(tag)) {
|
|
82
|
-
blockStack.push({ tag, line: lineNumber });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Find closing tags
|
|
86
|
-
const closeMatches = line.matchAll(/{%\s*end(\w+)/g);
|
|
87
|
-
for (const match of closeMatches) {
|
|
88
|
-
const tag = match[1];
|
|
89
|
-
if (blockStack.length === 0) {
|
|
90
|
-
this.errors.push(createError('template_syntax', `Unexpected closing tag: {% end${tag} %}`, {
|
|
91
|
-
path: templatePath,
|
|
92
|
-
line: lineNumber,
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
const lastBlock = blockStack.pop();
|
|
97
|
-
if (lastBlock && lastBlock.tag !== tag) {
|
|
98
|
-
this.errors.push(createError('template_syntax', `Mismatched closing tag: expected {% end${lastBlock.tag} %}, found {% end${tag} %}`, {
|
|
99
|
-
path: templatePath,
|
|
100
|
-
line: lineNumber,
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
// Check for unclosed blocks
|
|
107
|
-
if (blockStack.length > 0) {
|
|
108
|
-
for (const block of blockStack) {
|
|
109
|
-
this.errors.push(createError('template_syntax', `Unclosed block: {% ${block.tag} %}`, {
|
|
110
|
-
path: templatePath,
|
|
111
|
-
line: block.line,
|
|
112
|
-
}));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Check for basic variable syntax errors
|
|
116
|
-
const variablePattern = /{{\s*[\w._[\]]+\s*}}/g;
|
|
117
|
-
const invalidVariables = content.match(/{{[^}]*$/gm);
|
|
118
|
-
if (invalidVariables) {
|
|
119
|
-
this.errors.push(createError('template_syntax', 'Unclosed variable tag: {{', {
|
|
120
|
-
path: templatePath,
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Check for common template issues
|
|
126
|
-
*/
|
|
127
|
-
checkCommonIssues(content, templatePath) {
|
|
128
|
-
// Warn about hardcoded URLs
|
|
129
|
-
if (content.includes('http://') || content.includes('https://')) {
|
|
130
|
-
const httpMatches = content.match(/https?:\/\/[^\s"'<>]+/g);
|
|
131
|
-
if (httpMatches && httpMatches.length > 0) {
|
|
132
|
-
this.warnings.push(createWarning('hardcoded_url', `Found ${httpMatches.length} hardcoded URL(s) in template`, {
|
|
133
|
-
path: templatePath,
|
|
134
|
-
suggestion: 'Use relative URLs or Django template tags like {% url %}',
|
|
135
|
-
}));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// Warn about inline styles (should use design tokens)
|
|
139
|
-
const inlineStyleCount = (content.match(/style\s*=/gi) || []).length;
|
|
140
|
-
if (inlineStyleCount > 3) {
|
|
141
|
-
this.warnings.push(createWarning('inline_styles', `Found ${inlineStyleCount} inline style attributes`, {
|
|
142
|
-
path: templatePath,
|
|
143
|
-
suggestion: 'Consider using CSS classes and design tokens instead',
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
// Check for missing alt attributes on images
|
|
147
|
-
const imgTags = content.match(/<img[^>]+>/gi);
|
|
148
|
-
if (imgTags) {
|
|
149
|
-
for (const imgTag of imgTags) {
|
|
150
|
-
if (!imgTag.includes('alt=')) {
|
|
151
|
-
this.warnings.push(createWarning('accessibility', 'Image tag missing alt attribute', {
|
|
152
|
-
path: templatePath,
|
|
153
|
-
suggestion: 'Add alt attribute for accessibility',
|
|
154
|
-
}));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Build validation result
|
|
161
|
-
*/
|
|
162
|
-
buildResult() {
|
|
163
|
-
return {
|
|
164
|
-
isValid: this.errors.length === 0,
|
|
165
|
-
errors: this.errors,
|
|
166
|
-
warnings: this.warnings,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
//# sourceMappingURL=template-validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template-validator.js","sourceRoot":"","sources":["../../src/validators/template-validator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAIL,WAAW,EACX,aAAa,GACd,MAAM,+BAA+B,CAAC;AAEvC,MAAM,OAAO,iBAAiB;IACpB,MAAM,GAAsB,EAAE,CAAC;IAC/B,QAAQ,GAAwB,EAAE,CAAC;IAE3C;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,YAAoB;QACjC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,oBAAoB;QACpB,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,WAAW,CAAC,gBAAgB,EAAE,iCAAiC,YAAY,EAAE,CAAC,CAC/E,CAAC;YACF,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;Q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