@panomc/plugin-kit 0.0.0-stage → 1.0.0-dev.62
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/assets/pano-bootstrap.css +17903 -0
- package/bin/__tests__/new/e2e.test.js +111 -0
- package/bin/__tests__/new/helpers.js +76 -0
- package/bin/__tests__/new/new.test.js +472 -0
- package/bin/new.js +530 -0
- package/bin/pano-plugin.js +162 -0
- package/bin/templates/plugin/README.md +30 -0
- package/bin/templates/plugin/_gitignore +15 -0
- package/bin/templates/plugin/build.gradle.kts +389 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/bin/templates/plugin/gradle.properties +55 -0
- package/bin/templates/plugin/gradlew +249 -0
- package/bin/templates/plugin/gradlew.bat +92 -0
- package/bin/templates/plugin/package.json.tpl +14 -0
- package/bin/templates/plugin/rollup.config.js +2 -0
- package/bin/templates/plugin/settings.gradle.kts +5 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt +50 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/frontend/ExampleFallbackPage.kt +28 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/routes/GetHelloAPI.kt +19 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt +30 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt +144 -0
- package/bin/templates/plugin/src/main/resources/config.conf +1 -0
- package/bin/templates/plugin/src/main/resources/frontend-targets.json +1 -0
- package/bin/templates/plugin/src/main/resources/locales/en-US.json +3 -0
- package/bin/templates/plugin/src/main/resources/logo.png +0 -0
- package/bin/templates/plugin/src/theme/views/HelloPage.svelte +26 -0
- package/bin/ui.js +96 -0
- package/package.json +48 -4
- package/src/config.js +191 -0
- package/src/controller/__tests__/controller.test.js +647 -0
- package/src/controller/index.js +604 -0
- package/src/dev.js +208 -0
- package/src/index.js +22 -0
- package/src/rollup/__tests__/controllers/controllers.test.js +418 -0
- package/src/rollup/__tests__/controllers/fixture.js +143 -0
- package/src/rollup/__tests__/controllers/golden/controllers.json +34 -0
- package/src/rollup/__tests__/controllers/golden/controllers.types.js +69 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.json +16 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.lock.json +27 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.with-views.json +54 -0
- package/src/rollup/__tests__/preset/preset.test.js +418 -0
- package/src/rollup/__tests__/rules/_build.js +39 -0
- package/src/rollup/__tests__/rules/_fixture.js +83 -0
- package/src/rollup/__tests__/rules/helpers.test.js +148 -0
- package/src/rollup/__tests__/rules/rules.test.js +259 -0
- package/src/rollup/__tests__/rules/stamp.test.js +113 -0
- package/src/rollup/__tests__/samples/samples.test.js +481 -0
- package/src/rollup/__tests__/seams/config.test.js +78 -0
- package/src/rollup/__tests__/seams/lock.test.js +124 -0
- package/src/rollup/__tests__/seams/sdk-seams.test.js +93 -0
- package/src/rollup/__tests__/seams/stubs.test.js +52 -0
- package/src/rollup/__tests__/views/helpers.js +82 -0
- package/src/rollup/__tests__/views/views.test.js +522 -0
- package/src/rollup/__tests__/widgets/helpers.js +117 -0
- package/src/rollup/__tests__/widgets/widgets.test.js +422 -0
- package/src/rollup/cli-build.js +90 -0
- package/src/rollup/cli-check.js +280 -0
- package/src/rollup/cli-classes.js +75 -0
- package/src/rollup/client-gen.js +67 -0
- package/src/rollup/controllers.js +434 -0
- package/src/rollup/entry.js +250 -0
- package/src/rollup/helpers.js +193 -0
- package/src/rollup/index.js +601 -0
- package/src/rollup/integrate.js +205 -0
- package/src/rollup/lock.js +230 -0
- package/src/rollup/meta.js +479 -0
- package/src/rollup/rules.js +950 -0
- package/src/rollup/samples.js +667 -0
- package/src/rollup/stamp.js +410 -0
- package/src/rollup/types.js +248 -0
- package/src/rollup/views.js +1205 -0
- package/src/rollup/widgets.js +1000 -0
- package/src/styles/__tests__/fallback/__snapshots__/build-fallback-css.test.js.snap +173 -0
- package/src/styles/__tests__/fallback/build-fallback-css.test.js +526 -0
- package/src/styles/__tests__/fallback/fixtures/base.css +247 -0
- package/src/styles/__tests__/fallback/plugins.test.js +301 -0
- package/src/styles/__tests__/lint/check-styles.test.js +423 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.golden.svelte +13 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.in.svelte +13 -0
- package/src/styles/__tests__/lint/semantic-classes.test.js +364 -0
- package/src/styles/bootstrap-classes.js +155 -0
- package/src/styles/check-styles.js +626 -0
- package/src/styles/fallback-css.js +1182 -0
- package/src/styles/plugin-css.js +237 -0
- package/src/styles/scan.js +206 -0
- package/src/styles/semantic-classes.js +436 -0
- package/src/styles/tokens.map.js +53 -0
- package/README.md +0 -3
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { RULE_LEVELS, checkStyles } from '../../check-styles.js';
|
|
6
|
+
|
|
7
|
+
const dirs = [];
|
|
8
|
+
/** Writes `files` ({ 'views/A.svelte': source }) under a fresh plugin root. */
|
|
9
|
+
function plugin(files) {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pano-lint-'));
|
|
11
|
+
dirs.push(root);
|
|
12
|
+
for (const [name, source] of Object.entries(files)) {
|
|
13
|
+
const full = path.join(root, 'src/theme', name);
|
|
14
|
+
fs.mkdirSync(path.dirname(full), { recursive: true });
|
|
15
|
+
fs.writeFileSync(full, source);
|
|
16
|
+
}
|
|
17
|
+
return root;
|
|
18
|
+
}
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
for (const d of dirs) fs.rmSync(d, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function run(files, extra = {}) {
|
|
24
|
+
const root = plugin(files);
|
|
25
|
+
const views = Object.keys(files)
|
|
26
|
+
.filter((f) => f.endsWith('.svelte') && !extra.noViews)
|
|
27
|
+
.map((f) => ({ name: path.basename(f, '.svelte'), file: `src/theme/${f}` }));
|
|
28
|
+
const opts = { root, ns: 'market', views, ...extra };
|
|
29
|
+
delete opts.noViews;
|
|
30
|
+
return {
|
|
31
|
+
core: checkStyles({ ...opts, level: 'core' }),
|
|
32
|
+
badge: checkStyles({ ...opts, level: 'badge' }),
|
|
33
|
+
default: checkStyles(opts),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const ofRule = (list, rule) => list.filter((f) => f.rule === rule);
|
|
37
|
+
|
|
38
|
+
describe('level table', () => {
|
|
39
|
+
test('matches doc 03 section 3', () => {
|
|
40
|
+
expect(RULE_LEVELS).toEqual({
|
|
41
|
+
'class-allowed': { core: 'warn', badge: 'error' },
|
|
42
|
+
'style-block-scope': { core: null, badge: 'error' },
|
|
43
|
+
'style-attr': { core: null, badge: 'error' },
|
|
44
|
+
'no-bs-var': { core: 'warn', badge: 'error' },
|
|
45
|
+
'dynamic-class': { core: 'warn', badge: 'warn' },
|
|
46
|
+
'root-class': { core: null, badge: 'error' },
|
|
47
|
+
'part-coverage': { core: null, badge: 'error' },
|
|
48
|
+
'part-prefix': { core: 'warn', badge: 'error' },
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('level defaults to core and an unknown level throws', () => {
|
|
53
|
+
const { core, default: def } = run({ 'views/A.svelte': '<div class="staff-list">x</div>' });
|
|
54
|
+
expect(def).toEqual(core);
|
|
55
|
+
expect(() => checkStyles({ root: '.', ns: 'market', views: [], level: 'loud' })).toThrow(/core/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a clean view has no finding at either level', () => {
|
|
59
|
+
const clean =
|
|
60
|
+
'<div class="market-a card"><h3 class="market-a__title card-title" style="--w: 3px">t</h3></div>';
|
|
61
|
+
const { core, badge } = run({ 'views/A.svelte': clean });
|
|
62
|
+
expect(core).toEqual([]);
|
|
63
|
+
expect(badge).toEqual([]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('a missing views directory is no finding', () => {
|
|
67
|
+
expect(checkStyles({ root: os.tmpdir(), ns: 'x', views: [], viewsDir: 'does/not/exist' })).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('class-allowed', () => {
|
|
72
|
+
const src = '<div class="market-a card staff-list is-open fa-solid fa-check mb-2">x</div>';
|
|
73
|
+
|
|
74
|
+
test('core warns, badge errors; the message names the class and the next step', () => {
|
|
75
|
+
const { core, badge } = run({ 'views/A.svelte': src });
|
|
76
|
+
for (const [list, level] of [
|
|
77
|
+
[core, 'warn'],
|
|
78
|
+
[badge, 'error'],
|
|
79
|
+
]) {
|
|
80
|
+
const found = ofRule(list, 'class-allowed');
|
|
81
|
+
expect(found.length).toBe(1);
|
|
82
|
+
expect(found[0].level).toBe(level);
|
|
83
|
+
expect(found[0].file).toBe('src/theme/views/A.svelte');
|
|
84
|
+
expect(found[0].line).toBe(1);
|
|
85
|
+
expect(found[0].message).toContain('own class "staff-list"');
|
|
86
|
+
expect(found[0].message).toContain('not covered by fallback.css in a Bootstrap-free theme');
|
|
87
|
+
expect(found[0].message).toContain('market-staff-list');
|
|
88
|
+
expect(found[0].message).toMatch(/\.$/);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('own classes, is- states, Bootstrap and FontAwesome tokens pass', () => {
|
|
93
|
+
const ok =
|
|
94
|
+
'<div class="market-a market-a__x is-sold-out card btn-primary fa-solid fa-check mb-3 gap-2 col-md-6">x</div>';
|
|
95
|
+
expect(ofRule(run({ 'views/A.svelte': ok }).badge, 'class-allowed')).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('class: directives and string literals in class expressions are checked', () => {
|
|
99
|
+
const { badge } = run({
|
|
100
|
+
'views/A.svelte': "<div class={['market-a', 'weird']} class:other={x}>x</div>",
|
|
101
|
+
});
|
|
102
|
+
expect(ofRule(badge, 'class-allowed').map((f) => f.message.match(/"([^"]+)"/)[1])).toEqual([
|
|
103
|
+
'weird',
|
|
104
|
+
'other',
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('another plugin namespace is not an own class', () => {
|
|
109
|
+
const { badge } = run({ 'views/A.svelte': '<div class="shop-thing">x</div>' });
|
|
110
|
+
expect(ofRule(badge, 'class-allowed').length).toBe(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a safelisted class passes', () => {
|
|
114
|
+
const { badge } = run({ 'views/A.svelte': '<div class="market-a staff-list">x</div>' }, { safelist: ['staff-list'] });
|
|
115
|
+
expect(ofRule(badge, 'class-allowed')).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('style-block-scope', () => {
|
|
120
|
+
const view = (style) => `<div class="market-a">x</div>\n<style>\n${style}\n</style>`;
|
|
121
|
+
const scope = (style, extra) => ofRule(run({ 'views/A.svelte': view(style) }, extra).badge, 'style-block-scope');
|
|
122
|
+
|
|
123
|
+
test('off at core', () => {
|
|
124
|
+
expect(ofRule(run({ 'views/A.svelte': view('p { color: red; }') }).core, 'style-block-scope')).toEqual([]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('a selector without the namespace class is an error with a line and a next step', () => {
|
|
128
|
+
const found = scope(' .x { color: red; }');
|
|
129
|
+
expect(found.length).toBe(1);
|
|
130
|
+
expect(found[0].level).toBe('error');
|
|
131
|
+
expect(found[0].line).toBe(3);
|
|
132
|
+
expect(found[0].message).toContain('".x"');
|
|
133
|
+
expect(found[0].message).toMatch(/start every selector with a class like \.market-name/);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('own classes, with .is-state, descendants and media queries pass', () => {
|
|
137
|
+
const css = [
|
|
138
|
+
' .market-a { color: var(--pano-color-primary); }',
|
|
139
|
+
' .market-a.is-open .inner, .market-a__body > p { margin: 0; }',
|
|
140
|
+
' @media (min-width: 600px) { .market-a { padding: 1rem; } }',
|
|
141
|
+
' @keyframes market-fade { from { opacity: 0 } 50% { opacity: .5 } to { opacity: 1 } }',
|
|
142
|
+
' .market-a { --market-gap: 1px; animation: market-fade 1s; }',
|
|
143
|
+
' .market-a { &:hover { color: red; } }',
|
|
144
|
+
].join('\n');
|
|
145
|
+
expect(scope(css)).toEqual([]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('every selector of a list needs the namespace class', () => {
|
|
149
|
+
expect(scope(' .market-a, .other { color: red; }').length).toBe(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a class of another namespace does not count', () => {
|
|
153
|
+
expect(scope(' .shop-a { color: red; }').length).toBe(1);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test(':global is an error', () => {
|
|
157
|
+
const found = scope(' :global(body) .market-a { color: red; }\n :global(.x) { color: blue; }');
|
|
158
|
+
expect(found.some((f) => f.message.includes(':global'))).toBe(true);
|
|
159
|
+
expect(found.every((f) => f.level === 'error')).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('keyframes must be named after the plugin', () => {
|
|
163
|
+
const found = scope(' @keyframes pulse { from { opacity: 0 } to { opacity: 1 } }');
|
|
164
|
+
expect(found.length).toBe(1);
|
|
165
|
+
expect(found[0].message).toContain('keyframes "pulse"');
|
|
166
|
+
expect(found[0].message).toContain('market-pulse');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('own custom properties must be --<ns>-...', () => {
|
|
170
|
+
const found = scope(' .market-a { --gap: 1px; --market-ok: 2px; }');
|
|
171
|
+
expect(found.length).toBe(1);
|
|
172
|
+
expect(found[0].message).toContain('"--gap"');
|
|
173
|
+
expect(found[0].message).toContain('--market-gap');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('var(--bs-...) stays no-bs-var', () => {
|
|
177
|
+
const { badge } = run({ 'views/A.svelte': view(' .market-a { color: var(--bs-primary); }') });
|
|
178
|
+
expect(ofRule(badge, 'no-bs-var').length).toBe(1);
|
|
179
|
+
expect(ofRule(badge, 'style-block-scope')).toEqual([]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('a view without a style block has no finding', () => {
|
|
183
|
+
expect(ofRule(run({ 'views/A.svelte': '<div class="market-a">x</div>' }).badge, 'style-block-scope')).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('style-attr', () => {
|
|
188
|
+
test('off at core; at badge only custom properties are allowed', () => {
|
|
189
|
+
const files = {
|
|
190
|
+
'views/Bad.svelte': '<div class="market-bad" style="width: 10px">x</div>',
|
|
191
|
+
'views/Good.svelte': '<div class="market-good" style="--w: {pct}%; --h: 2px">x</div>',
|
|
192
|
+
'views/GoodExpr.svelte': '<div class="market-good-expr" style={`--w: ${pct}%`}>x</div>',
|
|
193
|
+
'views/Dir.svelte': '<div class="market-dir" style:--w={pct} style:color={c}>x</div>',
|
|
194
|
+
'views/Mixed.svelte': '<div class="market-mixed" style="--w: 1px; color: red">x</div>',
|
|
195
|
+
'views/Dyn.svelte': '<div class="market-dyn" style={s}>x</div>',
|
|
196
|
+
};
|
|
197
|
+
const { core, badge } = run(files);
|
|
198
|
+
expect(ofRule(core, 'style-attr')).toEqual([]);
|
|
199
|
+
const found = ofRule(badge, 'style-attr');
|
|
200
|
+
expect(found.map((f) => path.basename(f.file)).sort()).toEqual([
|
|
201
|
+
'Bad.svelte',
|
|
202
|
+
'Dir.svelte',
|
|
203
|
+
'Dyn.svelte',
|
|
204
|
+
'Mixed.svelte',
|
|
205
|
+
]);
|
|
206
|
+
expect(found.every((f) => f.level === 'error')).toBe(true);
|
|
207
|
+
expect(found[0].message).toContain('styleAttrAllow');
|
|
208
|
+
expect(found.find((f) => f.file.endsWith('Dir.svelte')).message).toContain('style:color');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('a file in styleAttrAllow may set any property (by base name, file name or path)', () => {
|
|
212
|
+
const files = { 'views/CategoryNode.svelte': '<li class="market-category-node" style="padding-left: 4px">x</li>' };
|
|
213
|
+
for (const allow of ['CategoryNode', 'CategoryNode.svelte', 'src/theme/views/CategoryNode.svelte']) {
|
|
214
|
+
expect(ofRule(run(files, { styleAttrAllow: [allow] }).badge, 'style-attr')).toEqual([]);
|
|
215
|
+
}
|
|
216
|
+
expect(ofRule(run(files).badge, 'style-attr').length).toBe(1);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('no-bs-var', () => {
|
|
221
|
+
const files = {
|
|
222
|
+
'views/A.svelte':
|
|
223
|
+
'<div class="market-a" style="--c: var(--bs-primary)">x</div>\n<style>\n .x { color: var(--bs-body-color); }\n</style>',
|
|
224
|
+
'views/B.svelte': '<div class="market-b" style="color: var(--pano-color-text)">x</div>',
|
|
225
|
+
};
|
|
226
|
+
test('core warns, badge errors, for style= and <style>', () => {
|
|
227
|
+
const { core, badge } = run(files);
|
|
228
|
+
const warn = ofRule(core, 'no-bs-var');
|
|
229
|
+
const err = ofRule(badge, 'no-bs-var');
|
|
230
|
+
expect(warn.length).toBe(2);
|
|
231
|
+
expect(err.length).toBe(2);
|
|
232
|
+
expect(warn.every((f) => f.level === 'warn' && f.file.endsWith('A.svelte'))).toBe(true);
|
|
233
|
+
expect(err.every((f) => f.level === 'error')).toBe(true);
|
|
234
|
+
expect(err.map((f) => f.line)).toEqual([1, 3]);
|
|
235
|
+
expect(err[0].message).toContain('var(--bs-primary)');
|
|
236
|
+
expect(err[0].message).toContain('--pano-*');
|
|
237
|
+
expect(err[0].message).toMatch(/\.$/);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('dynamic-class', () => {
|
|
242
|
+
test('a non-literal member whose values cannot be found is a warning at both levels', () => {
|
|
243
|
+
const src = '<script>let { icon } = $props();</script>\n<i class={[\'market-a\', icon]}></i>';
|
|
244
|
+
const { core, badge } = run({ 'views/A.svelte': src });
|
|
245
|
+
for (const list of [core, badge]) {
|
|
246
|
+
const found = ofRule(list, 'dynamic-class');
|
|
247
|
+
expect(found.length).toBe(1);
|
|
248
|
+
expect(found[0].level).toBe('warn');
|
|
249
|
+
expect(found[0].line).toBe(2);
|
|
250
|
+
expect(found[0].message).toContain('"icon"');
|
|
251
|
+
expect(found[0].message).toContain('styles.safelist');
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('values found in the file script or in a helper under viewsDir are resolved', () => {
|
|
256
|
+
const files = {
|
|
257
|
+
'views/A.svelte':
|
|
258
|
+
"<script>import { badgeFor } from '../lib/badges.js'; const STATUS = { paid: 'text-bg-success', open: 'text-bg-warning' }; let { s } = $props();</script>\n" +
|
|
259
|
+
'<span class={[\'market-a\', STATUS[s], badgeFor(s)]}></span>',
|
|
260
|
+
'lib/badges.js': "export function badgeFor(s) { return s ? 'text-bg-primary' : 'text-bg-secondary'; }\n",
|
|
261
|
+
};
|
|
262
|
+
expect(ofRule(run(files).core, 'dynamic-class')).toEqual([]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('a prefix is resolved by a literal in a script or by the safelist', () => {
|
|
266
|
+
const tpl = '<script>let { v } = $props();</script>\n<button class="market-a btn btn-{v}">x</button>';
|
|
267
|
+
expect(ofRule(run({ 'views/A.svelte': tpl }).core, 'dynamic-class').length).toBe(1);
|
|
268
|
+
expect(ofRule(run({ 'views/A.svelte': tpl }, { safelist: ['btn-primary'] }).core, 'dynamic-class')).toEqual([]);
|
|
269
|
+
const withLiteral = tpl.replace('let { v }', "const V = ['btn-primary', 'btn-danger']; let { v }");
|
|
270
|
+
expect(ofRule(run({ 'views/A.svelte': withLiteral }).core, 'dynamic-class')).toEqual([]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('template literals and concatenation are dynamic members with a prefix', () => {
|
|
274
|
+
const src =
|
|
275
|
+
'<script>let { v } = $props();</script>\n<div class={`market-a btn-${v}`}></div><div class={"market-a " + v}></div>';
|
|
276
|
+
const found = ofRule(run({ 'views/A.svelte': src }).core, 'dynamic-class');
|
|
277
|
+
expect(found.length).toBe(2);
|
|
278
|
+
expect(found[0].message).toContain('start with "btn-"');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('literal members, conditionals of literals and object keys are fine', () => {
|
|
282
|
+
const src =
|
|
283
|
+
"<div class={['market-a', on && 'is-on', big ? 'is-big' : 'is-small', { 'is-x': y }, false]}></div>";
|
|
284
|
+
expect(ofRule(run({ 'views/A.svelte': src }).core, 'dynamic-class')).toEqual([]);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('dynamicClassAllow exempts a named view when the expression has no literal prefix', () => {
|
|
288
|
+
const src = '<script>let { cls } = $props();</script>\n<div class={cls}></div>';
|
|
289
|
+
const files = { 'views/A.svelte': src, 'views/B.svelte': src };
|
|
290
|
+
const free = run(files);
|
|
291
|
+
expect(ofRule(free.core, 'dynamic-class').length).toBe(2);
|
|
292
|
+
const allowed = run(files, { dynamicClassAllow: ['A'] });
|
|
293
|
+
const left = ofRule(allowed.core, 'dynamic-class');
|
|
294
|
+
expect(left.length).toBe(1);
|
|
295
|
+
expect(left[0].file).toContain('B.svelte');
|
|
296
|
+
expect(left[0].message).toContain('styles.dynamicClassAllow');
|
|
297
|
+
expect(ofRule(allowed.badge, 'dynamic-class').map((f) => f.file)).toEqual(left.map((f) => f.file));
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('dynamicClassAllow does not hide an expression with a literal prefix', () => {
|
|
301
|
+
const src = '<script>let { v } = $props();</script>\n<div class={`btn-${v}`}></div>';
|
|
302
|
+
expect(ofRule(run({ 'views/A.svelte': src }, { dynamicClassAllow: ['A'] }).core, 'dynamic-class').length).toBe(1);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('root-class', () => {
|
|
307
|
+
test('off at core; at badge each registered view needs its root class in source', () => {
|
|
308
|
+
const files = {
|
|
309
|
+
'views/ProductCard.svelte': '<div class="card">x</div>',
|
|
310
|
+
'views/Done.svelte': '<div class="market-done card">x</div>',
|
|
311
|
+
'views/Branches.svelte': '{#if a}<div class="market-branches">a</div>{:else}<p>b</p>{/if}',
|
|
312
|
+
};
|
|
313
|
+
const { core, badge } = run(files);
|
|
314
|
+
expect(ofRule(core, 'root-class')).toEqual([]);
|
|
315
|
+
const found = ofRule(badge, 'root-class');
|
|
316
|
+
expect(found.map((f) => path.basename(f.file)).sort()).toEqual(['Branches.svelte', 'ProductCard.svelte']);
|
|
317
|
+
const card = found.find((f) => f.file.endsWith('ProductCard.svelte'));
|
|
318
|
+
expect(card.level).toBe('error');
|
|
319
|
+
expect(card.message).toContain('"market-product-card"');
|
|
320
|
+
expect(card.message).toContain('pano-plugin classes --fix');
|
|
321
|
+
expect(found.find((f) => f.file.endsWith('Branches.svelte')).message).toContain('<p>');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test('files that are not registered views are not checked', () => {
|
|
325
|
+
const { badge } = run({ 'components/Sub.svelte': '<div class="card">x</div>' }, { noViews: true });
|
|
326
|
+
expect(ofRule(badge, 'root-class')).toEqual([]);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test('a view without an element root is a warning that says to wrap it', () => {
|
|
330
|
+
const { core, badge } = run({ 'views/Wrap.svelte': '<script>import C from "./C.svelte";</script><C />' });
|
|
331
|
+
expect(ofRule(core, 'root-class')).toEqual([]);
|
|
332
|
+
const found = ofRule(badge, 'root-class');
|
|
333
|
+
expect(found.length).toBe(1);
|
|
334
|
+
expect(found[0].level).toBe('warn');
|
|
335
|
+
expect(found[0].message).toContain('wrap it in an element');
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
describe('part-coverage', () => {
|
|
340
|
+
const files = {
|
|
341
|
+
'views/A.svelte':
|
|
342
|
+
'<div class="market-a">\n <div class="card-body">x</div>\n <h3 class="market-a__title card-title">t</h3>\n <button class="btn btn-primary">go</button>\n</div>',
|
|
343
|
+
};
|
|
344
|
+
test('off at core; at badge each Bootstrap component class needs a part class', () => {
|
|
345
|
+
const { core, badge } = run(files);
|
|
346
|
+
expect(ofRule(core, 'part-coverage')).toEqual([]);
|
|
347
|
+
const found = ofRule(badge, 'part-coverage');
|
|
348
|
+
expect(found.map((f) => f.line)).toEqual([2, 4]);
|
|
349
|
+
expect(found.every((f) => f.level === 'error')).toBe(true);
|
|
350
|
+
expect(found[0].message).toContain('market-a__body');
|
|
351
|
+
expect(found[1].message).toContain('market-a__action');
|
|
352
|
+
expect(found[0].message).toContain('pano-plugin classes --fix');
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test('utility-only elements need no part class', () => {
|
|
356
|
+
const { badge } = run({ 'views/A.svelte': '<div class="market-a"><p class="mb-2 d-flex">x</p></div>' });
|
|
357
|
+
expect(ofRule(badge, 'part-coverage')).toEqual([]);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('the generator output passes the rule', async () => {
|
|
361
|
+
const { addPartClasses, addRootClass } = await import('../../semantic-classes.js');
|
|
362
|
+
const input = fs.readFileSync(path.join(import.meta.dir, 'fixtures/ProductCard.in.svelte'), 'utf8');
|
|
363
|
+
const ctx = { ns: 'market', view: 'ProductCard' };
|
|
364
|
+
const fixed = addPartClasses(addRootClass(input, ctx).code, ctx).code;
|
|
365
|
+
const { badge } = run({ 'views/ProductCard.svelte': fixed });
|
|
366
|
+
expect(ofRule(badge, 'part-coverage')).toEqual([]);
|
|
367
|
+
expect(ofRule(badge, 'root-class')).toEqual([]);
|
|
368
|
+
expect(ofRule(badge, 'part-prefix')).toEqual([]);
|
|
369
|
+
expect(ofRule(badge, 'class-allowed')).toEqual([]);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('part-prefix', () => {
|
|
374
|
+
const files = { 'views/ProductCard.svelte': '<div class="market-product-card"><i class="market-order__icon">x</i></div>' };
|
|
375
|
+
test('a part class must start with the root class of its file: warn at core, error at badge', () => {
|
|
376
|
+
const { core, badge } = run(files);
|
|
377
|
+
const warn = ofRule(core, 'part-prefix');
|
|
378
|
+
const err = ofRule(badge, 'part-prefix');
|
|
379
|
+
expect(warn.length).toBe(1);
|
|
380
|
+
expect(err.length).toBe(1);
|
|
381
|
+
expect(warn[0].level).toBe('warn');
|
|
382
|
+
expect(err[0].level).toBe('error');
|
|
383
|
+
expect(err[0].message).toContain('"market-order__icon"');
|
|
384
|
+
expect(err[0].message).toContain('market-product-card__icon');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
test('a file that is not a registered view uses its own file name', () => {
|
|
388
|
+
const f = { 'components/Row.svelte': '<tr class="market-row__cell"><td class="market-other__cell">x</td></tr>' };
|
|
389
|
+
const { badge } = run(f, { noViews: true });
|
|
390
|
+
const found = ofRule(badge, 'part-prefix');
|
|
391
|
+
expect(found.length).toBe(1);
|
|
392
|
+
expect(found[0].message).toContain('"market-other__cell"');
|
|
393
|
+
expect(found[0].message).toContain('market-row__');
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
describe('messages', () => {
|
|
398
|
+
test('every message ends with a next step', () => {
|
|
399
|
+
const files = {
|
|
400
|
+
'views/A.svelte':
|
|
401
|
+
'<script>let { icon } = $props();</script>\n<div class="staff-list card-body" style="width: 1px; color: var(--bs-primary)"><i class={icon}></i></div>\n<style>p { color: var(--bs-body-color) }</style>',
|
|
402
|
+
'views/Wrap.svelte': '<A />',
|
|
403
|
+
};
|
|
404
|
+
const { badge } = run(files);
|
|
405
|
+
const rules = new Set(badge.map((f) => f.rule));
|
|
406
|
+
for (const rule of ['class-allowed', 'style-block-scope', 'style-attr', 'no-bs-var', 'dynamic-class', 'root-class', 'part-coverage'])
|
|
407
|
+
expect(rules.has(rule), rule).toBe(true);
|
|
408
|
+
for (const f of badge) {
|
|
409
|
+
expect(f.message, f.rule).toMatch(/ — .+\.$/);
|
|
410
|
+
expect(['error', 'warn']).toContain(f.level);
|
|
411
|
+
expect(f.line).toBeGreaterThan(0);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
test('findings are sorted by file and line', () => {
|
|
416
|
+
const { badge } = run({
|
|
417
|
+
'views/B.svelte': '<div class="x-b">x</div>',
|
|
418
|
+
'views/A.svelte': '<div class="x-a">x</div>\n<div class="x-c">y</div>',
|
|
419
|
+
});
|
|
420
|
+
const keys = badge.map((f) => `${f.file}:${String(f.line).padStart(4, '0')}`);
|
|
421
|
+
expect(keys).toEqual([...keys].sort());
|
|
422
|
+
});
|
|
423
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { _ } from 'svelte-i18n';
|
|
3
|
+
|
|
4
|
+
let { product, add } = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class={['market-product-card', 'card', 'h-100', { 'is-sold-out': !product.inStock }]}>
|
|
8
|
+
<div class="market-product-card__body card-body d-flex flex-column gap-1">
|
|
9
|
+
<h3 class="market-product-card__title h6 card-title mb-0 text-truncate">{product.name}</h3>
|
|
10
|
+
<a class="market-product-card__action btn btn-outline-secondary btn-sm w-100" href={product.url}>{$_('theme.store.details')}</a>
|
|
11
|
+
<button class="market-product-card__add-to-cart btn btn-primary btn-sm w-100" onclick={add}>{$_('theme.store.addToCart')}</button>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { _ } from 'svelte-i18n';
|
|
3
|
+
|
|
4
|
+
let { product, add } = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class={['card', 'h-100', { 'is-sold-out': !product.inStock }]}>
|
|
8
|
+
<div class="card-body d-flex flex-column gap-1">
|
|
9
|
+
<h3 class="h6 card-title mb-0 text-truncate">{product.name}</h3>
|
|
10
|
+
<a class="btn btn-outline-secondary btn-sm w-100" href={product.url}>{$_('theme.store.details')}</a>
|
|
11
|
+
<button class="btn btn-primary btn-sm w-100" onclick={add}>{$_('theme.store.addToCart')}</button>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|