Skip to content

Commit

Permalink
[Refactor] jsx-indent: clean up the fixer function
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 2, 2022
1 parent f8b4aa3 commit 27e94ba
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rules/jsx-indent.js
Expand Up @@ -104,13 +104,17 @@ module.exports = {
* @private
*/
function getFixerFunction(node, needed) {
return function fix(fixer) {
const indent = Array(needed + 1).join(indentChar);
if (node.type === 'JSXText' || node.type === 'Literal') {
const indent = Array(needed + 1).join(indentChar);

if (node.type === 'JSXText' || node.type === 'Literal') {
return function fix(fixer) {
const regExp = /\n[\t ]*(\S)/g;
const fixedText = node.raw.replace(regExp, (match, p1) => `\n${indent}${p1}`);
return fixer.replaceText(node, fixedText);
}
};
}

return function fix(fixer) {
return fixer.replaceTextRange(
[node.range[0] - node.loc.start.column, node.range[0]],
indent
Expand Down

0 comments on commit 27e94ba

Please sign in to comment.