From 9b75493988888e97e0530c61b5862ab861c9d9dd Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 5 Oct 2015 08:08:57 +0100 Subject: [PATCH 1/8] auto-configured eslint and fixed gruntfile linting failures --- .eslintrc | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++- Gruntfile.js | 22 ++++---- 2 files changed, 163 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index 728f775e..dfb1bd26 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,6 +19,157 @@ "define": true }, "rules": { - "quotes": [2, "single"] + "comma-dangle": 2, + "no-cond-assign": 2, + "no-console": 0, + "no-constant-condition": 2, + "no-control-regex": 2, + "no-debugger": 2, + "no-dupe-args": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-empty-class": 0, + "no-empty": 2, + "no-ex-assign": 2, + "no-extra-boolean-cast": 2, + "no-extra-parens": 0, + "no-extra-semi": 2, + "no-func-assign": 2, + "no-inner-declarations": 2, + "no-invalid-regexp": 2, + "no-irregular-whitespace": 2, + "no-negated-in-lhs": 2, + "no-obj-calls": 2, + "no-regex-spaces": 2, + "no-reserved-keys": 0, + "no-sparse-arrays": 2, + "no-unreachable": 2, + "use-isnan": 2, + "valid-jsdoc": 2, + "valid-typeof": 2, + "block-scoped-var": 0, + "complexity": 2, + "consistent-return": 2, + "curly": 2, + "default-case": 0, + "dot-notation": 2, + "dot-location": 0, + "eqeqeq": 0, + "guard-for-in": 0, + "no-alert": 2, + "no-caller": 2, + "no-div-regex": 2, + "no-else-return": 0, + "no-empty-label": 2, + "no-eq-null": 0, + "no-eval": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-fallthrough": 2, + "no-floating-decimal": 2, + "no-implied-eval": 2, + "no-iterator": 2, + "no-labels": 2, + "no-lone-blocks": 2, + "no-loop-func": 2, + "no-multi-spaces": 0, + "no-multi-str": 2, + "no-native-reassign": 2, + "no-new-func": 2, + "no-new-wrappers": 2, + "no-new": 2, + "no-octal-escape": 2, + "no-octal": 2, + "no-param-reassign": 0, + "no-process-env": 2, + "no-proto": 2, + "no-redeclare": 0, + "no-return-assign": 2, + "no-script-url": 2, + "no-self-compare": 0, + "no-sequences": 2, + "no-throw-literal": 2, + "no-unused-expressions": 2, + "no-void": 2, + "no-warning-comments": 0, + "no-with": 2, + "radix": 2, + "vars-on-top": 0, + "wrap-iife": 0, + "yoda": 2, + "strict": 0, + "no-catch-shadow": 2, + "no-delete-var": 2, + "no-label-var": 2, + "no-shadow-restricted-names": 2, + "no-shadow": 0, + "no-undef-init": 2, + "no-undef": 0, + "no-undefined": 0, + "no-unused-vars": 0, + "no-use-before-define": 0, + "handle-callback-err": 2, + "no-mixed-requires": 2, + "no-new-require": 2, + "no-path-concat": 0, + "no-process-exit": 2, + "no-restricted-modules": 2, + "no-sync": 0, + "brace-style": 0, + "camelcase": 2, + "comma-spacing": 2, + "comma-style": 2, + "consistent-this": 2, + "eol-last": 2, + "func-names": 0, + "func-style": 0, + "indent": 0, + "key-spacing": 2, + "linebreak-style": 2, + "new-cap": 2, + "new-parens": 2, + "newline-after-var": 0, + "no-array-constructor": 2, + "no-continue": 0, + "no-inline-comments": 0, + "no-lonely-if": 2, + "no-mixed-spaces-and-tabs": 2, + "no-multiple-empty-lines": 2, + "no-nested-ternary": 2, + "no-new-object": 2, + "no-spaced-func": 2, + "no-ternary": 0, + "no-trailing-spaces": 0, + "no-underscore-dangle": 0, + "no-unneeded-ternary": 2, + "no-wrap-func": 0, + "one-var": 0, + "operator-assignment": 2, + "operator-linebreak": 0, + "padded-blocks": 0, + "quote-props": 0, + "quotes": 0, + "semi-spacing": 2, + "semi": 0, + "sort-vars": 0, + "space-after-keywords": 2, + "space-before-blocks": 2, + "space-before-function-paren": 0, + "space-in-brackets": 0, + "space-in-parens": 0, + "space-infix-ops": 2, + "space-return-throw-case": 2, + "space-unary-ops": 2, + "spaced-line-comment": 0, + "wrap-regex": 2, + "generator-star-spacing": 2, + "no-var": 0, + "object-shorthand": 0, + "max-depth": 2, + "max-len": 0, + "max-params": 0, + "max-statements": 0, + "no-bitwise": 2, + "no-plusplus": 0 } } diff --git a/Gruntfile.js b/Gruntfile.js index 00aafa56..0858aff3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,7 +3,7 @@ module.exports = function(grunt) { var fs = require('fs'); var path = require('path'); - var isWindows = /^win/.test(process.platform); + var isWindows = (/^win/).test(process.platform); require('load-grunt-tasks')(grunt); @@ -25,7 +25,7 @@ module.exports = function(grunt) { config.cTestOutput = 'c_test.exe'; config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"'; config.cTestExecute = '<%= config.cTestOutput %>'; - config.cTestClean = ['<%= config.cTestOutput %>','*.obj','*.pdb']; + config.cTestClean = ['<%= config.cTestOutput %>', '*.obj', '*.pdb']; } else { // GCC build (OSX, Linux, ...), assumes gcc is in the path. @@ -42,8 +42,8 @@ module.exports = function(grunt) { dist: { options: { create: ['<%= config.distFolder %>'] - }, - }, + } + } }, clean: { @@ -56,12 +56,12 @@ module.exports = function(grunt) { options: { configFile: '.eslintrc' }, - target: ['<%= config.srcFolder %>/Layout.js'] + target: ['<%= config.srcFolder %>/*.js'] }, includereplace: { options: { - prefix: '// @@', + prefix: '// @@' }, main: { src: '<%= config.srcFolder %>/<%= config.libName %>.js', @@ -125,12 +125,12 @@ module.exports = function(grunt) { else { return src; } - }, + } }, dist: { src: ['<%= config.srcFolder %>/Layout.h', '<%= config.srcFolder %>/Layout.c'], - dest: '<%= config.distFolder %>/css-layout.h', - }, + dest: '<%= config.distFolder %>/css-layout.h' + } }, shell: { @@ -153,8 +153,8 @@ module.exports = function(grunt) { watch: { files: ['src/Layout.js'], - tasks: ['ci'], - }, + tasks: ['ci'] + } }); // Compiles and runs the Java tests From 0f43977bb2e50e5d9c769ee31b0a95cbec94ec36 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 5 Oct 2015 12:49:28 +0100 Subject: [PATCH 2/8] Enforced the eqeqeq rule --- .eslintrc | 2 +- src/Layout.js | 88 +++++++++++++++++++++++++-------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.eslintrc b/.eslintrc index dfb1bd26..7d85b783 100644 --- a/.eslintrc +++ b/.eslintrc @@ -54,7 +54,7 @@ "default-case": 0, "dot-notation": 2, "dot-location": 0, - "eqeqeq": 0, + "eqeqeq": 2, "guard-for-in": 0, "no-alert": 2, "no-caller": 2, diff --git a/src/Layout.js b/src/Layout.js index 63165624..1ddec262 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -100,7 +100,7 @@ var computeLayout = (function() { } function getLeadingMargin(node, axis) { - if (node.style.marginStart != null && isRowDirection(axis)) { + if (typeof node.style.marginStart !== 'undefined' && isRowDirection(axis)) { return node.style.marginStart; } @@ -112,11 +112,11 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.marginBottom; break; } - if (value != null) { + if (value !== null && typeof value !== 'undefined') { return value; } - if (node.style.margin != null) { + if (typeof node.style.margin !== 'undefined') { return node.style.margin; } @@ -124,7 +124,7 @@ var computeLayout = (function() { } function getTrailingMargin(node, axis) { - if (node.style.marginEnd != null && isRowDirection(axis)) { + if (typeof node.style.marginEnd !== 'undefined' && isRowDirection(axis)) { return node.style.marginEnd; } @@ -136,11 +136,11 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.marginTop; break; } - if (value != null) { + if (value !== null && typeof value !== 'undefined') { return value; } - if (node.style.margin != null) { + if (typeof node.style.margin !== 'undefined') { return node.style.margin; } @@ -148,7 +148,7 @@ var computeLayout = (function() { } function getLeadingPadding(node, axis) { - if (node.style.paddingStart != null && node.style.paddingStart >= 0 + if (typeof node.style.paddingStart !== 'undefined' && node.style.paddingStart >= 0 && isRowDirection(axis)) { return node.style.paddingStart; } @@ -161,11 +161,11 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.paddingBottom; break; } - if (value != null && value >= 0) { + if (value !== null && value >= 0) { return value; } - if (node.style.padding != null && node.style.padding >= 0) { + if (typeof node.style.padding !== 'undefined' && node.style.padding >= 0) { return node.style.padding; } @@ -173,7 +173,7 @@ var computeLayout = (function() { } function getTrailingPadding(node, axis) { - if (node.style.paddingEnd != null && node.style.paddingEnd >= 0 + if (typeof node.style.paddingEnd !== 'undefined' && node.style.paddingEnd >= 0 && isRowDirection(axis)) { return node.style.paddingEnd; } @@ -186,11 +186,11 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.paddingTop; break; } - if (value != null && value >= 0) { + if (value !== null && value >= 0) { return value; } - if (node.style.padding != null && node.style.padding >= 0) { + if (typeof node.style.padding !== 'undefined' && node.style.padding >= 0) { return node.style.padding; } @@ -198,7 +198,7 @@ var computeLayout = (function() { } function getLeadingBorder(node, axis) { - if (node.style.borderStartWidth != null && node.style.borderStartWidth >= 0 + if (typeof node.style.borderStartWidth !== 'undefined' && node.style.borderStartWidth >= 0 && isRowDirection(axis)) { return node.style.borderStartWidth; } @@ -211,11 +211,11 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.borderBottomWidth; break; } - if (value != null && value >= 0) { + if (value !== null && value >= 0) { return value; } - if (node.style.borderWidth != null && node.style.borderWidth >= 0) { + if (typeof node.style.borderWidth !== 'undefined' && node.style.borderWidth >= 0) { return node.style.borderWidth; } @@ -223,7 +223,7 @@ var computeLayout = (function() { } function getTrailingBorder(node, axis) { - if (node.style.borderEndWidth != null && node.style.borderEndWidth >= 0 + if (typeof node.style.borderEndWidth !== 'undefined' && node.style.borderEndWidth >= 0 && isRowDirection(axis)) { return node.style.borderEndWidth; } @@ -236,17 +236,17 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.borderTopWidth; break; } - if (value != null && value >= 0) { + if (value !== null && value >= 0) { return value; } - if (node.style.borderWidth != null && node.style.borderWidth >= 0) { + if (typeof node.style.borderWidth !== undefined && node.style.borderWidth >= 0) { return node.style.borderWidth; } return 0; } - + function getLeadingPaddingAndBorder(node, axis) { return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); } @@ -357,19 +357,19 @@ var computeLayout = (function() { } function isDimDefined(node, axis) { - return node.style[dim[axis]] != null && node.style[dim[axis]] >= 0; + return typeof node.style[dim[axis]] !== 'undefined' && node.style[dim[axis]] >= 0; } function isPosDefined(node, pos) { - return node.style[pos] != null; + return typeof node.style[pos] !== 'undefined'; } function isMeasureDefined(node) { - return node.style.measure != null; + return typeof node.style.measure !== 'undefined'; } function getPosition(node, pos) { - if (node.style[pos] != null) { + if (typeof node.style[pos] !== 'undefined') { return node.style[pos]; } return 0; @@ -391,10 +391,10 @@ var computeLayout = (function() { }[axis]; var boundValue = value; - if (max != null && max >= 0 && boundValue > max) { + if (max !== null && max >= 0 && boundValue > max) { boundValue = max; } - if (min != null && min >= 0 && boundValue < min) { + if (min !== null && min >= 0 && boundValue < min) { boundValue = min; } return boundValue; @@ -410,7 +410,7 @@ var computeLayout = (function() { // When the user specifically sets a value for width or height function setDimensionFromStyle(node, axis) { // The parent already computed us a width or height. We just skip it - if (node.layout[dim[axis]] != null) { + if (typeof node.layout[dim[axis]] !== 'undefined') { return; } // We only run if there's a width or height defined @@ -433,7 +433,7 @@ var computeLayout = (function() { // If both left and right are defined, then use left. Otherwise return // +left or -right depending on which is defined. function getRelativePosition(node, axis) { - if (node.style[leading[axis]] != null) { + if (typeof node.style[leading[axis]] !== 'undefined') { return getPosition(node, leading[axis]); } return -getPosition(node, trailing[axis]); @@ -565,8 +565,8 @@ var computeLayout = (function() { // immediately stacked in the initial loop will not be touched again // in . var/*bool*/ isSimpleStackMain = - (isMainDimDefined && justifyContent == CSS_JUSTIFY_FLEX_START) || - (!isMainDimDefined && justifyContent != CSS_JUSTIFY_CENTER); + (isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START) || + (!isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER); var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine); // Use the initial line loop to position children in the cross axis for @@ -704,7 +704,7 @@ var computeLayout = (function() { // we found a non-trivial child. The remaining children will be laid out // in . if (isSimpleStackMain && - (getPositionType(child) != CSS_POSITION_RELATIVE || isFlex(child))) { + (getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) { isSimpleStackMain = false; firstComplexMain = i; } @@ -713,8 +713,8 @@ var computeLayout = (function() { // we found a non-trivial child. The remaining children will be laid out // in . if (isSimpleStackCross && - (getPositionType(child) != CSS_POSITION_RELATIVE || - (alignItem !== CSS_ALIGN_STRETCH && alignItem != CSS_ALIGN_FLEX_START) || + (getPositionType(child) !== CSS_POSITION_RELATIVE || + (alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START) || isUndefined(child.layout[dim[crossAxis]]))) { isSimpleStackCross = false; firstComplexCross = i; @@ -1048,8 +1048,8 @@ var computeLayout = (function() { paddingAndBorderAxisMain ); - if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || - mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE || + mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) { needsMainTrailingPos = true; } } @@ -1063,8 +1063,8 @@ var computeLayout = (function() { paddingAndBorderAxisCross ); - if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || - crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE || + crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) { needsCrossTrailingPos = true; } } @@ -1122,19 +1122,19 @@ var computeLayout = (function() { child.nextAbsoluteChild = null; } } - + function layoutNode(node, parentMaxWidth, parentDirection) { node.shouldUpdate = true; - + var direction = node.style.direction || CSS_DIRECTION_LTR; - var skipLayout = + var skipLayout = !node.isDirty && node.lastLayout && node.lastLayout.requestedHeight === node.layout.height && node.lastLayout.requestedWidth === node.layout.width && node.lastLayout.parentMaxWidth === parentMaxWidth && node.lastLayout.direction === direction; - + if (skipLayout) { node.layout.width = node.lastLayout.width; node.layout.height = node.lastLayout.height; @@ -1144,12 +1144,12 @@ var computeLayout = (function() { if (!node.lastLayout) { node.lastLayout = {}; } - + node.lastLayout.requestedWidth = node.layout.width; node.lastLayout.requestedHeight = node.layout.height; node.lastLayout.parentMaxWidth = parentMaxWidth; node.lastLayout.direction = direction; - + // Reset child layouts node.children.forEach(function(child) { child.layout.width = undefined; @@ -1157,9 +1157,9 @@ var computeLayout = (function() { child.layout.top = 0; child.layout.left = 0; }); - + layoutNodeImpl(node, parentMaxWidth, parentDirection); - + node.lastLayout.width = node.layout.width; node.lastLayout.height = node.layout.height; node.lastLayout.top = node.layout.top; From c33e255182e8d0fb0a446634b6dc68075e931d8f Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 5 Oct 2015 13:18:27 +0100 Subject: [PATCH 3/8] Enforced quote style and indentation --- .eslintrc | 6 +++--- src/CSharpTranspiler.js | 22 +++++++++++----------- src/JavaTranspiler.js | 10 +++++----- src/css-layout.js | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7d85b783..e379dfe7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -106,7 +106,7 @@ "no-undef-init": 2, "no-undef": 0, "no-undefined": 0, - "no-unused-vars": 0, + "no-unused-vars": 2, "no-use-before-define": 0, "handle-callback-err": 2, "no-mixed-requires": 2, @@ -123,7 +123,7 @@ "eol-last": 2, "func-names": 0, "func-style": 0, - "indent": 0, + "indent": [2, 2, {"SwitchCase": 1}], "key-spacing": 2, "linebreak-style": 2, "new-cap": 2, @@ -148,7 +148,7 @@ "operator-linebreak": 0, "padded-blocks": 0, "quote-props": 0, - "quotes": 0, + "quotes": [2, "single"], "semi-spacing": 2, "semi": 0, "sort-vars": 0, diff --git a/src/CSharpTranspiler.js b/src/CSharpTranspiler.js index 7aa3e0a7..d2576f55 100644 --- a/src/CSharpTranspiler.js +++ b/src/CSharpTranspiler.js @@ -57,7 +57,7 @@ function __transpileToCSharpCommon(code) { .replace(/(CSSConstants|CSSWrap|CSSJustify|CSSAlign|CSSPositionType)\.([_A-Z]+)/g, function (str, match1, match2) { - return match1 + "." + constantToPascalCase(match2); + return match1 + '.' + constantToPascalCase(match2); }); } @@ -71,33 +71,33 @@ function __transpileSingleTestToCSharp(code) { /(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g, function (str, match1, match2) { return match1 + '.position[POSITION_' + match2 + ']'; - }) + }) .replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH] /(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { return match1 + '.dimensions[DIMENSION_' + match2 + ']'; - }) + }) .replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth /(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); - }) + }) .replace( // style.minDimensions[CSS_WIDTH] => style.minWidth /(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g, 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) /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g, 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] /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g, function (str, match1, match2) { return 'style.' + match1 + '.get(Spacing.' + match2 + ')'; - }) + }) .replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)') .replace(/init_css_node_children/g, 'addChildren') .replace(/css_node_t(\s)\*/g, 'TestCSSNode$1') @@ -107,14 +107,14 @@ function __transpileSingleTestToCSharp(code) { /style\.([^_\[\]\s]+)_(\w)(\w+)/g, function (str, match1, match2, match3) { return 'style.' + match1 + match2.toUpperCase() + match3; - }) + }) .replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);') // additional case conversions .replace(/(CSSWrap|CSSFlexDirection)\.([_A-Z]+)/g, function (str, match1, match2) { - return match1 + "." + constantToPascalCase(match2); + return match1 + '.' + constantToPascalCase(match2); }); } @@ -162,8 +162,8 @@ var CSharpTranspiler = { var allTestsInCSharp = []; for (var i = 0; i < allTestsInC.length; i++) { allTestsInCSharp[i] = - " [Test]\n" + - " public void TestCase" + i + "()\n" + + ' [Test]\n' + + ' public void TestCase' + i + '()\n' + __transpileSingleTestToCSharp(allTestsInC[i]); } return allTestsInCSharp.join('\n\n'); diff --git a/src/JavaTranspiler.js b/src/JavaTranspiler.js index bf528424..b7f2d212 100644 --- a/src/JavaTranspiler.js +++ b/src/JavaTranspiler.js @@ -64,22 +64,22 @@ function __transpileSingleTestToJava(code) { /(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g, function (str, match1, match2) { return match1 + '.position[POSITION_' + match2 + ']'; - }) + }) .replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH] /(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { return match1 + '.dimensions[DIMENSION_' + match2 + ']'; - }) + }) .replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth /(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); - }) + }) .replace( // style.minDimensions[CSS_WIDTH] => style.minWidth /(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g, 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) /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g, function (str, match1, match2, match3) { @@ -100,7 +100,7 @@ function __transpileSingleTestToJava(code) { /style\.([^_\[\]\s]+)_(\w)(\w+)/g, function (str, match1, match2, match3) { return 'style.' + match1 + match2.toUpperCase() + match3; - }) + }) .replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);'); } diff --git a/src/css-layout.js b/src/css-layout.js index 46f37b10..bfa5c74f 100644 --- a/src/css-layout.js +++ b/src/css-layout.js @@ -22,5 +22,5 @@ return function(node) { computeLayout.fillNodes(node); computeLayout.computeLayout(node); - }; -})); + }; + })); From 45f62c424cd3414849d15bc3eac59937e36b6441 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 5 Oct 2015 13:21:19 +0100 Subject: [PATCH 4/8] Widened scope of CI eslint to all JavaScript files --- Gruntfile.js | 3 +-- src/__tests__/Layout-random-test.js | 2 +- src/__tests__/Layout-test.js | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 0858aff3..d3f06280 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,6 @@ 'use strict'; module.exports = function(grunt) { - var fs = require('fs'); var path = require('path'); var isWindows = (/^win/).test(process.platform); @@ -56,7 +55,7 @@ module.exports = function(grunt) { options: { configFile: '.eslintrc' }, - target: ['<%= config.srcFolder %>/*.js'] + target: ['<%= config.srcFolder %>/**/*.js', './Gruntfile.js'] }, includereplace: { diff --git a/src/__tests__/Layout-random-test.js b/src/__tests__/Layout-random-test.js index e974ef19..d2da1dc7 100644 --- a/src/__tests__/Layout-random-test.js +++ b/src/__tests__/Layout-random-test.js @@ -98,7 +98,7 @@ describe('Random layout', function() { } function checkRandomLayout(i, node) { - it('should layout randomly #' + i + '.', function(node) { + it('should layout randomly #' + i + '.', function(node) { if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) { node = reduceTest(node); } diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index 3db4e72f..5134b53c 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -11,7 +11,6 @@ var testLayout = layoutTestUtils.testLayout; var testLayoutAgainstDomOnly = layoutTestUtils.testLayoutAgainstDomOnly; var testFillNodes = layoutTestUtils.testFillNodes; -var testExtractNodes = layoutTestUtils.testExtractNodes; var text = layoutTestUtils.text; var texts = layoutTestUtils.texts; var textSizes = layoutTestUtils.textSizes; From 538cb2e940e0a3967cd1154d0e36210fb08107d3 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 5 Oct 2015 13:30:59 +0100 Subject: [PATCH 5/8] Fixed build (I was using an older verson of eslint locally) --- src/CSharpTranspiler.js | 30 ++++++++++++++--------------- src/JavaTranspiler.js | 20 +++++++++---------- src/__tests__/Layout-random-test.js | 10 +++++----- src/css-layout.js | 12 ++++++------ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/CSharpTranspiler.js b/src/CSharpTranspiler.js index d2576f55..52d8eef0 100644 --- a/src/CSharpTranspiler.js +++ b/src/CSharpTranspiler.js @@ -70,34 +70,34 @@ function __transpileSingleTestToCSharp(code) { .replace( // style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP] /(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g, function (str, match1, match2) { - return match1 + '.position[POSITION_' + match2 + ']'; - }) + return match1 + '.position[POSITION_' + match2 + ']'; + }) .replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH] /(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { - return match1 + '.dimensions[DIMENSION_' + match2 + ']'; - }) + return match1 + '.dimensions[DIMENSION_' + match2 + ']'; + }) .replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth /(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { - return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); - }) + return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); + }) .replace( // style.minDimensions[CSS_WIDTH] => style.minWidth /(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { - return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); - }) + 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) /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g, function (str, match1, match2, match3) { - var propertyCap = match1.charAt(0).toUpperCase() + match1.slice(1); - return 'set' + propertyCap + '(Spacing.' + 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] /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]/g, function (str, match1, match2) { - return 'style.' + match1 + '.get(Spacing.' + match2 + ')'; - }) + return 'style.' + match1 + '.get(Spacing.' + match2 + ')'; + }) .replace(/get_child\(.*context\,\s([^\)]+)\)/g, 'getChildAt($1)') .replace(/init_css_node_children/g, 'addChildren') .replace(/css_node_t(\s)\*/g, 'TestCSSNode$1') @@ -106,8 +106,8 @@ function __transpileSingleTestToCSharp(code) { .replace( // style.flex_direction => style.flexDirection /style\.([^_\[\]\s]+)_(\w)(\w+)/g, function (str, match1, match2, match3) { - return 'style.' + match1 + match2.toUpperCase() + match3; - }) + return 'style.' + match1 + match2.toUpperCase() + match3; + }) .replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);') // additional case conversions diff --git a/src/JavaTranspiler.js b/src/JavaTranspiler.js index b7f2d212..58caf08a 100644 --- a/src/JavaTranspiler.js +++ b/src/JavaTranspiler.js @@ -63,23 +63,23 @@ function __transpileSingleTestToJava(code) { .replace( // style.position[CSS_TOP] => style.position[CSSLayout.POSITION_TOP] /(style|layout)\.position\[CSS_(LEFT|TOP|RIGHT|BOTTOM)\]/g, function (str, match1, match2) { - return match1 + '.position[POSITION_' + match2 + ']'; - }) + return match1 + '.position[POSITION_' + match2 + ']'; + }) .replace( // style.dimensions[CSS_WIDTH] => style.dimensions[CSSLayout.DIMENSION_WIDTH] /(style|layout)\.dimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { - return match1 + '.dimensions[DIMENSION_' + match2 + ']'; - }) + return match1 + '.dimensions[DIMENSION_' + match2 + ']'; + }) .replace( // style.maxDimensions[CSS_WIDTH] => style.maxWidth /(style|layout)\.maxDimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { - return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); - }) + return match1 + '.max' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); + }) .replace( // style.minDimensions[CSS_WIDTH] => style.minWidth /(style|layout)\.minDimensions\[CSS_(WIDTH|HEIGHT)\]/g, function (str, match1, match2) { - return match1 + '.min' + match2.substr(0, 1).toUpperCase() + match2.substr(1).toLowerCase(); - }) + 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) /style\.(margin|border|padding)\[CSS_(TOP|BOTTOM|LEFT|RIGHT|START|END)\]\s+=\s+(-?[\.\d]+)/g, function (str, match1, match2, match3) { @@ -99,8 +99,8 @@ function __transpileSingleTestToJava(code) { .replace( // style.flex_direction => style.flexDirection /style\.([^_\[\]\s]+)_(\w)(\w+)/g, function (str, match1, match2, match3) { - return 'style.' + match1 + match2.toUpperCase() + match3; - }) + return 'style.' + match1 + match2.toUpperCase() + match3; + }) .replace(/(\w+)\.measure\s+=\s+.+/, '$1.setMeasureFunction(sTestMeasureFunction);'); } diff --git a/src/__tests__/Layout-random-test.js b/src/__tests__/Layout-random-test.js index d2da1dc7..355a2779 100644 --- a/src/__tests__/Layout-random-test.js +++ b/src/__tests__/Layout-random-test.js @@ -99,12 +99,12 @@ describe('Random layout', function() { function checkRandomLayout(i, node) { it('should layout randomly #' + i + '.', function(node) { - if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) { - node = reduceTest(node); - } + if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) { + node = reduceTest(node); + } - testRandomLayout(node, i); - }.bind(this, node)); + testRandomLayout(node, i); + }.bind(this, node)); } for (var i = 0; i < 100; ++i) { diff --git a/src/css-layout.js b/src/css-layout.js index bfa5c74f..5ee1f466 100644 --- a/src/css-layout.js +++ b/src/css-layout.js @@ -17,10 +17,10 @@ root.computeLayout = factory(); } }(this, function () { - // @@include('./Layout.js') + // @@include('./Layout.js') - return function(node) { - computeLayout.fillNodes(node); - computeLayout.computeLayout(node); - }; - })); + return function(node) { + computeLayout.fillNodes(node); + computeLayout.computeLayout(node); + }; +})); From 040f0f3e7cff924fad5b714216649d972e4d67d3 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Wed, 7 Oct 2015 06:40:17 +0100 Subject: [PATCH 6/8] relaxed the eqeqeq rule to permit 'foo != null' --- .eslintrc | 2 +- src/Layout.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index e379dfe7..34a6589b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -54,7 +54,7 @@ "default-case": 0, "dot-notation": 2, "dot-location": 0, - "eqeqeq": 2, + "eqeqeq": [2, "allow-null"], "guard-for-in": 0, "no-alert": 2, "no-caller": 2, diff --git a/src/Layout.js b/src/Layout.js index 1ddec262..d37a47f2 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -112,7 +112,7 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.marginBottom; break; } - if (value !== null && typeof value !== 'undefined') { + if (typeof value !== 'undefined') { return value; } @@ -136,7 +136,7 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.marginTop; break; } - if (value !== null && typeof value !== 'undefined') { + if (value != null) { return value; } @@ -161,7 +161,7 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.paddingBottom; break; } - if (value !== null && value >= 0) { + if (value != null && value >= 0) { return value; } @@ -186,7 +186,7 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.paddingTop; break; } - if (value !== null && value >= 0) { + if (value != null && value >= 0) { return value; } @@ -211,7 +211,7 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.borderBottomWidth; break; } - if (value !== null && value >= 0) { + if (value != null && value >= 0) { return value; } @@ -236,7 +236,7 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.borderTopWidth; break; } - if (value !== null && value >= 0) { + if (value != null && value >= 0) { return value; } From e4c93e8c596cea009b2eeea88e6dc4feb936bdfa Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Wed, 7 Oct 2015 21:52:22 +0100 Subject: [PATCH 7/8] Updated to use eslint from fbjs-scripts --- .eslintrc | 157 +----------------- Gruntfile.js | 8 +- package.json | 2 + src/CSharpTranspiler.js | 36 ++-- src/JavaTranspiler.js | 30 ++-- src/Layout-test-utils.js | 21 ++- src/Layout.c | 3 + src/Layout.js | 3 + src/csharp/Facebook.CSSLayout/LayoutEngine.cs | 3 + src/css-layout.js | 7 +- .../com/facebook/csslayout/LayoutEngine.java | 3 + 11 files changed, 66 insertions(+), 207 deletions(-) diff --git a/.eslintrc b/.eslintrc index 34a6589b..91d700b9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,5 @@ { - "browser": true, - "shadow": true, + "extends": "./node_modules/fbjs-scripts/eslint/.eslintrc", "globals": { "jasmine": true, "describe": true, @@ -17,159 +16,5 @@ "console": true, "setTimeout": true, "define": true - }, - "rules": { - "comma-dangle": 2, - "no-cond-assign": 2, - "no-console": 0, - "no-constant-condition": 2, - "no-control-regex": 2, - "no-debugger": 2, - "no-dupe-args": 2, - "no-dupe-keys": 2, - "no-duplicate-case": 2, - "no-empty-class": 0, - "no-empty": 2, - "no-ex-assign": 2, - "no-extra-boolean-cast": 2, - "no-extra-parens": 0, - "no-extra-semi": 2, - "no-func-assign": 2, - "no-inner-declarations": 2, - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-negated-in-lhs": 2, - "no-obj-calls": 2, - "no-regex-spaces": 2, - "no-reserved-keys": 0, - "no-sparse-arrays": 2, - "no-unreachable": 2, - "use-isnan": 2, - "valid-jsdoc": 2, - "valid-typeof": 2, - "block-scoped-var": 0, - "complexity": 2, - "consistent-return": 2, - "curly": 2, - "default-case": 0, - "dot-notation": 2, - "dot-location": 0, - "eqeqeq": [2, "allow-null"], - "guard-for-in": 0, - "no-alert": 2, - "no-caller": 2, - "no-div-regex": 2, - "no-else-return": 0, - "no-empty-label": 2, - "no-eq-null": 0, - "no-eval": 2, - "no-extend-native": 2, - "no-extra-bind": 2, - "no-fallthrough": 2, - "no-floating-decimal": 2, - "no-implied-eval": 2, - "no-iterator": 2, - "no-labels": 2, - "no-lone-blocks": 2, - "no-loop-func": 2, - "no-multi-spaces": 0, - "no-multi-str": 2, - "no-native-reassign": 2, - "no-new-func": 2, - "no-new-wrappers": 2, - "no-new": 2, - "no-octal-escape": 2, - "no-octal": 2, - "no-param-reassign": 0, - "no-process-env": 2, - "no-proto": 2, - "no-redeclare": 0, - "no-return-assign": 2, - "no-script-url": 2, - "no-self-compare": 0, - "no-sequences": 2, - "no-throw-literal": 2, - "no-unused-expressions": 2, - "no-void": 2, - "no-warning-comments": 0, - "no-with": 2, - "radix": 2, - "vars-on-top": 0, - "wrap-iife": 0, - "yoda": 2, - "strict": 0, - "no-catch-shadow": 2, - "no-delete-var": 2, - "no-label-var": 2, - "no-shadow-restricted-names": 2, - "no-shadow": 0, - "no-undef-init": 2, - "no-undef": 0, - "no-undefined": 0, - "no-unused-vars": 2, - "no-use-before-define": 0, - "handle-callback-err": 2, - "no-mixed-requires": 2, - "no-new-require": 2, - "no-path-concat": 0, - "no-process-exit": 2, - "no-restricted-modules": 2, - "no-sync": 0, - "brace-style": 0, - "camelcase": 2, - "comma-spacing": 2, - "comma-style": 2, - "consistent-this": 2, - "eol-last": 2, - "func-names": 0, - "func-style": 0, - "indent": [2, 2, {"SwitchCase": 1}], - "key-spacing": 2, - "linebreak-style": 2, - "new-cap": 2, - "new-parens": 2, - "newline-after-var": 0, - "no-array-constructor": 2, - "no-continue": 0, - "no-inline-comments": 0, - "no-lonely-if": 2, - "no-mixed-spaces-and-tabs": 2, - "no-multiple-empty-lines": 2, - "no-nested-ternary": 2, - "no-new-object": 2, - "no-spaced-func": 2, - "no-ternary": 0, - "no-trailing-spaces": 0, - "no-underscore-dangle": 0, - "no-unneeded-ternary": 2, - "no-wrap-func": 0, - "one-var": 0, - "operator-assignment": 2, - "operator-linebreak": 0, - "padded-blocks": 0, - "quote-props": 0, - "quotes": [2, "single"], - "semi-spacing": 2, - "semi": 0, - "sort-vars": 0, - "space-after-keywords": 2, - "space-before-blocks": 2, - "space-before-function-paren": 0, - "space-in-brackets": 0, - "space-in-parens": 0, - "space-infix-ops": 2, - "space-return-throw-case": 2, - "space-unary-ops": 2, - "spaced-line-comment": 0, - "wrap-regex": 2, - "generator-star-spacing": 2, - "no-var": 0, - "object-shorthand": 0, - "max-depth": 2, - "max-len": 0, - "max-params": 0, - "max-statements": 0, - "no-bitwise": 2, - "no-plusplus": 0 } } diff --git a/Gruntfile.js b/Gruntfile.js index d3f06280..ecc986f7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -25,8 +25,7 @@ module.exports = function(grunt) { config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"'; config.cTestExecute = '<%= config.cTestOutput %>'; config.cTestClean = ['<%= config.cTestOutput %>', '*.obj', '*.pdb']; - } - else { + } else { // GCC build (OSX, Linux, ...), assumes gcc is in the path. config.cTestOutput = 'c_test'; config.cTestCompile = 'gcc -std=c99 -Werror -Wno-padded src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -lm -o "./<%= config.cTestOutput %>"'; @@ -119,9 +118,8 @@ module.exports = function(grunt) { '#ifdef CSS_LAYOUT_IMPLEMENTATION', src, '#endif // CSS_LAYOUT_IMPLEMENTATION' - ].join('\n') - } - else { + ].join('\n'); + } else { return src; } } diff --git a/package.json b/package.json index 87e6a945..20c71174 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ }, "homepage": "https://github.com/facebook/css-layout", "devDependencies": { + "babel-eslint": "^4.1.3", + "fbjs-scripts": "^0.2.2", "grunt": "^0.4.5", "grunt-cli": "^0.1.13", "grunt-contrib-clean": "^0.6.0", diff --git a/src/CSharpTranspiler.js b/src/CSharpTranspiler.js index 52d8eef0..1e3dfa85 100644 --- a/src/CSharpTranspiler.js +++ b/src/CSharpTranspiler.js @@ -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; diff --git a/src/JavaTranspiler.js b/src/JavaTranspiler.js index 58caf08a..4e129bd0 100644 --- a/src/JavaTranspiler.js +++ b/src/JavaTranspiler.js @@ -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);'); diff --git a/src/Layout-test-utils.js b/src/Layout-test-utils.js index be912e0f..2a79f1dc 100644 --- a/src/Layout-test-utils.js +++ b/src/Layout-test-utils.js @@ -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; } diff --git a/src/Layout.c b/src/Layout.c index fa031f20..9242a885 100644 --- a/src/Layout.c +++ b/src/Layout.c @@ -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. diff --git a/src/Layout.js b/src/Layout.js index d37a47f2..d9038bc4 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -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. diff --git a/src/csharp/Facebook.CSSLayout/LayoutEngine.cs b/src/csharp/Facebook.CSSLayout/LayoutEngine.cs index 7f3f09b5..47b7cb3d 100644 --- a/src/csharp/Facebook.CSSLayout/LayoutEngine.cs +++ b/src/csharp/Facebook.CSSLayout/LayoutEngine.cs @@ -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. diff --git a/src/css-layout.js b/src/css-layout.js index 5ee1f466..0f24f5cb 100644 --- a/src/css-layout.js +++ b/src/css-layout.js @@ -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 */ }; })); diff --git a/src/java/src/com/facebook/csslayout/LayoutEngine.java b/src/java/src/com/facebook/csslayout/LayoutEngine.java index c88a9295..8d92129b 100644 --- a/src/java/src/com/facebook/csslayout/LayoutEngine.java +++ b/src/java/src/com/facebook/csslayout/LayoutEngine.java @@ -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. From f02fbfc10c0e55ae81236a76766bcb92febd64cd Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Wed, 7 Oct 2015 22:18:27 +0100 Subject: [PATCH 8/8] Changed from '"typeof foo === 'undefined'" to "foo === undefined" --- src/Layout.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Layout.js b/src/Layout.js index d9038bc4..15e3fbcf 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -100,7 +100,7 @@ var computeLayout = (function() { } function getLeadingMargin(node, axis) { - if (typeof node.style.marginStart !== 'undefined' && isRowDirection(axis)) { + if (node.style.marginStart !== undefined && isRowDirection(axis)) { return node.style.marginStart; } @@ -112,11 +112,11 @@ var computeLayout = (function() { case 'column-reverse': value = node.style.marginBottom; break; } - if (typeof value !== 'undefined') { + if (value !== undefined) { return value; } - if (typeof node.style.margin !== 'undefined') { + if (node.style.margin !== undefined) { return node.style.margin; } @@ -124,7 +124,7 @@ var computeLayout = (function() { } function getTrailingMargin(node, axis) { - if (typeof node.style.marginEnd !== 'undefined' && isRowDirection(axis)) { + if (node.style.marginEnd !== undefined && isRowDirection(axis)) { return node.style.marginEnd; } @@ -140,7 +140,7 @@ var computeLayout = (function() { return value; } - if (typeof node.style.margin !== 'undefined') { + if (node.style.margin !== undefined) { return node.style.margin; } @@ -148,7 +148,7 @@ var computeLayout = (function() { } function getLeadingPadding(node, axis) { - if (typeof node.style.paddingStart !== 'undefined' && node.style.paddingStart >= 0 + if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0 && isRowDirection(axis)) { return node.style.paddingStart; } @@ -165,7 +165,7 @@ var computeLayout = (function() { return value; } - if (typeof node.style.padding !== 'undefined' && node.style.padding >= 0) { + if (node.style.padding !== undefined && node.style.padding >= 0) { return node.style.padding; } @@ -173,7 +173,7 @@ var computeLayout = (function() { } function getTrailingPadding(node, axis) { - if (typeof node.style.paddingEnd !== 'undefined' && node.style.paddingEnd >= 0 + if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0 && isRowDirection(axis)) { return node.style.paddingEnd; } @@ -190,7 +190,7 @@ var computeLayout = (function() { return value; } - if (typeof node.style.padding !== 'undefined' && node.style.padding >= 0) { + if (node.style.padding !== undefined && node.style.padding >= 0) { return node.style.padding; } @@ -198,7 +198,7 @@ var computeLayout = (function() { } function getLeadingBorder(node, axis) { - if (typeof node.style.borderStartWidth !== 'undefined' && node.style.borderStartWidth >= 0 + if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0 && isRowDirection(axis)) { return node.style.borderStartWidth; } @@ -215,7 +215,7 @@ var computeLayout = (function() { return value; } - if (typeof node.style.borderWidth !== 'undefined' && node.style.borderWidth >= 0) { + if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) { return node.style.borderWidth; } @@ -223,7 +223,7 @@ var computeLayout = (function() { } function getTrailingBorder(node, axis) { - if (typeof node.style.borderEndWidth !== 'undefined' && node.style.borderEndWidth >= 0 + if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0 && isRowDirection(axis)) { return node.style.borderEndWidth; } @@ -240,7 +240,7 @@ var computeLayout = (function() { return value; } - if (typeof node.style.borderWidth !== undefined && node.style.borderWidth >= 0) { + if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) { return node.style.borderWidth; } @@ -357,19 +357,19 @@ var computeLayout = (function() { } function isDimDefined(node, axis) { - return typeof node.style[dim[axis]] !== 'undefined' && node.style[dim[axis]] >= 0; + return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0; } function isPosDefined(node, pos) { - return typeof node.style[pos] !== 'undefined'; + return node.style[pos] !== undefined; } function isMeasureDefined(node) { - return typeof node.style.measure !== 'undefined'; + return node.style.measure !== undefined; } function getPosition(node, pos) { - if (typeof node.style[pos] !== 'undefined') { + if (node.style[pos] !== undefined) { return node.style[pos]; } return 0; @@ -391,10 +391,10 @@ var computeLayout = (function() { }[axis]; var boundValue = value; - if (max !== null && max >= 0 && boundValue > max) { + if (max !== undefined && max >= 0 && boundValue > max) { boundValue = max; } - if (min !== null && min >= 0 && boundValue < min) { + if (min !== undefined && min >= 0 && boundValue < min) { boundValue = min; } return boundValue; @@ -410,7 +410,7 @@ var computeLayout = (function() { // When the user specifically sets a value for width or height function setDimensionFromStyle(node, axis) { // The parent already computed us a width or height. We just skip it - if (typeof node.layout[dim[axis]] !== 'undefined') { + if (node.layout[dim[axis]] !== undefined) { return; } // We only run if there's a width or height defined @@ -433,7 +433,7 @@ var computeLayout = (function() { // If both left and right are defined, then use left. Otherwise return // +left or -right depending on which is defined. function getRelativePosition(node, axis) { - if (typeof node.style[leading[axis]] !== 'undefined') { + if (node.style[leading[axis]] !== undefined) { return getPosition(node, leading[axis]); } return -getPosition(node, trailing[axis]);