-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathitem-no-grid-props.ts
More file actions
48 lines (39 loc) · 1.77 KB
/
item-no-grid-props.ts
File metadata and controls
48 lines (39 loc) · 1.77 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 { registerRule } from './registry.ts';
const RULE_ID = 'item-no-grid-props' as const;
const warn = (fields: Omit<Warning, 'ruleId' | 'severity'>) => createWarning(RULE_ID, fields);
const GRID_CHILD_PROPERTIES = [
{ key: 'gridColumnStart', cssName: 'grid-column-start', defaultValue: 'auto' },
{ key: 'gridColumnEnd', cssName: 'grid-column-end', defaultValue: 'auto' },
{ key: 'gridRowStart', cssName: 'grid-row-start', defaultValue: 'auto' },
{ key: 'gridRowEnd', cssName: 'grid-row-end', defaultValue: 'auto' },
] as const;
const rule: RuleDescriptor = {
id: RULE_ID,
label: 'grid item props on non-grid child',
requiredProperties: GRID_CHILD_PROPERTIES.map((p) => p.key),
requiredParentProperties: ['display'],
check(ctx): Warning[] {
if (!ctx.parentStyles) return [];
if (ctx.isGridItem) return [];
// display:contents removes the parent's box, so the child participates in the
// grandparent's formatting context. Without grandparent data we cannot determine
// if this element is effectively a grid item.
if (ctx.isParentContents) return [];
return GRID_CHILD_PROPERTIES.flatMap(({ key, cssName, defaultValue }) => {
const value = ctx.styles[key];
if (value === defaultValue) return [];
return [
warn({
property: cssName,
title: `${cssName} has no effect`,
details: `${cssName} is "${value}" but parent display is "${ctx.parentDisplay}". These properties only apply to grid items.`,
suggestion:
'Set display: grid or display: inline-grid on the parent element, or remove this property.',
}),
];
});
},
};
registerRule(rule);
export const checkItemNoGridProps = rule.check;