-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoutline-no-style.ts
More file actions
53 lines (42 loc) · 1.83 KB
/
Copy pathoutline-no-style.ts
File metadata and controls
53 lines (42 loc) · 1.83 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
51
52
53
import { type RuleDescriptor, type Warning, createWarning } from './types.ts';
import { registerRule } from './registry.ts';
const RULE_ID = 'outline-no-style' as const;
const warn = (fields: Omit<Warning, 'ruleId' | 'severity'>) => createWarning(RULE_ID, fields);
const OUTLINE_PROPERTIES = [
{ key: 'outlineWidth', css: 'outline-width' },
{ key: 'outlineColor', css: 'outline-color' },
{ key: 'outlineOffset', css: 'outline-offset' },
] as const;
/**
* Browsers resolve computed outline-width to '0px' when outline-style is 'none'.
* Since we read computed styles, we cannot distinguish "author set outline-width: 3px"
* from the default when outline-style is none. We use inline styles to detect authored values.
*/
const rule: RuleDescriptor = {
id: RULE_ID,
label: 'outline properties without outline-style',
requiredProperties: ['outlineStyle'],
requiredInlineProperties: ['outlineWidth', 'outlineColor', 'outlineOffset'],
check(ctx) {
const outlineStyle = ctx.styles['outlineStyle'] ?? 'none';
// If outline-style is set to something other than 'none', the outline is visible
if (outlineStyle !== 'none') return [];
const warnings: Warning[] = [];
for (const { key, css } of OUTLINE_PROPERTIES) {
const inlineValue = ctx.inlineStyles[key] ?? '';
if (inlineValue === '') continue;
warnings.push(
warn({
property: css,
title: `${css} has no effect without outline-style`,
details: `${css} is "${inlineValue}" but outline-style is "none". Without outline-style, no outline is rendered and this property has no visible effect.`,
suggestion:
'Add outline-style (e.g. outline-style: solid), or remove the outline property.',
}),
);
}
return warnings;
},
};
registerRule(rule);
export const checkOutlineNoStyle = rule.check;