2121// MODULES //
2222
2323var startsWith = require ( '@stdlib/string/starts-with' ) ;
24+ var endsWith = require ( '@stdlib/string/ends-with' ) ;
2425var hasOwnProp = require ( '@stdlib/assert/has-own-property' ) ;
2526var isNodeBuiltin = require ( '@stdlib/assert/is-node-builtin' ) ;
2627var isString = require ( '@stdlib/assert/is-string' ) . isPrimitive ;
@@ -99,6 +100,21 @@ function rank( order, regexps, name ) {
99100 return indexOf ( order , type ) ;
100101}
101102
103+ /**
104+ * Sorts `require` statements based on their ranks.
105+ *
106+ * @private
107+ * @param {Object } a - first require statement
108+ * @param {Object } b - second require statement
109+ * @returns {number } number indicating sort order
110+ */
111+ function sortRequires ( a , b ) {
112+ if ( a . rank < b . rank ) {
113+ return - 1 ;
114+ }
115+ return 1 ;
116+ }
117+
102118/**
103119* Rule for validating `require()` calls follow a specified order.
104120*
@@ -125,21 +141,6 @@ function main( context ) {
125141 }
126142 }
127143
128- /**
129- * Sorts `require` statements based on their ranks.
130- *
131- * @private
132- * @param {Object } a - first require statement
133- * @param {Object } b - second require statement
134- * @returns {number } number indicating sort order
135- */
136- function sortRequires ( a , b ) {
137- if ( a . rank < b . rank ) {
138- return - 1 ;
139- }
140- return 1 ;
141- }
142-
143144 /**
144145 * Fixes the lint error by reordering the require statements.
145146 *
@@ -181,10 +182,10 @@ function main( context ) {
181182 // Build the replacement text:
182183 for ( i = 0 ; i < requireDeclarations . length ; i ++ ) {
183184 txt = requireDeclarations [ i ] . text ;
184- if ( ! txt . startsWith ( 'var' ) ) {
185+ if ( ! startsWith ( txt , 'var' ) ) {
185186 txt = 'var ' + txt ;
186187 }
187- if ( ! txt . endsWith ( ';' ) ) {
188+ if ( ! endsWith ( txt , ';' ) ) {
188189 txt += ';' ;
189190 }
190191 replacingText += txt ;
0 commit comments