zyzz 0.0.17 → 0.0.19
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/dist/Style.d.ts.map +1 -1
- package/dist/Style.js +16 -3
- package/dist/Style.js.map +1 -1
- package/dist/oxlint/index.d.ts +6 -0
- package/dist/oxlint/index.d.ts.map +1 -0
- package/dist/oxlint/index.js +18 -0
- package/dist/oxlint/index.js.map +1 -0
- package/dist/oxlint/internal/Bindings.d.ts +20 -0
- package/dist/oxlint/internal/Bindings.d.ts.map +1 -0
- package/dist/oxlint/internal/Bindings.js +203 -0
- package/dist/oxlint/internal/Bindings.js.map +1 -0
- package/dist/oxlint/internal/Declarations.d.ts +19 -0
- package/dist/oxlint/internal/Declarations.d.ts.map +1 -0
- package/dist/oxlint/internal/Declarations.js +114 -0
- package/dist/oxlint/internal/Declarations.js.map +1 -0
- package/dist/oxlint/rules/noConflictingProps.d.ts +5 -0
- package/dist/oxlint/rules/noConflictingProps.d.ts.map +1 -0
- package/dist/oxlint/rules/noConflictingProps.js +45 -0
- package/dist/oxlint/rules/noConflictingProps.js.map +1 -0
- package/dist/oxlint/rules/noUnused.d.ts +5 -0
- package/dist/oxlint/rules/noUnused.d.ts.map +1 -0
- package/dist/oxlint/rules/noUnused.js +62 -0
- package/dist/oxlint/rules/noUnused.js.map +1 -0
- package/dist/oxlint/rules/restrictedProperties.d.ts +5 -0
- package/dist/oxlint/rules/restrictedProperties.d.ts.map +1 -0
- package/dist/oxlint/rules/restrictedProperties.js +82 -0
- package/dist/oxlint/rules/restrictedProperties.js.map +1 -0
- package/dist/oxlint/rules/useLogicalProperties.d.ts +5 -0
- package/dist/oxlint/rules/useLogicalProperties.d.ts.map +1 -0
- package/dist/oxlint/rules/useLogicalProperties.js +76 -0
- package/dist/oxlint/rules/useLogicalProperties.js.map +1 -0
- package/dist/oxlint/rules/validStyles.d.ts +5 -0
- package/dist/oxlint/rules/validStyles.d.ts.map +1 -0
- package/dist/oxlint/rules/validStyles.js +75 -0
- package/dist/oxlint/rules/validStyles.js.map +1 -0
- package/package.json +7 -1
- package/src/Style.ts +16 -3
- package/src/oxlint/index.ts +21 -0
- package/src/oxlint/internal/Bindings.ts +270 -0
- package/src/oxlint/internal/Declarations.ts +137 -0
- package/src/oxlint/rules/noConflictingProps.ts +52 -0
- package/src/oxlint/rules/noUnused.ts +67 -0
- package/src/oxlint/rules/restrictedProperties.ts +92 -0
- package/src/oxlint/rules/useLogicalProperties.ts +81 -0
- package/src/oxlint/rules/validStyles.ts +88 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Reports statically known declaration errors using Zyzz's authoring validation. @module */
|
|
2
|
+
import type { ESTree, Rule } from '@oxlint/plugins'
|
|
3
|
+
import * as Bindings from '../internal/Bindings.js'
|
|
4
|
+
import * as Declarations from '../internal/Declarations.js'
|
|
5
|
+
import * as Literal from '../../internal/Literal.js'
|
|
6
|
+
import * as Style from '../../Style.js'
|
|
7
|
+
|
|
8
|
+
/** Validates known structure and values while leaving unresolved bindings to the compiler. */
|
|
9
|
+
export const validStyles: Rule = {
|
|
10
|
+
meta: { messages: { invalid: '{{message}}' }, schema: [], type: 'problem' },
|
|
11
|
+
create(context) {
|
|
12
|
+
const bindings = Bindings.create(context)
|
|
13
|
+
const reported = new Set<number>()
|
|
14
|
+
function report(node: ESTree.Node, message: string) {
|
|
15
|
+
if (reported.has(node.start)) return
|
|
16
|
+
reported.add(node.start)
|
|
17
|
+
context.report({ data: { message }, messageId: 'invalid', node })
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
CallExpression(node) {
|
|
21
|
+
const binding = bindings.resolve(node.callee)
|
|
22
|
+
if (binding?.kind !== 'style' && binding?.kind !== 'variants') return
|
|
23
|
+
const input = node.arguments[0]
|
|
24
|
+
if (!input || input.type === 'SpreadElement') return
|
|
25
|
+
Declarations.visit(input, {
|
|
26
|
+
bindings,
|
|
27
|
+
recipe: binding.kind === 'variants',
|
|
28
|
+
visitors: {
|
|
29
|
+
declaration(property, name) {
|
|
30
|
+
if (binding.themed && name === 'typography') return
|
|
31
|
+
if (
|
|
32
|
+
!binding.themed &&
|
|
33
|
+
!name.startsWith('--') &&
|
|
34
|
+
!Object.hasOwn(Literal.rules, name)
|
|
35
|
+
) {
|
|
36
|
+
report(property.key, `Unknown CSS property '${name}'.`)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const value = bindings.expression(property.value)
|
|
40
|
+
if (value.type === 'ObjectExpression') {
|
|
41
|
+
report(
|
|
42
|
+
value,
|
|
43
|
+
'CSS declarations require scalar values or fallback arrays.',
|
|
44
|
+
)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
if (
|
|
48
|
+
value.type === 'ArrayExpression' &&
|
|
49
|
+
value.elements.some((element) => !element)
|
|
50
|
+
) {
|
|
51
|
+
report(
|
|
52
|
+
value,
|
|
53
|
+
'Fallback arrays require dense data entries without holes.',
|
|
54
|
+
)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
const literal = Declarations.literal(value, bindings)
|
|
58
|
+
if (!literal) return
|
|
59
|
+
const values = Array.isArray(literal.value)
|
|
60
|
+
? literal.value
|
|
61
|
+
: [literal.value]
|
|
62
|
+
if (
|
|
63
|
+
values.some(
|
|
64
|
+
(value) =>
|
|
65
|
+
typeof value !== 'string' && typeof value !== 'number',
|
|
66
|
+
)
|
|
67
|
+
) {
|
|
68
|
+
report(
|
|
69
|
+
value,
|
|
70
|
+
'CSS declarations require string or number values.',
|
|
71
|
+
)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
Style.define({ lint: { [name]: literal.value } } as never)
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (!(error instanceof Style.InvalidError)) throw error
|
|
78
|
+
for (const diagnostic of error.diagnostics)
|
|
79
|
+
report(value, diagnostic.message)
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
invalid: report,
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
}
|