-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinline-no-logical-dimensions.ts
More file actions
50 lines (40 loc) · 1.66 KB
/
inline-no-logical-dimensions.ts
File metadata and controls
50 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { type RuleDescriptor, type Warning, createWarning } from './types.ts';
import { isDefaultInlineSizeValue, isReplacedInlineElement } from './context.ts';
import { registerRule } from './registry.ts';
const RULE_ID = 'inline-no-logical-dimensions' as const;
const warn = (fields: Omit<Warning, 'ruleId' | 'severity'>) => createWarning(RULE_ID, fields);
const rule: RuleDescriptor = {
id: RULE_ID,
label: 'inline-size/block-size on inline',
requiredProperties: ['display', 'inlineSize', 'blockSize'],
check(ctx) {
const { display, inlineSize, blockSize } = ctx.styles;
const { tagName } = ctx.element;
if (display !== 'inline') return [];
if (isReplacedInlineElement(tagName)) return [];
const warnings: Warning[] = [];
if (!isDefaultInlineSizeValue(inlineSize)) {
warnings.push(
warn({
property: 'inline-size',
title: 'inline-size has no effect on inline elements',
details: `inline-size is "${inlineSize}" but display is "inline". Inline elements ignore inline-size.`,
suggestion: 'Set display: inline-block or display: block, or remove inline-size.',
}),
);
}
if (!isDefaultInlineSizeValue(blockSize)) {
warnings.push(
warn({
property: 'block-size',
title: 'block-size has no effect on inline elements',
details: `block-size is "${blockSize}" but display is "inline". Inline elements ignore block-size.`,
suggestion: 'Set display: inline-block or display: block, or remove block-size.',
}),
);
}
return warnings;
},
};
registerRule(rule);
export const checkInlineLogicalDimensions = rule.check;