-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (25 loc) · 1.01 KB
/
index.js
File metadata and controls
29 lines (25 loc) · 1.01 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
const { elementType, getProp, getPropValue } = require('jsx-ast-utils');
module.exports = {
rules: {
'data-type-required': {
create: context => ({
JSXOpeningElement: node => {
const [options = {}] = context.options;
const elements = ['Drawer'].concat(options.additionalElements || []);
const nodeType = elementType(node);
if (!elements.includes(nodeType)) {
return;
}
const prop = getProp(node.attributes, 'data-type');
const propValue = getPropValue(prop);
if (!prop || !propValue || typeof propValue !== 'string') {
context.report({
node,
message: `<${nodeType}> components must have a valid "data-type" attribute`,
});
}
},
}),
},
},
};