@@ -9,6 +9,7 @@ const has = require('object.hasown/polyfill')();
9
9
const docsUrl = require ( '../util/docsUrl' ) ;
10
10
const jsxUtil = require ( '../util/jsx' ) ;
11
11
const reportC = require ( '../util/report' ) ;
12
+ const isParenthesized = require ( '../util/ast' ) . isParenthesized ;
12
13
13
14
// ------------------------------------------------------------------------------
14
15
// Constants
@@ -89,20 +90,10 @@ module.exports = {
89
90
return option && option !== 'ignore' ;
90
91
}
91
92
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
-
102
93
function needsOpeningNewLine ( node ) {
103
94
const previousToken = context . getSourceCode ( ) . getTokenBefore ( node ) ;
104
95
105
- if ( ! isParenthesised ( node ) ) {
96
+ if ( ! isParenthesized ( context , node ) ) {
106
97
return false ;
107
98
}
108
99
@@ -116,7 +107,7 @@ module.exports = {
116
107
function needsClosingNewLine ( node ) {
117
108
const nextToken = context . getSourceCode ( ) . getTokenAfter ( node ) ;
118
109
119
- if ( ! isParenthesised ( node ) ) {
110
+ if ( ! isParenthesized ( context , node ) ) {
120
111
return false ;
121
112
}
122
113
@@ -153,12 +144,12 @@ module.exports = {
153
144
const sourceCode = context . getSourceCode ( ) ;
154
145
const option = getOption ( type ) ;
155
146
156
- if ( ( option === true || option === 'parens' ) && ! isParenthesised ( node ) && isMultilines ( node ) ) {
147
+ if ( ( option === true || option === 'parens' ) && ! isParenthesized ( context , node ) && isMultilines ( node ) ) {
157
148
report ( node , 'missingParens' , ( fixer ) => fixer . replaceText ( node , `(${ sourceCode . getText ( node ) } )` ) ) ;
158
149
}
159
150
160
151
if ( option === 'parens-new-line' && isMultilines ( node ) ) {
161
- if ( ! isParenthesised ( node ) ) {
152
+ if ( ! isParenthesized ( context , node ) ) {
162
153
const tokenBefore = sourceCode . getTokenBefore ( node , { includeComments : true } ) ;
163
154
const tokenAfter = sourceCode . getTokenAfter ( node , { includeComments : true } ) ;
164
155
const start = node . loc . start ;
0 commit comments