@putout/plugin-putout-config
Version:
🐊Putout plugin helps to maintain putout config
34 lines (28 loc) • 717 B
JavaScript
import {operator} from 'putout';
const {
traverseProperties,
__json,
setLiteralValue,
} = operator;
export const createRenameProperty = (tuples) => ({
report,
fix,
traverse: createTraverse(tuples),
});
const report = ({from, to}) => `Rename property: '${from}' -> '${to}'`;
const fix = ({path, to}) => {
setLiteralValue(path.node.key, to);
};
const createTraverse = (tuples) => ({push}) => ({
[__json](mainPath) {
for (const [from, to] of tuples) {
for (const path of traverseProperties(mainPath, from)) {
push({
path,
from,
to,
});
}
}
},
});