Updated to use eslint from fbjs-scripts

This commit is contained in:
Colin Eberhardt
2015-10-07 21:52:22 +01:00
parent 040f0f3e7c
commit e4c93e8c59
11 changed files with 66 additions and 207 deletions

View File

@@ -56,7 +56,7 @@ function __transpileToCSharpCommon(code) {
// additional case conversions
.replace(/(CSSConstants|CSSWrap|CSSJustify|CSSAlign|CSSPositionType)\.([_A-Z]+)/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.' + constantToPascalCase(match2);
});
}
@@ -67,35 +67,35 @@ function __transpileSingleTestToCSharp(code) {
.replace(/CSS_FLEX_DIRECTION_/g, 'CSSFlexDirection.')
.replace(/CSS_WRAP/g, 'CSSWrap.WRAP')
.replace(/new_test_css_node/g, 'new TestCSSNode')
.replace( // style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP]
.replace(// style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP]
/(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.position[POSITION_' + match2 + ']';
})
.replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH]
.replace(// style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH]
/(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.dimensions[DIMENSION_' + match2 + ']';
})
.replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth
.replace(// style.maxDimensions[CSS_WIDTH] => style.maxWidth
/(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
})
.replace( // style.minDimensions[CSS_WIDTH] => style.minWidth
.replace(// style.minDimensions[CSS_WIDTH] => style.minWidth
/(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
})
.replace( // style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3)
.replace(// style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3)
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g,
function (str, match1, match2, match3) {
function(str, match1, match2, match3) {
var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1);
return 'set' + propertyCap + '(Spacing.' + match2 + ', ' + match3 + ')';
})
.replace( // style.margin[CSS_TOP] => style.margin[Spacing.TOP]
.replace(// style.margin[CSS_TOP] => style.margin[Spacing.TOP]
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return 'style.' + match1 + '.get(Spacing.' + match2 + ')';
})
.replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)')
@@ -103,9 +103,9 @@ function __transpileSingleTestToCSharp(code) {
.replace(/css_node_t(\s)\*/g, 'TestCSSNode$1')
.replace(/\->/g, '.')
.replace(/(\d+\.\d+)/g, '$1f')
.replace( // style.flex_direction => style.flexDirection
.replace(// style.flex_direction => style.flexDirection
/style\.([^_\[\]\s]+)_(\w)(\w+)/g,
function (str, match1, match2, match3) {
function(str, match1, match2, match3) {
return 'style.' + match1 + match2.toUpperCase() + match3;
})
.replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);')
@@ -113,7 +113,7 @@ function __transpileSingleTestToCSharp(code) {
// additional case conversions
.replace(/(CSSWrap|CSSFlexDirection)\.([_A-Z]+)/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.' + constantToPascalCase(match2);
});
}
@@ -129,7 +129,7 @@ function constantToPascalCase(str) {
return str[0] + str.substr(1)
.toLowerCase()
.replace(/_(.)/g,
function (_, m) { return m.toUpperCase(); });
function(_, m) { return m.toUpperCase(); });
}
var CSharpTranspiler = {
@@ -168,7 +168,7 @@ var CSharpTranspiler = {
}
return allTestsInCSharp.join('\n\n');
}
}
};
if (typeof module !== 'undefined') {
module.exports = CSharpTranspiler;

View File

@@ -51,7 +51,7 @@ function __transpileToJavaCommon(code) {
.replace(/isUndefined\((.+?)\)/g, 'Float.isNaN\($1\)')
.replace(/\/\*\(c\)!([^*]+)\*\//g, '')
.replace(/var\/\*\(java\)!([^*]+)\*\//g, '$1')
.replace(/\/\*\(java\)!([^*]+)\*\//g, '$1')
.replace(/\/\*\(java\)!([^*]+)\*\//g, '$1');
}
function __transpileSingleTestToJava(code) {
@@ -60,35 +60,35 @@ function __transpileSingleTestToJava(code) {
.replace(/CSS_FLEX_DIRECTION_/g, 'CSSFlexDirection.')
.replace(/CSS_WRAP/g, 'CSSWrap.WRAP')
.replace(/new_test_css_node/g, 'new TestCSSNode')
.replace( // style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP]
.replace(// style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP]
/(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.position[POSITION_' + match2 + ']';
})
.replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH]
.replace(// style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH]
/(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.dimensions[DIMENSION_' + match2 + ']';
})
.replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth
.replace(// style.maxDimensions[CSS_WIDTH] => style.maxWidth
/(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
})
.replace( // style.minDimensions[CSS_WIDTH] => style.minWidth
.replace(// style.minDimensions[CSS_WIDTH] => style.minWidth
/(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase();
})
.replace( // style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3)
.replace(// style.margin[CSS_TOP] = 12.3 => style.margin[Spacing.TOP].set(12.3)
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g,
function (str, match1, match2, match3) {
function(str, match1, match2, match3) {
var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1);
return 'set' + propertyCap + '(Spacing.' + match2 + ', ' + match3 + ')';
})
.replace( // style.margin[CSS_TOP] => style.margin[Spacing.TOP]
.replace(// style.margin[CSS_TOP] => style.margin[Spacing.TOP]
/style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g,
function (str, match1, match2) {
function(str, match1, match2) {
return 'style.' + match1 + '.get(Spacing.' + match2 + ')';
})
.replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)')
@@ -96,9 +96,9 @@ function __transpileSingleTestToJava(code) {
.replace(/css_node_t(\s)\*/g, 'TestCSSNode$1')
.replace(/\->/g, '.')
.replace(/(\d+\.\d+)/g, '$1f')
.replace( // style.flex_direction => style.flexDirection
.replace(// style.flex_direction => style.flexDirection
/style\.([^_\[\]\s]+)_(\w)(\w+)/g,
function (str, match1, match2, match3) {
function(str, match1, match2, match3) {
return 'style.' + match1 + match2.toUpperCase() + match3;
})
.replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);');

View File

@@ -23,13 +23,13 @@ var layoutTestUtils = (function() {
var testMeasurePrecision = 1.0;
if (typeof jasmine !== 'undefined') {
jasmine.matchersUtil.buildFailureMessage = function () {
var args = Array.prototype.slice.call(arguments, 0),
matcherName = args[0],
isNot = args[1],
actual = args[2],
expected = args.slice(3),
englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
jasmine.matchersUtil.buildFailureMessage = function() {
var args = Array.prototype.slice.call(arguments, 0);
var matcherName = args[0];
var isNot = args[1];
var actual = args[2];
var expected = args.slice(3);
var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
var pp = function(node) {
return jasmine.pp(node)
@@ -278,8 +278,7 @@ var layoutTestUtils = (function() {
var val = obj[key];
if (typeof val === 'number') {
obj[key] = Math.floor((val * testMeasurePrecision) + 0.5) / testMeasurePrecision;
}
else if (typeof val === 'object') {
} else if (typeof val === 'object') {
inplaceRoundNumbersInObject(val);
}
}
@@ -386,7 +385,7 @@ var layoutTestUtils = (function() {
document.body.appendChild(iframeText);
var body = iframeText.contentDocument.body;
if (width === undefined || width !== width) {
if (width === undefined || isNaN(width)) {
width = Infinity;
}
@@ -490,7 +489,7 @@ var layoutTestUtils = (function() {
reduceTest: reduceTest,
text: function(text) {
var fn = function(width) {
if (width === undefined || width !== width) {
if (width === undefined || isNaN(width)) {
width = Infinity;
}

View File

@@ -989,7 +989,10 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
// For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis
if (child->style.position_type == CSS_POSITION_RELATIVE) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
css_align_t alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem == CSS_ALIGN_STRETCH) {
// You can only stretch if the dimension has not already been set
// previously.

View File

@@ -911,7 +911,10 @@ var computeLayout = (function() {
// For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis
if (getPositionType(child) === CSS_POSITION_RELATIVE) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
var/*css_align_t*/ alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem === CSS_ALIGN_STRETCH) {
// You can only stretch if the dimension has not already been set
// previously.

View File

@@ -718,7 +718,10 @@ namespace Facebook.CSSLayout
// For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis
if (child.style.positionType == CSSPositionType.Relative) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
CSSAlign alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem == CSSAlign.Stretch) {
// You can only stretch if the dimension has not already been set
// previously.

View File

@@ -3,7 +3,7 @@
//
// This file uses the following specific UMD implementation:
// https://github.com/umdjs/umd/blob/master/returnExports.js
(function (root, factory) {
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
@@ -16,11 +16,14 @@
// Browser globals (root is window)
root.computeLayout = factory();
}
}(this, function () {
}(this, function() {
// @@include('./Layout.js')
return function(node) {
/*eslint-disable */
// disabling ESLint because this code relies on the above include
computeLayout.fillNodes(node);
computeLayout.computeLayout(node);
/*eslint-enable */
};
}));

View File

@@ -692,7 +692,10 @@ public class LayoutEngine {
// For a relative children, we're either using alignItems (parent) or
// alignSelf (child) in order to determine the position in the cross axis
if (child.style.positionType == CSSPositionType.RELATIVE) {
/*eslint-disable */
// This variable is intentionally re-defined as the code is transpiled to a block scope language
CSSAlign alignItem = getAlignItem(node, child);
/*eslint-enable */
if (alignItem == CSSAlign.STRETCH) {
// You can only stretch if the dimension has not already been set
// previously.