You can convert js-code like this:
var a = '1',
b,
c = '2';
into
const a = '1';
let b;
const c = '2';
just install npm-package jscodeshift
and run:
jscodeshift -t transform.js <file_to_transform>
module.exports = function(fileInfo, api, options) { | |
const j = api.jscodeshift; | |
return j(fileInfo.source) | |
.find(j.VariableDeclaration) | |
.replaceWith(path => { | |
return path.value.declarations.map(declaration => { | |
let var_dec; | |
if (path.value.kind === 'var') { | |
var_dec = declaration.init ? 'const' : 'let'; | |
} else { | |
var_dec = path.value.kind; | |
} | |
return j.variableDeclaration(var_dec, [declaration]); | |
}); | |
}) | |
.toSource(); | |
}; |