UNPKG

29.8 kBJavaScriptView Raw
1/**
2 * @fileoverview Disallow parenthesising higher precedence subexpressions.
3 * @author Michael Ficarra
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11const astUtils = require("../ast-utils.js");
12
13module.exports = {
14 meta: {
15 docs: {
16 description: "disallow unnecessary parentheses",
17 category: "Possible Errors",
18 recommended: false,
19 url: "https://eslint.org/docs/rules/no-extra-parens"
20 },
21
22 fixable: "code",
23
24 schema: {
25 anyOf: [
26 {
27 type: "array",
28 items: [
29 {
30 enum: ["functions"]
31 }
32 ],
33 minItems: 0,
34 maxItems: 1
35 },
36 {
37 type: "array",
38 items: [
39 {
40 enum: ["all"]
41 },
42 {
43 type: "object",
44 properties: {
45 conditionalAssign: { type: "boolean" },
46 nestedBinaryExpressions: { type: "boolean" },
47 returnAssign: { type: "boolean" },
48 ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
49 enforceForArrowConditionals: { type: "boolean" }
50 },
51 additionalProperties: false
52 }
53 ],
54 minItems: 0,
55 maxItems: 2
56 }
57 ]
58 },
59
60 messages: {
61 unexpected: "Gratuitous parentheses around expression."
62 }
63 },
64
65 create(context) {
66 const sourceCode = context.getSourceCode();
67
68 const tokensToIgnore = new WeakSet();
69 const isParenthesised = astUtils.isParenthesised.bind(astUtils, sourceCode);
70 const precedence = astUtils.getPrecedence;
71 const ALL_NODES = context.options[0] !== "functions";
72 const EXCEPT_COND_ASSIGN = ALL_NODES && context.options[1] && context.options[1].conditionalAssign === false;
73 const NESTED_BINARY = ALL_NODES && context.options[1] && context.options[1].nestedBinaryExpressions === false;
74 const EXCEPT_RETURN_ASSIGN = ALL_NODES && context.options[1] && context.options[1].returnAssign === false;
75 const IGNORE_JSX = ALL_NODES && context.options[1] && context.options[1].ignoreJSX;
76 const IGNORE_ARROW_CONDITIONALS = ALL_NODES && context.options[1] &&
77 context.options[1].enforceForArrowConditionals === false;
78
79 const PRECEDENCE_OF_ASSIGNMENT_EXPR = precedence({ type: "AssignmentExpression" });
80 const PRECEDENCE_OF_UPDATE_EXPR = precedence({ type: "UpdateExpression" });
81
82 /**
83 * Determines if this rule should be enforced for a node given the current configuration.
84 * @param {ASTNode} node - The node to be checked.
85 * @returns {boolean} True if the rule should be enforced for this node.
86 * @private
87 */
88 function ruleApplies(node) {
89 if (node.type === "JSXElement") {
90 const isSingleLine = node.loc.start.line === node.loc.end.line;
91
92 switch (IGNORE_JSX) {
93
94 // Exclude this JSX element from linting
95 case "all":
96 return false;
97
98 // Exclude this JSX element if it is multi-line element
99 case "multi-line":
100 return isSingleLine;
101
102 // Exclude this JSX element if it is single-line element
103 case "single-line":
104 return !isSingleLine;
105
106 // Nothing special to be done for JSX elements
107 case "none":
108 break;
109
110 // no default
111 }
112 }
113
114 return ALL_NODES || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
115 }
116
117 /**
118 * Determines if a node is surrounded by parentheses twice.
119 * @param {ASTNode} node - The node to be checked.
120 * @returns {boolean} True if the node is doubly parenthesised.
121 * @private
122 */
123 function isParenthesisedTwice(node) {
124 const previousToken = sourceCode.getTokenBefore(node, 1),
125 nextToken = sourceCode.getTokenAfter(node, 1);
126
127 return isParenthesised(node) && previousToken && nextToken &&
128 astUtils.isOpeningParenToken(previousToken) && previousToken.range[1] <= node.range[0] &&
129 astUtils.isClosingParenToken(nextToken) && nextToken.range[0] >= node.range[1];
130 }
131
132 /**
133 * Determines if a node is surrounded by (potentially) invalid parentheses.
134 * @param {ASTNode} node - The node to be checked.
135 * @returns {boolean} True if the node is incorrectly parenthesised.
136 * @private
137 */
138 function hasExcessParens(node) {
139 return ruleApplies(node) && isParenthesised(node);
140 }
141
142 /**
143 * Determines if a node that is expected to be parenthesised is surrounded by
144 * (potentially) invalid extra parentheses.
145 * @param {ASTNode} node - The node to be checked.
146 * @returns {boolean} True if the node is has an unexpected extra pair of parentheses.
147 * @private
148 */
149 function hasDoubleExcessParens(node) {
150 return ruleApplies(node) && isParenthesisedTwice(node);
151 }
152
153 /**
154 * Determines if a node test expression is allowed to have a parenthesised assignment
155 * @param {ASTNode} node - The node to be checked.
156 * @returns {boolean} True if the assignment can be parenthesised.
157 * @private
158 */
159 function isCondAssignException(node) {
160 return EXCEPT_COND_ASSIGN && node.test.type === "AssignmentExpression";
161 }
162
163 /**
164 * Determines if a node is in a return statement
165 * @param {ASTNode} node - The node to be checked.
166 * @returns {boolean} True if the node is in a return statement.
167 * @private
168 */
169 function isInReturnStatement(node) {
170 for (let currentNode = node; currentNode; currentNode = currentNode.parent) {
171 if (
172 currentNode.type === "ReturnStatement" ||
173 (currentNode.type === "ArrowFunctionExpression" && currentNode.body.type !== "BlockStatement")
174 ) {
175 return true;
176 }
177 }
178
179 return false;
180 }
181
182 /**
183 * Determines if a constructor function is newed-up with parens
184 * @param {ASTNode} newExpression - The NewExpression node to be checked.
185 * @returns {boolean} True if the constructor is called with parens.
186 * @private
187 */
188 function isNewExpressionWithParens(newExpression) {
189 const lastToken = sourceCode.getLastToken(newExpression);
190 const penultimateToken = sourceCode.getTokenBefore(lastToken);
191
192 return newExpression.arguments.length > 0 || astUtils.isOpeningParenToken(penultimateToken) && astUtils.isClosingParenToken(lastToken);
193 }
194
195 /**
196 * Determines if a node is or contains an assignment expression
197 * @param {ASTNode} node - The node to be checked.
198 * @returns {boolean} True if the node is or contains an assignment expression.
199 * @private
200 */
201 function containsAssignment(node) {
202 if (node.type === "AssignmentExpression") {
203 return true;
204 }
205 if (node.type === "ConditionalExpression" &&
206 (node.consequent.type === "AssignmentExpression" || node.alternate.type === "AssignmentExpression")) {
207 return true;
208 }
209 if ((node.left && node.left.type === "AssignmentExpression") ||
210 (node.right && node.right.type === "AssignmentExpression")) {
211 return true;
212 }
213
214 return false;
215 }
216
217 /**
218 * Determines if a node is contained by or is itself a return statement and is allowed to have a parenthesised assignment
219 * @param {ASTNode} node - The node to be checked.
220 * @returns {boolean} True if the assignment can be parenthesised.
221 * @private
222 */
223 function isReturnAssignException(node) {
224 if (!EXCEPT_RETURN_ASSIGN || !isInReturnStatement(node)) {
225 return false;
226 }
227
228 if (node.type === "ReturnStatement") {
229 return node.argument && containsAssignment(node.argument);
230 }
231 if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
232 return containsAssignment(node.body);
233 }
234 return containsAssignment(node);
235
236 }
237
238 /**
239 * Determines if a node following a [no LineTerminator here] restriction is
240 * surrounded by (potentially) invalid extra parentheses.
241 * @param {Token} token - The token preceding the [no LineTerminator here] restriction.
242 * @param {ASTNode} node - The node to be checked.
243 * @returns {boolean} True if the node is incorrectly parenthesised.
244 * @private
245 */
246 function hasExcessParensNoLineTerminator(token, node) {
247 if (token.loc.end.line === node.loc.start.line) {
248 return hasExcessParens(node);
249 }
250
251 return hasDoubleExcessParens(node);
252 }
253
254 /**
255 * Determines whether a node should be preceded by an additional space when removing parens
256 * @param {ASTNode} node node to evaluate; must be surrounded by parentheses
257 * @returns {boolean} `true` if a space should be inserted before the node
258 * @private
259 */
260 function requiresLeadingSpace(node) {
261 const leftParenToken = sourceCode.getTokenBefore(node);
262 const tokenBeforeLeftParen = sourceCode.getTokenBefore(node, 1);
263 const firstToken = sourceCode.getFirstToken(node);
264
265 return tokenBeforeLeftParen &&
266 tokenBeforeLeftParen.range[1] === leftParenToken.range[0] &&
267 leftParenToken.range[1] === firstToken.range[0] &&
268 !astUtils.canTokensBeAdjacent(tokenBeforeLeftParen, firstToken);
269 }
270
271 /**
272 * Determines whether a node should be followed by an additional space when removing parens
273 * @param {ASTNode} node node to evaluate; must be surrounded by parentheses
274 * @returns {boolean} `true` if a space should be inserted after the node
275 * @private
276 */
277 function requiresTrailingSpace(node) {
278 const nextTwoTokens = sourceCode.getTokensAfter(node, { count: 2 });
279 const rightParenToken = nextTwoTokens[0];
280 const tokenAfterRightParen = nextTwoTokens[1];
281 const tokenBeforeRightParen = sourceCode.getLastToken(node);
282
283 return rightParenToken && tokenAfterRightParen &&
284 !sourceCode.isSpaceBetweenTokens(rightParenToken, tokenAfterRightParen) &&
285 !astUtils.canTokensBeAdjacent(tokenBeforeRightParen, tokenAfterRightParen);
286 }
287
288 /**
289 * Determines if a given expression node is an IIFE
290 * @param {ASTNode} node The node to check
291 * @returns {boolean} `true` if the given node is an IIFE
292 */
293 function isIIFE(node) {
294 return node.type === "CallExpression" && node.callee.type === "FunctionExpression";
295 }
296
297 /**
298 * Report the node
299 * @param {ASTNode} node node to evaluate
300 * @returns {void}
301 * @private
302 */
303 function report(node) {
304 const leftParenToken = sourceCode.getTokenBefore(node);
305 const rightParenToken = sourceCode.getTokenAfter(node);
306
307 if (!isParenthesisedTwice(node)) {
308 if (tokensToIgnore.has(sourceCode.getFirstToken(node))) {
309 return;
310 }
311
312 if (isIIFE(node) && !isParenthesised(node.callee)) {
313 return;
314 }
315 }
316
317 context.report({
318 node,
319 loc: leftParenToken.loc.start,
320 messageId: "unexpected",
321 fix(fixer) {
322 const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]);
323
324 return fixer.replaceTextRange([
325 leftParenToken.range[0],
326 rightParenToken.range[1]
327 ], (requiresLeadingSpace(node) ? " " : "") + parenthesizedSource + (requiresTrailingSpace(node) ? " " : ""));
328 }
329 });
330 }
331
332 /**
333 * Evaluate Unary update
334 * @param {ASTNode} node node to evaluate
335 * @returns {void}
336 * @private
337 */
338 function checkUnaryUpdate(node) {
339 if (node.type === "UnaryExpression" && node.argument.type === "BinaryExpression" && node.argument.operator === "**") {
340 return;
341 }
342
343 if (hasExcessParens(node.argument) && precedence(node.argument) >= precedence(node)) {
344 report(node.argument);
345 }
346 }
347
348 /**
349 * Check if a member expression contains a call expression
350 * @param {ASTNode} node MemberExpression node to evaluate
351 * @returns {boolean} true if found, false if not
352 */
353 function doesMemberExpressionContainCallExpression(node) {
354 let currentNode = node.object;
355 let currentNodeType = node.object.type;
356
357 while (currentNodeType === "MemberExpression") {
358 currentNode = currentNode.object;
359 currentNodeType = currentNode.type;
360 }
361
362 return currentNodeType === "CallExpression";
363 }
364
365 /**
366 * Evaluate a new call
367 * @param {ASTNode} node node to evaluate
368 * @returns {void}
369 * @private
370 */
371 function checkCallNew(node) {
372 const callee = node.callee;
373
374 if (hasExcessParens(callee) && precedence(callee) >= precedence(node)) {
375 const hasNewParensException = callee.type === "NewExpression" && !isNewExpressionWithParens(callee);
376
377 if (
378 hasDoubleExcessParens(callee) ||
379 !isIIFE(node) && !hasNewParensException && !(
380
381 /*
382 * Allow extra parens around a new expression if
383 * there are intervening parentheses.
384 */
385 callee.type === "MemberExpression" &&
386 doesMemberExpressionContainCallExpression(callee)
387 )
388 ) {
389 report(node.callee);
390 }
391 }
392 if (node.arguments.length === 1) {
393 if (hasDoubleExcessParens(node.arguments[0]) && precedence(node.arguments[0]) >= PRECEDENCE_OF_ASSIGNMENT_EXPR) {
394 report(node.arguments[0]);
395 }
396 } else {
397 node.arguments
398 .filter(arg => hasExcessParens(arg) && precedence(arg) >= PRECEDENCE_OF_ASSIGNMENT_EXPR)
399 .forEach(report);
400 }
401 }
402
403 /**
404 * Evaluate binary logicals
405 * @param {ASTNode} node node to evaluate
406 * @returns {void}
407 * @private
408 */
409 function checkBinaryLogical(node) {
410 const prec = precedence(node);
411 const leftPrecedence = precedence(node.left);
412 const rightPrecedence = precedence(node.right);
413 const isExponentiation = node.operator === "**";
414 const shouldSkipLeft = (NESTED_BINARY && (node.left.type === "BinaryExpression" || node.left.type === "LogicalExpression")) ||
415 node.left.type === "UnaryExpression" && isExponentiation;
416 const shouldSkipRight = NESTED_BINARY && (node.right.type === "BinaryExpression" || node.right.type === "LogicalExpression");
417
418 if (!shouldSkipLeft && hasExcessParens(node.left) && (leftPrecedence > prec || (leftPrecedence === prec && !isExponentiation))) {
419 report(node.left);
420 }
421 if (!shouldSkipRight && hasExcessParens(node.right) && (rightPrecedence > prec || (rightPrecedence === prec && isExponentiation))) {
422 report(node.right);
423 }
424 }
425
426 /**
427 * Check the parentheses around the super class of the given class definition.
428 * @param {ASTNode} node The node of class declarations to check.
429 * @returns {void}
430 */
431 function checkClass(node) {
432 if (!node.superClass) {
433 return;
434 }
435
436 /*
437 * If `node.superClass` is a LeftHandSideExpression, parentheses are extra.
438 * Otherwise, parentheses are needed.
439 */
440 const hasExtraParens = precedence(node.superClass) > PRECEDENCE_OF_UPDATE_EXPR
441 ? hasExcessParens(node.superClass)
442 : hasDoubleExcessParens(node.superClass);
443
444 if (hasExtraParens) {
445 report(node.superClass);
446 }
447 }
448
449 /**
450 * Check the parentheses around the argument of the given spread operator.
451 * @param {ASTNode} node The node of spread elements/properties to check.
452 * @returns {void}
453 */
454 function checkSpreadOperator(node) {
455 const hasExtraParens = precedence(node.argument) >= PRECEDENCE_OF_ASSIGNMENT_EXPR
456 ? hasExcessParens(node.argument)
457 : hasDoubleExcessParens(node.argument);
458
459 if (hasExtraParens) {
460 report(node.argument);
461 }
462 }
463
464 /**
465 * Checks the parentheses for an ExpressionStatement or ExportDefaultDeclaration
466 * @param {ASTNode} node The ExpressionStatement.expression or ExportDefaultDeclaration.declaration node
467 * @returns {void}
468 */
469 function checkExpressionOrExportStatement(node) {
470 const firstToken = isParenthesised(node) ? sourceCode.getTokenBefore(node) : sourceCode.getFirstToken(node);
471 const secondToken = sourceCode.getTokenAfter(firstToken, astUtils.isNotOpeningParenToken);
472 const thirdToken = secondToken ? sourceCode.getTokenAfter(secondToken) : null;
473
474 if (
475 astUtils.isOpeningParenToken(firstToken) &&
476 (
477 astUtils.isOpeningBraceToken(secondToken) ||
478 secondToken.type === "Keyword" && (
479 secondToken.value === "function" ||
480 secondToken.value === "class" ||
481 secondToken.value === "let" && astUtils.isOpeningBracketToken(sourceCode.getTokenAfter(secondToken, astUtils.isNotClosingParenToken))
482 ) ||
483 secondToken && secondToken.type === "Identifier" && secondToken.value === "async" && thirdToken && thirdToken.type === "Keyword" && thirdToken.value === "function"
484 )
485 ) {
486 tokensToIgnore.add(secondToken);
487 }
488
489 if (hasExcessParens(node)) {
490 report(node);
491 }
492 }
493
494 return {
495 ArrayExpression(node) {
496 node.elements
497 .filter(e => e && hasExcessParens(e) && precedence(e) >= PRECEDENCE_OF_ASSIGNMENT_EXPR)
498 .forEach(report);
499 },
500
501 ArrowFunctionExpression(node) {
502 if (isReturnAssignException(node)) {
503 return;
504 }
505
506 if (node.body.type === "ConditionalExpression" &&
507 IGNORE_ARROW_CONDITIONALS &&
508 !isParenthesisedTwice(node.body)
509 ) {
510 return;
511 }
512
513 if (node.body.type !== "BlockStatement") {
514 const firstBodyToken = sourceCode.getFirstToken(node.body, astUtils.isNotOpeningParenToken);
515 const tokenBeforeFirst = sourceCode.getTokenBefore(firstBodyToken);
516
517 if (astUtils.isOpeningParenToken(tokenBeforeFirst) && astUtils.isOpeningBraceToken(firstBodyToken)) {
518 tokensToIgnore.add(firstBodyToken);
519 }
520 if (hasExcessParens(node.body) && precedence(node.body) >= PRECEDENCE_OF_ASSIGNMENT_EXPR) {
521 report(node.body);
522 }
523 }
524 },
525
526 AssignmentExpression(node) {
527 if (isReturnAssignException(node)) {
528 return;
529 }
530
531 if (hasExcessParens(node.right) && precedence(node.right) >= precedence(node)) {
532 report(node.right);
533 }
534 },
535
536 BinaryExpression: checkBinaryLogical,
537 CallExpression: checkCallNew,
538
539 ConditionalExpression(node) {
540 if (isReturnAssignException(node)) {
541 return;
542 }
543
544 if (hasExcessParens(node.test) && precedence(node.test) >= precedence({ type: "LogicalExpression", operator: "||" })) {
545 report(node.test);
546 }
547
548 if (hasExcessParens(node.consequent) && precedence(node.consequent) >= PRECEDENCE_OF_ASSIGNMENT_EXPR) {
549 report(node.consequent);
550 }
551
552 if (hasExcessParens(node.alternate) && precedence(node.alternate) >= PRECEDENCE_OF_ASSIGNMENT_EXPR) {
553 report(node.alternate);
554 }
555 },
556
557 DoWhileStatement(node) {
558 if (hasDoubleExcessParens(node.test) && !isCondAssignException(node)) {
559 report(node.test);
560 }
561 },
562
563 ExportDefaultDeclaration: node => checkExpressionOrExportStatement(node.declaration),
564 ExpressionStatement: node => checkExpressionOrExportStatement(node.expression),
565
566 "ForInStatement, ForOfStatement"(node) {
567 if (node.left.type !== "VariableDeclarator") {
568 const firstLeftToken = sourceCode.getFirstToken(node.left, astUtils.isNotOpeningParenToken);
569
570 if (
571 firstLeftToken.value === "let" && (
572
573 /*
574 * If `let` is the only thing on the left side of the loop, it's the loop variable: `for ((let) of foo);`
575 * Removing it will cause a syntax error, because it will be parsed as the start of a VariableDeclarator.
576 */
577 firstLeftToken.range[1] === node.left.range[1] ||
578
579 /*
580 * If `let` is followed by a `[` token, it's a property access on the `let` value: `for ((let[foo]) of bar);`
581 * Removing it will cause the property access to be parsed as a destructuring declaration of `foo` instead.
582 */
583 astUtils.isOpeningBracketToken(
584 sourceCode.getTokenAfter(firstLeftToken, astUtils.isNotClosingParenToken)
585 )
586 )
587 ) {
588 tokensToIgnore.add(firstLeftToken);
589 }
590 }
591 if (!(node.type === "ForOfStatement" && node.right.type === "SequenceExpression") && hasExcessParens(node.right)) {
592 report(node.right);
593 }
594 if (hasExcessParens(node.left)) {
595 report(node.left);
596 }
597 },
598
599 ForStatement(node) {
600 if (node.init && hasExcessParens(node.init)) {
601 report(node.init);
602 }
603
604 if (node.test && hasExcessParens(node.test) && !isCondAssignException(node)) {
605 report(node.test);
606 }
607
608 if (node.update && hasExcessParens(node.update)) {
609 report(node.update);
610 }
611 },
612
613 IfStatement(node) {
614 if (hasDoubleExcessParens(node.test) && !isCondAssignException(node)) {
615 report(node.test);
616 }
617 },
618
619 LogicalExpression: checkBinaryLogical,
620
621 MemberExpression(node) {
622 const nodeObjHasExcessParens = hasExcessParens(node.object);
623
624 if (
625 nodeObjHasExcessParens &&
626 precedence(node.object) >= precedence(node) &&
627 (
628 node.computed ||
629 !(
630 astUtils.isDecimalInteger(node.object) ||
631
632 // RegExp literal is allowed to have parens (#1589)
633 (node.object.type === "Literal" && node.object.regex)
634 )
635 )
636 ) {
637 report(node.object);
638 }
639
640 if (nodeObjHasExcessParens &&
641 node.object.type === "CallExpression" &&
642 node.parent.type !== "NewExpression") {
643 report(node.object);
644 }
645
646 if (node.computed && hasExcessParens(node.property)) {
647 report(node.property);
648 }
649 },
650
651 NewExpression: checkCallNew,
652
653 ObjectExpression(node) {
654 node.properties
655 .filter(property => {
656 const value = property.value;
657
658 return value && hasExcessParens(value) && precedence(value) >= PRECEDENCE_OF_ASSIGNMENT_EXPR;
659 }).forEach(property => report(property.value));
660 },
661
662 ReturnStatement(node) {
663 const returnToken = sourceCode.getFirstToken(node);
664
665 if (isReturnAssignException(node)) {
666 return;
667 }
668
669 if (node.argument &&
670 hasExcessParensNoLineTerminator(returnToken, node.argument) &&
671
672 // RegExp literal is allowed to have parens (#1589)
673 !(node.argument.type === "Literal" && node.argument.regex)) {
674 report(node.argument);
675 }
676 },
677
678 SequenceExpression(node) {
679 node.expressions
680 .filter(e => hasExcessParens(e) && precedence(e) >= precedence(node))
681 .forEach(report);
682 },
683
684 SwitchCase(node) {
685 if (node.test && hasExcessParens(node.test)) {
686 report(node.test);
687 }
688 },
689
690 SwitchStatement(node) {
691 if (hasDoubleExcessParens(node.discriminant)) {
692 report(node.discriminant);
693 }
694 },
695
696 ThrowStatement(node) {
697 const throwToken = sourceCode.getFirstToken(node);
698
699 if (hasExcessParensNoLineTerminator(throwToken, node.argument)) {
700 report(node.argument);
701 }
702 },
703
704 UnaryExpression: checkUnaryUpdate,
705 UpdateExpression: checkUnaryUpdate,
706 AwaitExpression: checkUnaryUpdate,
707
708 VariableDeclarator(node) {
709 if (node.init && hasExcessParens(node.init) &&
710 precedence(node.init) >= PRECEDENCE_OF_ASSIGNMENT_EXPR &&
711
712 // RegExp literal is allowed to have parens (#1589)
713 !(node.init.type === "Literal" && node.init.regex)) {
714 report(node.init);
715 }
716 },
717
718 WhileStatement(node) {
719 if (hasDoubleExcessParens(node.test) && !isCondAssignException(node)) {
720 report(node.test);
721 }
722 },
723
724 WithStatement(node) {
725 if (hasDoubleExcessParens(node.object)) {
726 report(node.object);
727 }
728 },
729
730 YieldExpression(node) {
731 if (node.argument) {
732 const yieldToken = sourceCode.getFirstToken(node);
733
734 if ((precedence(node.argument) >= precedence(node) &&
735 hasExcessParensNoLineTerminator(yieldToken, node.argument)) ||
736 hasDoubleExcessParens(node.argument)) {
737 report(node.argument);
738 }
739 }
740 },
741
742 ClassDeclaration: checkClass,
743 ClassExpression: checkClass,
744
745 SpreadElement: checkSpreadOperator,
746 SpreadProperty: checkSpreadOperator,
747 ExperimentalSpreadProperty: checkSpreadOperator
748 };
749
750 }
751};