@@ -9,6 +9,7 @@ const has = require('object.hasown/polyfill')();
99const docsUrl = require ( '../util/docsUrl' ) ;
1010const jsxUtil = require ( '../util/jsx' ) ;
1111const reportC = require ( '../util/report' ) ;
12+ const isParenthesized = require ( '../util/ast' ) . isParenthesized ;
1213
1314// ------------------------------------------------------------------------------
1415// Constants
@@ -89,20 +90,10 @@ module.exports = {
8990 return option && option !== 'ignore' ;
9091 }
9192
92- function isParenthesised ( node ) {
93- const sourceCode = context . getSourceCode ( ) ;
94- const previousToken = sourceCode . getTokenBefore ( node ) ;
95- const nextToken = sourceCode . getTokenAfter ( node ) ;
96-
97- return previousToken && nextToken
98- && previousToken . value === '(' && previousToken . range [ 1 ] <= node . range [ 0 ]
99- && nextToken . value === ')' && nextToken . range [ 0 ] >= node . range [ 1 ] ;
100- }
101-
10293 function needsOpeningNewLine ( node ) {
10394 const previousToken = context . getSourceCode ( ) . getTokenBefore ( node ) ;
10495
105- if ( ! isParenthesised ( node ) ) {
96+ if ( ! isParenthesized ( context , node ) ) {
10697 return false ;
10798 }
10899
@@ -116,7 +107,7 @@ module.exports = {
116107 function needsClosingNewLine ( node ) {
117108 const nextToken = context . getSourceCode ( ) . getTokenAfter ( node ) ;
118109
119- if ( ! isParenthesised ( node ) ) {
110+ if ( ! isParenthesized ( context , node ) ) {
120111 return false ;
121112 }
122113
@@ -153,12 +144,12 @@ module.exports = {
153144 const sourceCode = context . getSourceCode ( ) ;
154145 const option = getOption ( type ) ;
155146
156- if ( ( option === true || option === 'parens' ) && ! isParenthesised ( node ) && isMultilines ( node ) ) {
147+ if ( ( option === true || option === 'parens' ) && ! isParenthesized ( context , node ) && isMultilines ( node ) ) {
157148 report ( node , 'missingParens' , ( fixer ) => fixer . replaceText ( node , `(${ sourceCode . getText ( node ) } )` ) ) ;
158149 }
159150
160151 if ( option === 'parens-new-line' && isMultilines ( node ) ) {
161- if ( ! isParenthesised ( node ) ) {
152+ if ( ! isParenthesized ( context , node ) ) {
162153 const tokenBefore = sourceCode . getTokenBefore ( node , { includeComments : true } ) ;
163154 const tokenAfter = sourceCode . getTokenAfter ( node , { includeComments : true } ) ;
164155 const start = node . loc . start ;
0 commit comments