Unify ESLint and Prettier across xplat/yoga (#1335)

Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1335

Reviewed By: christophpurrer

Differential Revision: D47459866

fbshipit-source-id: fd6b4e4e2518d91968ac7180b32129b3f70edf88
This commit is contained in:
Nick Gerleman
2023-07-17 14:27:32 -07:00
committed by Facebook GitHub Bot
parent 05b2edfb85
commit 44507ec62e
35 changed files with 2064 additions and 1559 deletions

View File

@@ -5,254 +5,485 @@
* LICENSE file in the root directory of this source tree.
*/
/* global Emitter:readable */
function toValueCpp(value) {
var n = value.toString().replace('px','').replace('%','');
const n = value.toString().replace('px', '').replace('%', '');
return n + (Number(n) == n && n % 1 !== 0 ? 'f' : '');
}
function toFunctionName(value) {
if (value.indexOf('%') >= 0) {
return 'Percent';
} else if(value.indexOf('Auto') >= 0) {
} else if (value.indexOf('Auto') >= 0) {
return 'Auto';
}
return '';
}
var CPPEmitter = function() {
const CPPEmitter = function () {
Emitter.call(this, 'cpp', ' ');
};
CPPEmitter.prototype = Object.create(Emitter.prototype, {
constructor:{value:CPPEmitter},
constructor: {value: CPPEmitter},
emitPrologue:{value:function() {
this.push([
'#include <gtest/gtest.h>',
'#include <yoga/Yoga.h>',
'',
]);
}},
emitPrologue: {
value: function () {
this.push(['#include <gtest/gtest.h>', '#include <yoga/Yoga.h>', '']);
},
},
emitTestPrologue:{value:function(name, experiments, disabled) {
this.push('TEST(YogaTest, ' + name + ') {');
this.pushIndent();
emitTestPrologue: {
value: function (name, experiments, disabled) {
this.push('TEST(YogaTest, ' + name + ') {');
this.pushIndent();
if (disabled) {
this.push('GTEST_SKIP();');
if (disabled) {
this.push('GTEST_SKIP();');
this.push('');
}
this.push('const YGConfigRef config = YGConfigNew();');
for (const i in experiments) {
this.push(
'YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeature' +
experiments[i] +
', true);',
);
}
this.push('');
}
},
},
this.push('const YGConfigRef config = YGConfigNew();')
for (var i in experiments) {
this.push('YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeature' + experiments[i] +', true);');
}
this.push('');
}},
emitTestTreePrologue: {
value: function (nodeName) {
this.push(
'const YGNodeRef ' + nodeName + ' = YGNodeNewWithConfig(config);',
);
},
},
emitTestTreePrologue:{value:function(nodeName) {
this.push('const YGNodeRef ' + nodeName + ' = YGNodeNewWithConfig(config);');
}},
emitTestEpilogue: {
value: function (_experiments) {
this.push(['', 'YGNodeFreeRecursive(root);']);
emitTestEpilogue:{value:function(experiments) {
this.push([
'',
'YGNodeFreeRecursive(root);',
]);
this.push('');
this.push('YGConfigFree(config);');
this.push('');
this.push('YGConfigFree(config);')
this.popIndent();
this.push(['}', '']);
},
},
this.popIndent();
this.push([
'}',
'',
]);
}},
emitEpilogue: {value: function () {}},
emitEpilogue:{value:function() {
}},
AssertEQ: {
value: function (v0, v1) {
this.push('ASSERT_FLOAT_EQ(' + toValueCpp(v0) + ', ' + v1 + ');');
},
},
AssertEQ:{value:function(v0, v1) {
this.push('ASSERT_FLOAT_EQ(' + toValueCpp(v0) + ', ' + v1 + ');');
}},
YGAlignAuto: {value: 'YGAlignAuto'},
YGAlignCenter: {value: 'YGAlignCenter'},
YGAlignFlexEnd: {value: 'YGAlignFlexEnd'},
YGAlignFlexStart: {value: 'YGAlignFlexStart'},
YGAlignStretch: {value: 'YGAlignStretch'},
YGAlignSpaceBetween: {value: 'YGAlignSpaceBetween'},
YGAlignSpaceAround: {value: 'YGAlignSpaceAround'},
YGAlignBaseline: {value: 'YGAlignBaseline'},
YGAlignAuto:{value:'YGAlignAuto'},
YGAlignCenter:{value:'YGAlignCenter'},
YGAlignFlexEnd:{value:'YGAlignFlexEnd'},
YGAlignFlexStart:{value:'YGAlignFlexStart'},
YGAlignStretch:{value:'YGAlignStretch'},
YGAlignSpaceBetween:{value:'YGAlignSpaceBetween'},
YGAlignSpaceAround:{value:'YGAlignSpaceAround'},
YGAlignBaseline:{value:'YGAlignBaseline'},
YGDirectionInherit: {value: 'YGDirectionInherit'},
YGDirectionLTR: {value: 'YGDirectionLTR'},
YGDirectionRTL: {value: 'YGDirectionRTL'},
YGDirectionInherit:{value:'YGDirectionInherit'},
YGDirectionLTR:{value:'YGDirectionLTR'},
YGDirectionRTL:{value:'YGDirectionRTL'},
YGEdgeBottom: {value: 'YGEdgeBottom'},
YGEdgeEnd: {value: 'YGEdgeEnd'},
YGEdgeLeft: {value: 'YGEdgeLeft'},
YGEdgeRight: {value: 'YGEdgeRight'},
YGEdgeStart: {value: 'YGEdgeStart'},
YGEdgeTop: {value: 'YGEdgeTop'},
YGEdgeBottom:{value:'YGEdgeBottom'},
YGEdgeEnd:{value:'YGEdgeEnd'},
YGEdgeLeft:{value:'YGEdgeLeft'},
YGEdgeRight:{value:'YGEdgeRight'},
YGEdgeStart:{value:'YGEdgeStart'},
YGEdgeTop:{value:'YGEdgeTop'},
YGGutterAll: {value: 'YGGutterAll'},
YGGutterColumn: {value: 'YGGutterColumn'},
YGGutterRow: {value: 'YGGutterRow'},
YGGutterAll:{value:'YGGutterAll'},
YGGutterColumn:{value:'YGGutterColumn'},
YGGutterRow:{value:'YGGutterRow'},
YGFlexDirectionColumn: {value: 'YGFlexDirectionColumn'},
YGFlexDirectionColumnReverse: {value: 'YGFlexDirectionColumnReverse'},
YGFlexDirectionRow: {value: 'YGFlexDirectionRow'},
YGFlexDirectionRowReverse: {value: 'YGFlexDirectionRowReverse'},
YGFlexDirectionColumn:{value:'YGFlexDirectionColumn'},
YGFlexDirectionColumnReverse:{value:'YGFlexDirectionColumnReverse'},
YGFlexDirectionRow:{value:'YGFlexDirectionRow'},
YGFlexDirectionRowReverse:{value:'YGFlexDirectionRowReverse'},
YGJustifyCenter: {value: 'YGJustifyCenter'},
YGJustifyFlexEnd: {value: 'YGJustifyFlexEnd'},
YGJustifyFlexStart: {value: 'YGJustifyFlexStart'},
YGJustifySpaceAround: {value: 'YGJustifySpaceAround'},
YGJustifySpaceBetween: {value: 'YGJustifySpaceBetween'},
YGJustifySpaceEvenly: {value: 'YGJustifySpaceEvenly'},
YGJustifyCenter:{value:'YGJustifyCenter'},
YGJustifyFlexEnd:{value:'YGJustifyFlexEnd'},
YGJustifyFlexStart:{value:'YGJustifyFlexStart'},
YGJustifySpaceAround:{value:'YGJustifySpaceAround'},
YGJustifySpaceBetween:{value:'YGJustifySpaceBetween'},
YGJustifySpaceEvenly:{value:'YGJustifySpaceEvenly'},
YGOverflowHidden: {value: 'YGOverflowHidden'},
YGOverflowVisible: {value: 'YGOverflowVisible'},
YGOverflowHidden:{value:'YGOverflowHidden'},
YGOverflowVisible:{value:'YGOverflowVisible'},
YGPositionTypeAbsolute: {value: 'YGPositionTypeAbsolute'},
YGPositionTypeRelative: {value: 'YGPositionTypeRelative'},
YGPositionTypeAbsolute:{value:'YGPositionTypeAbsolute'},
YGPositionTypeRelative:{value:'YGPositionTypeRelative'},
YGWrapNoWrap: {value: 'YGWrapNoWrap'},
YGWrapWrap: {value: 'YGWrapWrap'},
YGWrapWrapReverse: {value: 'YGWrapWrapReverse'},
YGWrapNoWrap:{value:'YGWrapNoWrap'},
YGWrapWrap:{value:'YGWrapWrap'},
YGWrapWrapReverse:{value: 'YGWrapWrapReverse'},
YGUndefined: {value: 'YGUndefined'},
YGUndefined:{value:'YGUndefined'},
YGDisplayFlex: {value: 'YGDisplayFlex'},
YGDisplayNone: {value: 'YGDisplayNone'},
YGAuto: {value: 'YGAuto'},
YGDisplayFlex:{value:'YGDisplayFlex'},
YGDisplayNone:{value:'YGDisplayNone'},
YGAuto:{value:'YGAuto'},
YGNodeCalculateLayout: {
value: function (node, dir, _experiments) {
this.push(
'YGNodeCalculateLayout(' +
node +
', YGUndefined, YGUndefined, ' +
dir +
');',
);
},
},
YGNodeInsertChild: {
value: function (parentName, nodeName, index) {
this.push(
'YGNodeInsertChild(' +
parentName +
', ' +
nodeName +
', ' +
index +
');',
);
},
},
YGNodeCalculateLayout:{value:function(node, dir, experiments) {
this.push('YGNodeCalculateLayout(' + node + ', YGUndefined, YGUndefined, ' + dir + ');');
}},
YGNodeLayoutGetLeft: {
value: function (nodeName) {
return 'YGNodeLayoutGetLeft(' + nodeName + ')';
},
},
YGNodeInsertChild:{value:function(parentName, nodeName, index) {
this.push('YGNodeInsertChild(' + parentName + ', ' + nodeName + ', ' + index + ');');
}},
YGNodeLayoutGetTop: {
value: function (nodeName) {
return 'YGNodeLayoutGetTop(' + nodeName + ')';
},
},
YGNodeLayoutGetLeft:{value:function(nodeName) {
return 'YGNodeLayoutGetLeft(' + nodeName + ')';
}},
YGNodeLayoutGetWidth: {
value: function (nodeName) {
return 'YGNodeLayoutGetWidth(' + nodeName + ')';
},
},
YGNodeLayoutGetTop:{value:function(nodeName) {
return 'YGNodeLayoutGetTop(' + nodeName + ')';
}},
YGNodeLayoutGetHeight: {
value: function (nodeName) {
return 'YGNodeLayoutGetHeight(' + nodeName + ')';
},
},
YGNodeLayoutGetWidth:{value:function(nodeName) {
return 'YGNodeLayoutGetWidth(' + nodeName + ')';
}},
YGNodeStyleSetAlignContent: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetAlignContent(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeLayoutGetHeight:{value:function(nodeName) {
return 'YGNodeLayoutGetHeight(' + nodeName + ')';
}},
YGNodeStyleSetAlignItems: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetAlignItems(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetAlignContent:{value:function(nodeName, value) {
this.push('YGNodeStyleSetAlignContent(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetAlignSelf: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetAlignSelf(' + nodeName + ', ' + toValueCpp(value) + ');',
);
},
},
YGNodeStyleSetAlignItems:{value:function(nodeName, value) {
this.push('YGNodeStyleSetAlignItems(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetBorder: {
value: function (nodeName, edge, value) {
this.push(
'YGNodeStyleSetBorder(' +
nodeName +
', ' +
edge +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetAlignSelf:{value:function(nodeName, value) {
this.push('YGNodeStyleSetAlignSelf(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetDirection: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetDirection(' + nodeName + ', ' + toValueCpp(value) + ');',
);
},
},
YGNodeStyleSetBorder:{value:function(nodeName, edge, value) {
this.push('YGNodeStyleSetBorder(' + nodeName + ', ' + edge + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetDisplay: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetDisplay(' + nodeName + ', ' + toValueCpp(value) + ');',
);
},
},
YGNodeStyleSetDirection:{value:function(nodeName, value) {
this.push('YGNodeStyleSetDirection(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexBasis' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetDisplay:{value:function(nodeName, value) {
this.push('YGNodeStyleSetDisplay(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetFlexDirection: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexDirection(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetFlexBasis:{value:function(nodeName, value) {
this.push('YGNodeStyleSetFlexBasis' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetFlexGrow: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexGrow(' + nodeName + ', ' + toValueCpp(value) + ');',
);
},
},
YGNodeStyleSetFlexDirection:{value:function(nodeName, value) {
this.push('YGNodeStyleSetFlexDirection(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetFlexShrink: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexShrink(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetFlexGrow:{value:function(nodeName, value) {
this.push('YGNodeStyleSetFlexGrow(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetFlexWrap: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexWrap(' + nodeName + ', ' + toValueCpp(value) + ');',
);
},
},
YGNodeStyleSetFlexShrink:{value:function(nodeName, value) {
this.push('YGNodeStyleSetFlexShrink(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetHeight' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetFlexWrap:{value:function(nodeName, value) {
this.push('YGNodeStyleSetFlexWrap(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetJustifyContent(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetHeight:{value:function(nodeName, value) {
this.push('YGNodeStyleSetHeight' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetMargin: {
value: function (nodeName, edge, value) {
let valueStr = toValueCpp(value);
if (valueStr != 'YGAuto') {
valueStr = ', ' + valueStr;
} else {
valueStr = '';
}
this.push(
'YGNodeStyleSetMargin' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
edge +
valueStr +
');',
);
},
},
YGNodeStyleSetJustifyContent:{value:function(nodeName, value) {
this.push('YGNodeStyleSetJustifyContent(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMaxHeight' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetMargin:{value:function(nodeName, edge, value) {
var valueStr = toValueCpp(value);
if (valueStr != 'YGAuto') {
valueStr = ', ' + valueStr;
} else {
valueStr = '';
}
this.push('YGNodeStyleSetMargin' + toFunctionName(value) + '(' + nodeName + ', ' + edge + valueStr + ');');
}},
YGNodeStyleSetMaxWidth: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMaxWidth' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetMaxHeight:{value:function(nodeName, value) {
this.push('YGNodeStyleSetMaxHeight' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetMinHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMinHeight' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetMaxWidth:{value:function(nodeName, value) {
this.push('YGNodeStyleSetMaxWidth' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetMinWidth: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMinWidth' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetMinHeight:{value:function(nodeName, value) {
this.push('YGNodeStyleSetMinHeight' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetOverflow: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetOverflow(' + nodeName + ', ' + toValueCpp(value) + ');',
);
},
},
YGNodeStyleSetMinWidth:{value:function(nodeName, value) {
this.push('YGNodeStyleSetMinWidth' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetPadding: {
value: function (nodeName, edge, value) {
this.push(
'YGNodeStyleSetPadding' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
edge +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetOverflow:{value:function(nodeName, value) {
this.push('YGNodeStyleSetOverflow(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetPosition: {
value: function (nodeName, edge, value) {
this.push(
'YGNodeStyleSetPosition' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
edge +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetPadding:{value:function(nodeName, edge, value) {
this.push('YGNodeStyleSetPadding' + toFunctionName(value) + '(' + nodeName + ', ' + edge + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetPositionType: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetPositionType(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetPosition:{value:function(nodeName, edge, value) {
this.push('YGNodeStyleSetPosition' + toFunctionName(value) + '(' + nodeName + ', ' + edge + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetWidth' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetPositionType:{value:function(nodeName, value) {
this.push('YGNodeStyleSetPositionType(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetWidth:{value:function(nodeName, value) {
this.push('YGNodeStyleSetWidth' + toFunctionName(value) + '(' + nodeName + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetGap:{value:function(nodeName, gap, value) {
this.push('YGNodeStyleSetGap' + toFunctionName(value) + '(' + nodeName + ', ' + gap + ', ' + toValueCpp(value) + ');');
}},
YGNodeStyleSetGap: {
value: function (nodeName, gap, value) {
this.push(
'YGNodeStyleSetGap' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
gap +
', ' +
toValueCpp(value) +
');',
);
},
},
});