-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
jsx-embed-condition.js
45 lines (39 loc) · 1.09 KB
/
jsx-embed-condition.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
45
/**
* @fileoverview Prevents usage of && condition in JSX Embeds.
* @author Anees Iqbal <i@steelbrain.me>
*/
'use strict';
const docsUrl = require('../util/docsUrl');
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'Prevents usage of && condition in JSX embed',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-embed-condition')
},
schema: []
},
create(context) {
return {
JSXExpressionContainer(node) {
if (
node.parent == null
|| node.parent.type !== 'JSXElement'
|| node.expression == null
|| node.expression.type !== 'LogicalExpression'
|| node.expression.operator === '??'
) {
return;
}
context.report({
node,
message: 'Using && to condition JSX embeds is forbidden. Convert it to a ternary operation instead'
});
}
};
}
};