Add Prettier Formatting (#258)

* Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs

* Remove trailing-comma as we are using Node 6 on Circle

* Use latest Node 6 LTS version in Circle

* Remove unused test
This commit is contained in:
Héctor Ramos 2017-12-04 19:21:02 -08:00 committed by Joel Marcey
parent 0cead4b6f9
commit 65421db62e
50 changed files with 1376 additions and 1350 deletions

View file

@ -8,40 +8,40 @@
/* replaces translate tags with calls to translate function */
module.exports = function translatePlugin(babel) {
const { types: t } = babel;
const {types: t} = babel;
return {
visitor: {
JSXElement(path) {
if (path.node.openingElement.name.name !== "translate") {
if (path.node.openingElement.name.name !== 'translate') {
return;
}
/* assume translate element only has one child which is the text */
const text = path.node.children[0].value.trim().replace(/\s+/g, " ");
let description = "no description given";
const text = path.node.children[0].value.trim().replace(/\s+/g, ' ');
let description = 'no description given';
const attributes = path.node.openingElement.attributes;
for (let i = 0; i < attributes.length; i++) {
if (attributes[i].name.name === "desc") {
if (attributes[i].name.name === 'desc') {
description = attributes[i].value.value;
}
}
/* use an expression container if inside a jsxelement */
if (path.findParent(path => true).node.type === "JSXElement") {
if (path.findParent(path => true).node.type === 'JSXElement') {
path.replaceWith(
t.jSXExpressionContainer(
t.callExpression(t.identifier("translate"), [
t.stringLiteral(text + "|" + description)
t.callExpression(t.identifier('translate'), [
t.stringLiteral(text + '|' + description),
])
)
);
} else {
path.replaceWith(
t.callExpression(t.identifier("translate"), [
t.stringLiteral(text + "|" + description)
t.callExpression(t.identifier('translate'), [
t.stringLiteral(text + '|' + description),
])
);
}
}
}
},
},
};
};