forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslint-plugin-local.js
44 lines (41 loc) · 1.18 KB
/
.eslint-plugin-local.js
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
// @ts-check
'use strict';
/**
* @type {{[ruleName: string]: import('eslint').Rule.RuleModule}}
*/
const rules = {
'jsx-uses-m-pragma': {
create(context) {
const pragma = 'm';
const usePragma = () => context.markVariableAsUsed(pragma);
return {
JSXOpeningElement: usePragma,
JSXOpeningFragment: usePragma,
};
},
},
'jsx-uses-vars': {
create(context) {
return {
/**
* @param {{ name: any; }} node
*/
JSXOpeningElement(node) {
let variable;
const jsxTag = node.name;
if (jsxTag.type === 'JSXIdentifier') {
variable = jsxTag.name;
} else if (jsxTag.type === 'JSXMemberExpression') {
variable = jsxTag.object.name;
} else {
console.warn('Unsupported JSX identifier', jsxTag);
}
context.markVariableAsUsed(variable);
},
};
},
},
};
module.exports = {
rules,
};