Skip to content

Instantly share code, notes, and snippets.

@aj0strow
Created November 5, 2015 22:28
Show Gist options
  • Save aj0strow/3fc70f4cbb4de0b0e2d6 to your computer and use it in GitHub Desktop.
Save aj0strow/3fc70f4cbb4de0b0e2d6 to your computer and use it in GitHub Desktop.
Codemod script to prefer self-closing JSX tags
// jscodeshift -t self-closing-jsx-tags.js ./src
module.exports = function(file, api) {
let j = api.jscodeshift
let root = j(file.source)
root.find(j.JSXElement)
.filter(function (path) {
return !path.value.children.length
})
.forEach(function (path) {
path.value.openingElement.selfClosing = true
path.value.closingElement = null
})
return root.toSource()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment