-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnonreplaced-no-aspect-ratio.ts
More file actions
48 lines (37 loc) · 1.73 KB
/
nonreplaced-no-aspect-ratio.ts
File metadata and controls
48 lines (37 loc) · 1.73 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
import { type RuleDescriptor, type Warning, createWarning } from './types.ts';
import { isReplacedInlineElement } from './context.ts';
import { registerRule } from './registry.ts';
const RULE_ID = 'nonreplaced-no-aspect-ratio' as const;
const warn = (fields: Omit<Warning, 'ruleId' | 'severity'>) => createWarning(RULE_ID, fields);
function isDefaultAspectRatio(value: string): boolean {
return value === 'auto';
}
const rule: RuleDescriptor = {
id: RULE_ID,
label: 'aspect-ratio on inline non-replaced element',
requiredProperties: ['display', 'aspectRatio'],
check(ctx) {
const { display, aspectRatio } = ctx.styles;
const { tagName } = ctx.element;
// display: contents elements generate no box — skip
if (ctx.isContents) return [];
// aspect-ratio only has no effect on inline non-replaced elements.
// Note: ruby/ruby-text (display: ruby, ruby-text) are also inline-level boxes
// where aspect-ratio has no effect, but this is intentionally out of scope —
// ruby elements with aspect-ratio is an extremely rare combination.
if (display !== 'inline') return [];
// Replaced inline elements (img, video, etc.) support aspect-ratio
if (isReplacedInlineElement(tagName)) return [];
if (isDefaultAspectRatio(aspectRatio)) return [];
return [
warn({
property: 'aspect-ratio',
title: 'aspect-ratio has no effect on inline non-replaced elements',
details: `aspect-ratio is "${aspectRatio}" but display is "inline" on <${tagName}>. Inline non-replaced elements ignore aspect-ratio.`,
suggestion: 'Remove aspect-ratio, or change display to block or inline-block.',
}),
];
},
};
registerRule(rule);
export const checkNonreplacedAspectRatio = rule.check;