@@ -70,8 +70,7 @@ module.exports = {
7070 allowShortCircuit = config . allowShortCircuit || false ,
7171 allowTernary = config . allowTernary || false ,
7272 allowTaggedTemplates = config . allowTaggedTemplates || false ,
73- enforceForJSX = config . enforceForJSX || false ,
74- sourceCode = context . getSourceCode ( ) ;
73+ enforceForJSX = config . enforceForJSX || false ;
7574
7675 /**
7776 * Has AST suggesting a directive.
@@ -110,12 +109,11 @@ module.exports = {
110109 /**
111110 * Detect if a Node is a directive.
112111 * @param {ASTNode } node any node
113- * @param {ASTNode[] } ancestors the given node's ancestors
114112 * @returns {boolean } whether the given node is considered a directive in its current position
115113 */
116- function isDirective ( node , ancestors ) {
117- const parent = ancestors [ ancestors . length - 1 ] ,
118- grandparent = ancestors [ ancestors . length - 2 ] ;
114+ function isDirective ( node ) {
115+ const parent = node . parent ,
116+ grandparent = parent . parent ;
119117
120118 /**
121119 * https://tc39.es/ecma262/#directive-prologue
@@ -181,7 +179,7 @@ module.exports = {
181179
182180 return {
183181 ExpressionStatement ( node ) {
184- if ( Checker . isDisallowed ( node . expression ) && ! isDirective ( node , sourceCode . getAncestors ( node ) ) ) {
182+ if ( Checker . isDisallowed ( node . expression ) && ! isDirective ( node ) ) {
185183 context . report ( { node, messageId : "unusedExpression" } ) ;
186184 }
187185 }
0 commit comments