Skip to content
51 changes: 36 additions & 15 deletions lib/node_modules/@stdlib/_tools/eslint/rules/vars-order/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,6 @@ function main( context ) {
break;
}

/**
* Reports the error message.
*
* @private
* @param {string} msg - error message
* @param {Object} loc - lines of code (object with `start` and `end` properties)
*/
function report( msg, loc ) {
context.report({
'node': null,
'message': msg,
'loc': loc
});
}

/**
* Checks whether the variable declarations inside of the supplied node are ordered.
*
Expand All @@ -122,6 +107,42 @@ function main( context ) {
prevLength = name.length;
}
}

/**
* Reports the error message.
*
* @private
* @param {string} msg - error message
* @param {Object} loc - lines of code (object with `start` and `end` properties)
*/
function report( msg, loc ) {
context.report({
'node': null,
'message': msg,
'loc': loc,
'fix': fix
});
}

/**
* Fixes the lint error by reordering the variable declarations inside of the function.
*
* @private
* @param {Function} fixer - ESLint fixer
* @returns {(Object|null)} fix or null
*/
function fix(fixer) {
var replacingText;
var prevElem;
var source;

source = context.getSourceCode();
prevElem = body[ i - 1 ];

replacingText = source.getText( elem, 4 ) + '\n' + source.getText( prevElem, 4 );

return fixer.replaceTextRange( [ prevElem.range[0] -prevElem.loc.start.column, elem.range[1] ], replacingText ); // eslint-disable-line max-len
}
}

return {
Expand Down