-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinline-no-dimensions.ts
More file actions
50 lines (40 loc) · 1.55 KB
/
inline-no-dimensions.ts
File metadata and controls
50 lines (40 loc) · 1.55 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-dimensions' as const;
const warn = (fields: Omit<Warning, 'ruleId' | 'severity'>) => createWarning(RULE_ID, fields);
const rule: RuleDescriptor = {
id: RULE_ID,
label: 'width/height on inline',
requiredProperties: ['display', 'width', 'height'],
check(ctx) {
const { display, width, height } = ctx.styles;
const { tagName } = ctx.element;
if (display !== 'inline') return [];
if (isReplacedInlineElement(tagName)) return [];
const warnings: Warning[] = [];
if (!isDefaultInlineSizeValue(width)) {
warnings.push(
warn({
property: 'width',
title: 'width has no effect on inline elements',
details: `width is "${width}" but display is "inline". Inline elements ignore width.`,
suggestion: 'Set display: inline-block or display: block, or remove width.',
}),
);
}
if (!isDefaultInlineSizeValue(height)) {
warnings.push(
warn({
property: 'height',
title: 'height has no effect on inline elements',
details: `height is "${height}" but display is "inline". Inline elements ignore height.`,
suggestion: 'Set display: inline-block or display: block, or remove height.',
}),
);
}
return warnings;
},
};
registerRule(rule);
export const checkInlineDimensions = rule.check;