UNPKG

791 BJavaScriptView Raw
1const {docsUrl} = require('../utilities');
2
3const CONDITIONAL_EXPRESSION_WARNING = [
4 'Don’t use conditional expressions inside JSX;',
5 'they generally make your component harder to read.',
6 'Instead, break that expression out into its own variable,',
7 'and include the variable in JSX.',
8].join(' ');
9
10module.exports = {
11 meta: {
12 docs: {
13 description: 'Disallow complex expressions embedded in in JSX.',
14 category: 'Best Practices',
15 recommended: true,
16 uri: docsUrl('jsx-no-complex-expressions'),
17 },
18 schema: [],
19 },
20
21 create(context) {
22 return {
23 JSXExpressionContainer(node) {
24 if (node.expression.type === 'ConditionalExpression') {
25 context.report(node, CONDITIONAL_EXPRESSION_WARNING);
26 }
27 },
28 };
29 },
30};