@@ -140,6 +140,61 @@ function main( context ) {
140140 return 1 ;
141141 }
142142
143+ /**
144+ * Fixes the lint error by reordering the require statements.
145+ *
146+ * @private
147+ * @param {Function } fixer - ESLint fixer
148+ * @returns {(Object|Null) } fix or null
149+ */
150+ function fix ( fixer ) {
151+ var requireDeclarations ;
152+ var replacingText ;
153+ var startRange ;
154+ var endRange ;
155+ var source ;
156+ var elem ;
157+ var txt ;
158+ var i ;
159+
160+ replacingText = '' ;
161+ requireDeclarations = [ ] ;
162+ source = context . getSourceCode ( ) ;
163+
164+ // Get the text and rank for the require statements:
165+ for ( i = 0 ; i < requires . length ; i ++ ) {
166+ elem = requires [ i ] . node . parent . parent ;
167+ txt = source . getText ( elem ) ;
168+ if ( i === 0 ) {
169+ startRange = elem . range [ 0 ] - elem . loc . start . column ;
170+ }
171+ endRange = elem . range [ 1 ] ;
172+ requireDeclarations . push ( {
173+ 'text' : txt ,
174+ 'rank' : requires [ i ] . rank
175+ } ) ;
176+ }
177+
178+ // Sort the require statements:
179+ requireDeclarations . sort ( sortRequires ) ;
180+
181+ // Build the replacement text:
182+ for ( i = 0 ; i < requireDeclarations . length ; i ++ ) {
183+ txt = requireDeclarations [ i ] . text ;
184+ if ( ! txt . startsWith ( 'var' ) ) {
185+ txt = 'var ' + txt ;
186+ }
187+ if ( ! txt . endsWith ( ';' ) ) {
188+ txt += ';' ;
189+ }
190+ replacingText += txt ;
191+ if ( i < requireDeclarations . length - 1 ) {
192+ replacingText += '\n' ;
193+ }
194+ }
195+ return fixer . replaceTextRange ( [ startRange , endRange ] , replacingText ) ; // eslint-disable-line max-len
196+ }
197+
143198 /**
144199 * Reports the error message.
145200 *
@@ -160,61 +215,6 @@ function main( context ) {
160215 'fix' : fix
161216 } ) ;
162217 }
163-
164- /**
165- * Fixes the lint error by reordering the require statements.
166- *
167- * @private
168- * @param {Function } fixer - ESLint fixer
169- * @returns {(Object|Null) } fix or null
170- */
171- function fix ( fixer ) {
172- var requireDeclarations ;
173- var replacingText ;
174- var startRange ;
175- var endRange ;
176- var source ;
177- var elem ;
178- var txt ;
179- var i ;
180-
181- replacingText = '' ;
182- requireDeclarations = [ ] ;
183- source = context . getSourceCode ( ) ;
184-
185- // Get the text and rank for the require statements:
186- for ( i = 0 ; i < requires . length ; i ++ ) {
187- elem = requires [ i ] . node . parent . parent ;
188- txt = source . getText ( elem ) ;
189- if ( i === 0 ) {
190- startRange = elem . range [ 0 ] - elem . loc . start . column ;
191- }
192- endRange = elem . range [ 1 ] ;
193- requireDeclarations . push ( {
194- 'text' : txt ,
195- 'rank' : requires [ i ] . rank
196- } ) ;
197- }
198-
199- // Sort the require statements:
200- requireDeclarations . sort ( sortRequires ) ;
201-
202- // Build the replacement text:
203- for ( i = 0 ; i < requireDeclarations . length ; i ++ ) {
204- txt = requireDeclarations [ i ] . text ;
205- if ( ! txt . startsWith ( 'var' ) ) {
206- txt = 'var ' + txt ;
207- }
208- if ( ! txt . endsWith ( ';' ) ) {
209- txt += ';' ;
210- }
211- replacingText += txt ;
212- if ( i < requireDeclarations . length - 1 ) {
213- replacingText += '\n' ;
214- }
215- }
216- return fixer . replaceTextRange ( [ startRange , endRange ] , replacingText ) ; // eslint-disable-line max-len
217- }
218218 }
219219
220220 /**
0 commit comments