@alis-build/design-system 0.52.1 → 0.53.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 +11 -5
- package/check.mjs +64 -10
- package/package.json +1 -1
- package/rules/styling.md +2 -1
- package/stylelint.mjs +26 -2
package/README.md
CHANGED
|
@@ -54,14 +54,15 @@ subfolder, the rules are under that folder's `node_modules`. Never copy the
|
|
|
54
54
|
rules into your repo: a copy stops moving with the version.
|
|
55
55
|
|
|
56
56
|
**2. Check your styles.** Add `stylelint` (16.11 or later) as a dev dependency,
|
|
57
|
-
with `postcss-html` if you have
|
|
58
|
-
|
|
59
|
-
skipped, silently).
|
|
57
|
+
with `postcss-html` if you have Svelte, Vue, HTML or templ files (it reads
|
|
58
|
+
their `<style>` blocks and static `style=""` attributes) and `postcss-scss` if
|
|
59
|
+
any block is `lang="scss"` (without it those blocks are skipped, silently).
|
|
60
|
+
Then in `stylelint.config.js`:
|
|
60
61
|
|
|
61
62
|
```js
|
|
62
63
|
export default {
|
|
63
64
|
extends: ['@alis-build/design-system/stylelint'],
|
|
64
|
-
overrides: [{ files: ['**/*.svelte', '**/*.vue'], customSyntax: 'postcss-html' }],
|
|
65
|
+
overrides: [{ files: ['**/*.svelte', '**/*.vue', '**/*.html', '**/*.templ'], customSyntax: 'postcss-html' }],
|
|
65
66
|
}
|
|
66
67
|
```
|
|
67
68
|
|
|
@@ -109,7 +110,9 @@ export default {
|
|
|
109
110
|
rule on that line), gives no reason, or silences nothing.
|
|
110
111
|
|
|
111
112
|
- It reads what is written in CSS. A value held in a Sass variable or a mixin,
|
|
112
|
-
or a literal behind a custom property of your own (`--pad: 13px`), is not seen
|
|
113
|
+
or a literal behind a custom property of your own (`--pad: 13px`), is not seen,
|
|
114
|
+
and nor is a bound style (`:style`, `style={ … }`). A templ `css` component
|
|
115
|
+
can't be read at all, so `alisx-check styles` stops on one.
|
|
113
116
|
|
|
114
117
|
**3. Run the checks in your build.**
|
|
115
118
|
|
|
@@ -143,6 +146,9 @@ export default {
|
|
|
143
146
|
- `alisx-check words` fails on a name `words.json` has retired ("idea" for a
|
|
144
147
|
project, "Access and ownership" for Sharing) in text a person reads: text
|
|
145
148
|
between tags, and quoted text that holds a space or starts with a capital.
|
|
149
|
+
In a templ file the Go is code, read as script is: outside a component, its
|
|
150
|
+
`if`, `for`, `switch` and `case` lines, and an `@Component(…)` call's
|
|
151
|
+
arguments.
|
|
146
152
|
Its baseline, `alisx-words-baseline.json`, works as the styles one does. A
|
|
147
153
|
use that must stay is marked on its line or the line above:
|
|
148
154
|
`alisx-words-ignore -- the reason`.
|
package/check.mjs
CHANGED
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
// person reads. Lines of the field code or alias are code, and so is what
|
|
42
42
|
// is in backticks, a printf verb (%s) or a placeholder (<id>). The baseline
|
|
43
43
|
// counts each block's place, so one gaining a retired name fails.
|
|
44
|
+
//
|
|
45
|
+
// Svelte, Vue, HTML and templ files are read as markup. In templ, the Go is
|
|
46
|
+
// script: outside a component, and inside one its statement lines (if, for,
|
|
47
|
+
// switch, case) and the arguments of an @Component(…) call.
|
|
44
48
|
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
45
49
|
import { spawnSync } from 'node:child_process'
|
|
46
50
|
import { tmpdir } from 'node:os'
|
|
@@ -81,7 +85,7 @@ function names() {
|
|
|
81
85
|
const prefixes = (options.prefix.length ? options.prefix : ['app-', 'text-']).map(escape).join('|')
|
|
82
86
|
const allowed = options.allow.map((glob) => new RegExp(`^${glob.split('*').map(escape).join('.*')}$`))
|
|
83
87
|
|
|
84
|
-
const sources = ['.svelte', '.vue', '.html', '.jsx', '.tsx', '.js', '.ts', '.mjs', '.css', '.scss', '.less']
|
|
88
|
+
const sources = ['.svelte', '.vue', '.html', '.templ', '.jsx', '.tsx', '.js', '.ts', '.mjs', '.css', '.scss', '.less']
|
|
85
89
|
const missing = [...paths, ...options.declared].filter((path) => !existsSync(path))
|
|
86
90
|
if (missing.length) stop(`alisx-check names: no such path: ${missing.join(', ')}`)
|
|
87
91
|
const files = paths.flatMap((path) => walk(resolve(path))).filter((file) => sources.includes(extname(file)))
|
|
@@ -172,10 +176,16 @@ function styles() {
|
|
|
172
176
|
for (const each of result.invalidOptionWarnings ?? []) broken.push(each.text)
|
|
173
177
|
for (const each of result.parseErrors ?? []) broken.push(`${result.source}: ${each.text}`)
|
|
174
178
|
for (const each of result.warnings) if (each.rule === 'CssSyntaxError') broken.push(`${result.source}:${each.line}: ${each.text}`)
|
|
179
|
+
// A templ css component is a stylesheet stylelint can't parse out of Go.
|
|
180
|
+
if (extname(result.source) === '.templ') {
|
|
181
|
+
const text = readFileSync(result.source, 'utf8')
|
|
182
|
+
for (const match of text.matchAll(/^css\s+\w+/gm))
|
|
183
|
+
broken.push(`${result.source}:${text.slice(0, match.index).split('\n').length}: a templ css component is not read. Write it in a stylesheet or a <style> block.`)
|
|
184
|
+
}
|
|
175
185
|
}
|
|
176
186
|
if (broken.length)
|
|
177
187
|
stop(
|
|
178
|
-
`alisx-check styles: the check could not run as configured, so nothing was compared.\n\n ${[...new Set(broken)].join('\n ')}\n\nA
|
|
188
|
+
`alisx-check styles: the check could not run as configured, so nothing was compared.\n\n ${[...new Set(broken)].join('\n ')}\n\nA Svelte, Vue, HTML or templ file needs its syntax in your stylelint config (postcss-html; postcss-scss for lang="scss").`,
|
|
179
189
|
)
|
|
180
190
|
|
|
181
191
|
// Keyed by the file's path from the baseline's own directory, so the same
|
|
@@ -255,7 +265,7 @@ function words() {
|
|
|
255
265
|
.sort((a, b) => b.text.length - a.text.length)
|
|
256
266
|
.map((each) => ({ ...each, pattern: new RegExp(`(?<![\\w./-])${escape(each.text).replace(/ /g, '\\s+')}(?![\\w/-]|\\.\\w)`, 'gi') }))
|
|
257
267
|
|
|
258
|
-
const sources = ['.svelte', '.vue', '.html', '.jsx', '.tsx', '.js', '.ts', '.mjs']
|
|
268
|
+
const sources = ['.svelte', '.vue', '.html', '.templ', '.jsx', '.tsx', '.js', '.ts', '.mjs']
|
|
259
269
|
const missing = paths.filter((path) => !existsSync(path))
|
|
260
270
|
if (missing.length) stop(`alisx-check words: no such path: ${missing.join(', ')}`)
|
|
261
271
|
const files = paths
|
|
@@ -357,23 +367,29 @@ function readable(text, ext) {
|
|
|
357
367
|
const human = (value) => /[A-Za-z]/.test(value) && (/\S\s+\S/.test(value) || /^\s*[A-Z][a-z]/.test(value))
|
|
358
368
|
// What a log or a console prints is read by nobody on screen.
|
|
359
369
|
const script = (code, offset) => quoted(unlogged(code), (start, value) => human(value) && pieces.push({ start: offset + start, value }))
|
|
360
|
-
if (!['.vue', '.svelte', '.html'].includes(ext)) {
|
|
370
|
+
if (!['.vue', '.svelte', '.html', '.templ'].includes(ext)) {
|
|
361
371
|
script(text, 0)
|
|
362
372
|
return pieces
|
|
363
373
|
}
|
|
364
374
|
|
|
365
375
|
// Script blocks are script; style blocks and comments are nobody's text.
|
|
366
376
|
const blank = (match) => match.replace(/[^\n]/g, ' ')
|
|
367
|
-
let markup =
|
|
377
|
+
let markup = ext === '.templ' ? templ(text, script, blank) : text
|
|
378
|
+
markup = markup.replace(/<!--[\s\S]*?-->/g, blank).replace(/<style\b[\s\S]*?<\/style>/gi, blank)
|
|
368
379
|
markup = markup.replace(/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi, (match, open, code, close, index) => {
|
|
369
380
|
script(code, index + open.length)
|
|
370
381
|
return blank(match)
|
|
371
382
|
})
|
|
372
|
-
// An expression in markup ({{ … }} or { … }) is script.
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
383
|
+
// An expression in markup ({{ … }} or { … }) is script. A templ expression
|
|
384
|
+
// may hold a Go literal's braces (Props{…}), so its file is read until none is left.
|
|
385
|
+
for (let before = null; before !== markup; ) {
|
|
386
|
+
before = markup
|
|
387
|
+
markup = markup.replace(/\{\{([\s\S]*?)\}\}|\{([^{}]*)\}/g, (match, mustache, single, index) => {
|
|
388
|
+
script(mustache ?? single, index + (mustache === undefined ? 1 : 2))
|
|
389
|
+
return blank(match)
|
|
390
|
+
})
|
|
391
|
+
if (ext !== '.templ') break
|
|
392
|
+
}
|
|
377
393
|
// An attribute: code when bound (:x, @x, #x, v-x, on:x, bind:x), nobody's
|
|
378
394
|
// text when it names a class, a route or a key; otherwise it may be read.
|
|
379
395
|
const code = /^(?:[:@#]|v-|on:|bind:)/
|
|
@@ -389,6 +405,44 @@ function readable(text, ext) {
|
|
|
389
405
|
return pieces
|
|
390
406
|
}
|
|
391
407
|
|
|
408
|
+
// A templ file as markup, every offset kept. Go outside a component (package,
|
|
409
|
+
// import, func, var) is script. Inside one, a statement line (if, for, switch,
|
|
410
|
+
// case, a closing brace) is script and leaves its markup; @Component(…) is a
|
|
411
|
+
// call, so its name is blanked and its arguments are script. The braces a line
|
|
412
|
+
// leaves would otherwise read as one expression around the markup it holds,
|
|
413
|
+
// and the text in it would go unread. A component starts at `templ Name(…) {`
|
|
414
|
+
// and ends at the `}` that starts a line, as templ fmt writes it.
|
|
415
|
+
function templ(text, script, blank) {
|
|
416
|
+
const out = []
|
|
417
|
+
let go = 0 // where the Go outside a component starts; null inside one
|
|
418
|
+
let at = 0
|
|
419
|
+
for (const line of text.split('\n')) {
|
|
420
|
+
const start = at
|
|
421
|
+
at += line.length + 1
|
|
422
|
+
const trimmed = line.trim()
|
|
423
|
+
if (go !== null) {
|
|
424
|
+
if (/^templ\s.*\{\s*$/.test(line)) {
|
|
425
|
+
script(text.slice(go, start), go)
|
|
426
|
+
go = null
|
|
427
|
+
}
|
|
428
|
+
out.push(blank(line))
|
|
429
|
+
} else if (/^\}/.test(line)) {
|
|
430
|
+
go = at
|
|
431
|
+
out.push(blank(line))
|
|
432
|
+
} else if (/^\/\//.test(trimmed)) out.push(blank(line))
|
|
433
|
+
else if (/^(?:if|for|switch|case|default)\b|^\}\s*(?:else\b.*)?$/.test(trimmed)) {
|
|
434
|
+
script(line, start)
|
|
435
|
+
out.push(blank(line))
|
|
436
|
+
} else if (/^@[\w.]+/.test(trimmed)) {
|
|
437
|
+
const call = line.indexOf('@') + /^@[\w.]+/.exec(trimmed)[0].length
|
|
438
|
+
script(' '.repeat(call) + line.slice(call), start)
|
|
439
|
+
out.push(blank(line))
|
|
440
|
+
} else out.push(line)
|
|
441
|
+
}
|
|
442
|
+
if (go !== null) script(text.slice(go), go)
|
|
443
|
+
return out.join('\n')
|
|
444
|
+
}
|
|
445
|
+
|
|
392
446
|
// The text in a words file a person reads, each line with where it starts and
|
|
393
447
|
// the place its block names. A code span that a long line wrapped carries on
|
|
394
448
|
// to the next line of its block.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alis-build/design-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "The AlisX design system for coding agents: tokens, product CSS, component markup, capability marks, words and rules.",
|
|
5
5
|
"keywords": ["alisx", "design-system", "design-tokens", "css"],
|
|
6
6
|
"homepage": "https://alisx.com",
|
package/rules/styling.md
CHANGED
|
@@ -96,7 +96,8 @@ The package ships what can be linted, so every app checks the same things
|
|
|
96
96
|
radius and shadow written without their tokens, local type, a forced
|
|
97
97
|
priority, and a selector on a system class. It reads the token and class
|
|
98
98
|
names from the package, so a new token needs no edit to the check. In a
|
|
99
|
-
Svelte or
|
|
99
|
+
Svelte, Vue, HTML or templ file it reads the `<style>` block and a static
|
|
100
|
+
`style=""`, under the same rules.
|
|
100
101
|
- **A gap is said where it is**, by rule and with a reason:
|
|
101
102
|
`/* stylelint-disable-next-line <rule> -- GAP: what this needs */`. A disable
|
|
102
103
|
is itself reported when it names no rule, gives no reason, or silences
|
package/stylelint.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
//
|
|
10
10
|
// export default {
|
|
11
11
|
// extends: ['@alis-build/design-system/stylelint'],
|
|
12
|
-
// overrides: [{ files: ['**/*.svelte', '**/*.vue'], customSyntax: 'postcss-html' }],
|
|
12
|
+
// overrides: [{ files: ['**/*.svelte', '**/*.vue', '**/*.html', '**/*.templ'], customSyntax: 'postcss-html' }],
|
|
13
13
|
// }
|
|
14
14
|
//
|
|
15
15
|
// A rule you set under the same name REPLACES the system's: stylelint never
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
// A disable is itself reported when it names no rule (it would silence every
|
|
25
25
|
// rule on that line), gives no reason after `--`, or silences nothing.
|
|
26
26
|
import { readFileSync } from 'node:fs'
|
|
27
|
+
import stylelint from 'stylelint'
|
|
27
28
|
|
|
28
29
|
export const guide = 'rules/styling.md in @alis-build/design-system'
|
|
29
30
|
|
|
@@ -114,12 +115,33 @@ export const allowed = {
|
|
|
114
115
|
/** Every allowed part, as the default config uses them. */
|
|
115
116
|
export const allowedValues = Object.values(allowed)
|
|
116
117
|
|
|
117
|
-
/** Type belongs to a text-* class. Refused in a rule; an @font-face is
|
|
118
|
+
/** Type belongs to a text-* class. Refused in a rule and in a style attribute; an @font-face is neither. */
|
|
118
119
|
export const refusedProperties = {
|
|
119
120
|
properties: ['font', 'font-family', 'font-size', 'font-weight', 'font-variation-settings', 'line-height', 'letter-spacing', 'text-transform', 'text-shadow'],
|
|
120
121
|
message: (selector, property) => `${property} is appearance: a text-* class carries type (${guide}).`,
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
// rule-selector-property-disallowed-list reads a declaration only inside a rule,
|
|
125
|
+
// so a static style="" (a stylesheet without the tag, styling.md) needs its own:
|
|
126
|
+
// a declaration with no rule or at-rule around it is one an attribute holds.
|
|
127
|
+
// Nothing in a rule is read here, so nothing is reported twice.
|
|
128
|
+
const inlineType = 'alisx/inline-type'
|
|
129
|
+
const inlineTypeRule = (on) => (root, result) => {
|
|
130
|
+
if (!on) return
|
|
131
|
+
root.walkDecls((declaration) => {
|
|
132
|
+
if (declaration.parent?.type !== 'root' || !refusedProperties.properties.includes(declaration.prop.toLowerCase())) return
|
|
133
|
+
stylelint.utils.report({
|
|
134
|
+
ruleName: inlineType,
|
|
135
|
+
result,
|
|
136
|
+
node: declaration,
|
|
137
|
+
word: declaration.prop,
|
|
138
|
+
message: `${declaration.prop} in a style attribute is appearance: a text-* class carries type (${guide}).`,
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
inlineTypeRule.ruleName = inlineType
|
|
143
|
+
inlineTypeRule.messages = {}
|
|
144
|
+
|
|
123
145
|
/** A site never restyles a system class. Exact names, so .app-bar-search of your own is yours. */
|
|
124
146
|
export const refusedSelectors = {
|
|
125
147
|
selectors: [new RegExp(`\\.(?:${escaped(systemClasses)})(?![\\w-])`)],
|
|
@@ -169,6 +191,7 @@ export default {
|
|
|
169
191
|
reportDescriptionlessDisables: true,
|
|
170
192
|
reportUnscopedDisables: true,
|
|
171
193
|
reportNeedlessDisables: true,
|
|
194
|
+
plugins: [stylelint.createPlugin(inlineType, inlineTypeRule)],
|
|
172
195
|
rules: {
|
|
173
196
|
// A named colour is a hex by another name. Hex is refused with the other
|
|
174
197
|
// literal colours below, so a mask may use either.
|
|
@@ -176,6 +199,7 @@ export default {
|
|
|
176
199
|
'declaration-property-value-disallowed-list': refuse(refusedValues),
|
|
177
200
|
'declaration-property-value-allowed-list': allow(allowedValues),
|
|
178
201
|
'rule-selector-property-disallowed-list': [{ '/.*/': refusedProperties.properties }, { message: refusedProperties.message }],
|
|
202
|
+
[inlineType]: true,
|
|
179
203
|
'declaration-no-important': [true, { message: `!important fights the system: settle it once, in the theme, or not at all (${guide}).` }],
|
|
180
204
|
'selector-disallowed-list': [refusedSelectors.selectors, { message: refusedSelectors.message }],
|
|
181
205
|
},
|