-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulticol-no-column-rule.ts
More file actions
75 lines (62 loc) · 2.17 KB
/
multicol-no-column-rule.ts
File metadata and controls
75 lines (62 loc) · 2.17 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { type RuleDescriptor, type Warning, createWarning } from './types.ts';
import { isMulticolContainer } from './context.ts';
import { registerRule } from './registry.ts';
const RULE_ID = 'multicol-no-column-rule' as const;
const warn = (fields: Omit<Warning, 'ruleId' | 'severity'>) => createWarning(RULE_ID, fields);
const MULTICOL_PROPERTIES = [
{
key: 'columnRuleStyle',
cssName: 'column-rule-style',
// 'medium' is the specified initial value; '0px' is the computed value
// when column-rule-style is 'none'. Both are treated as defaults.
defaults: ['none'],
shorthand: 'column-rule',
},
{
key: 'columnRuleWidth',
cssName: 'column-rule-width',
defaults: ['medium', '0px'],
shorthand: 'column-rule',
},
{
key: 'columnFill',
cssName: 'column-fill',
defaults: ['balance'],
},
] as const;
const DETAIL_SUFFIX =
'This property only applies when column-count or column-width establishes a multi-column layout.';
const rule: RuleDescriptor = {
id: RULE_ID,
label: 'column-rule/column-fill on non-multicol container',
requiredProperties: [
'display',
'columnCount',
'columnWidth',
...MULTICOL_PROPERTIES.map((p) => p.key),
],
check(ctx) {
const { display, columnCount, columnWidth } = ctx.styles;
if (isMulticolContainer(display, columnCount, columnWidth)) return [];
const warnings: Warning[] = [];
for (const prop of MULTICOL_PROPERTIES) {
const value = ctx.styles[prop.key];
if ((prop.defaults as readonly string[]).includes(value)) continue;
const removeHint =
'shorthand' in prop
? `Remove ${prop.cssName} (or the ${prop.shorthand} shorthand)`
: `Remove ${prop.cssName}`;
warnings.push(
warn({
property: prop.cssName,
title: `${prop.cssName} has no effect`,
details: `${prop.cssName} is "${value}" but this element is not a multi-column container. ${DETAIL_SUFFIX}`,
suggestion: `${removeHint}, or add column-count/column-width to create a multi-column layout.`,
}),
);
}
return warnings;
},
};
registerRule(rule);
export const checkMulticolColumnRule = rule.check;